This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[win32] Integrate mainline
[perl5.git] / t / lib / filecopy.t
CommitLineData
1a3850a5
GA
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6}
7
71be2cbc 8print "1..11\n";
1a3850a5
GA
9
10$| = 1;
11
12use File::Copy;
13
14# First we create a file
15open(F, ">file-$$") or die;
16print F "ok 3\n";
17close F;
18
19copy "file-$$", "copy-$$";
20
21open(F, "copy-$$") or die;
22$foo = <F>;
23close(F);
24
25print "not " if -s "file-$$" != -s "copy-$$";
26print "ok 1\n";
27
28print "not " unless $foo eq "ok 3\n";
29print "ok 2\n";
30
31copy "copy-$$", \*STDOUT;
e6434134 32unlink "copy-$$" or die "unlink: $!";
1a3850a5 33
71be2cbc 34open(F,"file-$$");
35copy(*F, "copy-$$");
e6434134 36open(R, "copy-$$") or die "open copy-$$: $!"; $foo = <R>; close(R);
71be2cbc 37print "not " unless $foo eq "ok 3\n";
38print "ok 4\n";
e6434134 39unlink "copy-$$" or die "unlink: $!";
71be2cbc 40open(F,"file-$$");
41copy(\*F, "copy-$$");
e6434134
IZ
42close(F) or die "close: $!";
43open(R, "copy-$$") or die; $foo = <R>; close(R) or die "close: $!";
71be2cbc 44print "not " unless $foo eq "ok 3\n";
45print "ok 5\n";
e6434134 46unlink "copy-$$" or die "unlink: $!";
71be2cbc 47
48require IO::File;
49$fh = IO::File->new(">copy-$$") or die "Cannot open copy-$$:$!";
e6434134 50binmode $fh or die;
71be2cbc 51copy("file-$$",$fh);
e6434134 52$fh->close or die "close: $!";
71be2cbc 53open(R, "copy-$$") or die; $foo = <R>; close(R);
e6434134 54print "# foo=`$foo'\nnot " unless $foo eq "ok 3\n";
71be2cbc 55print "ok 6\n";
e6434134 56unlink "copy-$$" or die "unlink: $!";
71be2cbc 57require FileHandle;
58my $fh = FileHandle->new(">copy-$$") or die "Cannot open copy-$$:$!";
e6434134 59binmode $fh or die;
71be2cbc 60copy("file-$$",$fh);
61$fh->close;
62open(R, "copy-$$") or die; $foo = <R>; close(R);
63print "not " unless $foo eq "ok 3\n";
64print "ok 7\n";
e6434134 65unlink "file-$$" or die "unlink: $!";
441496b2 66
e6434134
IZ
67print "# moved missing file.\nnot " if move("file-$$", "copy-$$");
68print "# target disappeared.\nnot " if not -e "copy-$$";
71be2cbc 69print "ok 8\n";
441496b2 70
e6434134
IZ
71move "copy-$$", "file-$$" or print "# move did not succeed.\n";
72print "# not moved: $!\nnot " unless -e "file-$$" and not -e "copy-$$";
71be2cbc 73open(R, "file-$$") or die; $foo = <R>; close(R);
e6434134 74print "# foo=`$foo'\nnot " unless $foo eq "ok 3\n";
71be2cbc 75print "ok 9\n";
76
77copy "file-$$", "lib";
78open(R, "lib/file-$$") or die; $foo = <R>; close(R);
79print "not " unless $foo eq "ok 3\n";
80print "ok 10\n";
e6434134 81unlink "lib/file-$$" or die "unlink: $!";
71be2cbc 82
83move "file-$$", "lib";
e6434134 84open(R, "lib/file-$$") or die "open lib/file-$$: $!"; $foo = <R>; close(R);
71be2cbc 85print "not " unless $foo eq "ok 3\n" and not -e "file-$$";;
86print "ok 11\n";
e6434134 87unlink "lib/file-$$" or die "unlink: $!";
441496b2 88