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