- Moved unused argc, temp variable into small scope.
[dragonfly.git] / contrib / perl5 / 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 binmode F; # for DOSISH platforms, because test 3 copies to stdout
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
32 binmode STDOUT unless $^O eq 'VMS';                     # Copy::copy works in binary mode
33 copy "copy-$$", \*STDOUT;
34 unlink "copy-$$" or die "unlink: $!";
35
36 open(F,"file-$$");
37 copy(*F, "copy-$$");
38 open(R, "copy-$$") or die "open copy-$$: $!"; $foo = <R>; close(R);
39 print "not " unless $foo eq "ok 3\n";
40 print "ok 4\n";
41 unlink "copy-$$" or die "unlink: $!";
42 open(F,"file-$$");
43 copy(\*F, "copy-$$");
44 close(F) or die "close: $!";
45 open(R, "copy-$$") or die; $foo = <R>; close(R) or die "close: $!";
46 print "not " unless $foo eq "ok 3\n";
47 print "ok 5\n";
48 unlink "copy-$$" or die "unlink: $!";
49
50 require IO::File;
51 $fh = IO::File->new(">copy-$$") or die "Cannot open copy-$$:$!";
52 binmode $fh or die;
53 copy("file-$$",$fh);
54 $fh->close or die "close: $!";
55 open(R, "copy-$$") or die; $foo = <R>; close(R);
56 print "# foo=`$foo'\nnot " unless $foo eq "ok 3\n";
57 print "ok 6\n";
58 unlink "copy-$$" or die "unlink: $!";
59 require FileHandle;
60 my $fh = FileHandle->new(">copy-$$") or die "Cannot open copy-$$:$!";
61 binmode $fh or die;
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";
67 unlink "file-$$" or die "unlink: $!";
68
69 print "# moved missing file.\nnot " if move("file-$$", "copy-$$");
70 print "# target disappeared.\nnot " if not -e "copy-$$";
71 print "ok 8\n";
72
73 move "copy-$$", "file-$$" or print "# move did not succeed.\n";
74 print "# not moved: $!\nnot " unless -e "file-$$" and not -e "copy-$$";
75 open(R, "file-$$") or die; $foo = <R>; close(R);
76 print "# foo=`$foo'\nnot " unless $foo eq "ok 3\n";
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";
83 unlink "lib/file-$$" or die "unlink: $!";
84
85 move "file-$$", "lib";
86 open(R, "lib/file-$$") or die "open lib/file-$$: $!"; $foo = <R>; close(R);
87 print "not " unless $foo eq "ok 3\n" and not -e "file-$$";;
88 print "ok 11\n";
89 unlink "lib/file-$$" or die "unlink: $!";
90