Commit | Line | Data |
1a3850a5 |
1 | #!./perl |
2 | |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
93430cb4 |
5 | unshift @INC, '../lib'; |
1a3850a5 |
6 | } |
7 | |
71be2cbc |
8 | print "1..11\n"; |
1a3850a5 |
9 | |
10 | $| = 1; |
11 | |
12 | use File::Copy; |
13 | |
14 | # First we create a file |
15 | open(F, ">file-$$") or die; |
0018b59d |
16 | binmode F; # for DOSISH platforms, because test 3 copies to stdout |
1a3850a5 |
17 | print F "ok 3\n"; |
18 | close F; |
19 | |
20 | copy "file-$$", "copy-$$"; |
21 | |
22 | open(F, "copy-$$") or die; |
23 | $foo = <F>; |
24 | close(F); |
25 | |
26 | print "not " if -s "file-$$" != -s "copy-$$"; |
27 | print "ok 1\n"; |
28 | |
29 | print "not " unless $foo eq "ok 3\n"; |
30 | print "ok 2\n"; |
31 | |
b2b3adea |
32 | binmode STDOUT unless $^O eq 'VMS'; # Copy::copy works in binary mode |
1a3850a5 |
33 | copy "copy-$$", \*STDOUT; |
e6434134 |
34 | unlink "copy-$$" or die "unlink: $!"; |
1a3850a5 |
35 | |
71be2cbc |
36 | open(F,"file-$$"); |
37 | copy(*F, "copy-$$"); |
e6434134 |
38 | open(R, "copy-$$") or die "open copy-$$: $!"; $foo = <R>; close(R); |
71be2cbc |
39 | print "not " unless $foo eq "ok 3\n"; |
40 | print "ok 4\n"; |
e6434134 |
41 | unlink "copy-$$" or die "unlink: $!"; |
71be2cbc |
42 | open(F,"file-$$"); |
43 | copy(\*F, "copy-$$"); |
e6434134 |
44 | close(F) or die "close: $!"; |
45 | open(R, "copy-$$") or die; $foo = <R>; close(R) or die "close: $!"; |
71be2cbc |
46 | print "not " unless $foo eq "ok 3\n"; |
47 | print "ok 5\n"; |
e6434134 |
48 | unlink "copy-$$" or die "unlink: $!"; |
71be2cbc |
49 | |
50 | require IO::File; |
51 | $fh = IO::File->new(">copy-$$") or die "Cannot open copy-$$:$!"; |
e6434134 |
52 | binmode $fh or die; |
71be2cbc |
53 | copy("file-$$",$fh); |
e6434134 |
54 | $fh->close or die "close: $!"; |
71be2cbc |
55 | open(R, "copy-$$") or die; $foo = <R>; close(R); |
e6434134 |
56 | print "# foo=`$foo'\nnot " unless $foo eq "ok 3\n"; |
71be2cbc |
57 | print "ok 6\n"; |
e6434134 |
58 | unlink "copy-$$" or die "unlink: $!"; |
71be2cbc |
59 | require FileHandle; |
60 | my $fh = FileHandle->new(">copy-$$") or die "Cannot open copy-$$:$!"; |
e6434134 |
61 | binmode $fh or die; |
71be2cbc |
62 | copy("file-$$",$fh); |
63 | $fh->close; |
64 | open(R, "copy-$$") or die; $foo = <R>; close(R); |
65 | print "not " unless $foo eq "ok 3\n"; |
66 | print "ok 7\n"; |
e6434134 |
67 | unlink "file-$$" or die "unlink: $!"; |
441496b2 |
68 | |
e6434134 |
69 | print "# moved missing file.\nnot " if move("file-$$", "copy-$$"); |
70 | print "# target disappeared.\nnot " if not -e "copy-$$"; |
71be2cbc |
71 | print "ok 8\n"; |
441496b2 |
72 | |
e6434134 |
73 | move "copy-$$", "file-$$" or print "# move did not succeed.\n"; |
74 | print "# not moved: $!\nnot " unless -e "file-$$" and not -e "copy-$$"; |
71be2cbc |
75 | open(R, "file-$$") or die; $foo = <R>; close(R); |
e6434134 |
76 | print "# foo=`$foo'\nnot " unless $foo eq "ok 3\n"; |
71be2cbc |
77 | print "ok 9\n"; |
78 | |
79 | copy "file-$$", "lib"; |
80 | open(R, "lib/file-$$") or die; $foo = <R>; close(R); |
81 | print "not " unless $foo eq "ok 3\n"; |
82 | print "ok 10\n"; |
e6434134 |
83 | unlink "lib/file-$$" or die "unlink: $!"; |
71be2cbc |
84 | |
85 | move "file-$$", "lib"; |
e6434134 |
86 | open(R, "lib/file-$$") or die "open lib/file-$$: $!"; $foo = <R>; close(R); |
71be2cbc |
87 | print "not " unless $foo eq "ok 3\n" and not -e "file-$$";; |
88 | print "ok 11\n"; |
e6434134 |
89 | unlink "lib/file-$$" or die "unlink: $!"; |
441496b2 |
90 | |