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