[asperl] various changes to get asperl working under Borland
[p5sagit/p5-mst-13.2.git] / t / lib / filecopy.t
CommitLineData
1a3850a5 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
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
32copy "copy-$$", \*STDOUT;
e6434134 33unlink "copy-$$" or die "unlink: $!";
1a3850a5 34
71be2cbc 35open(F,"file-$$");
36copy(*F, "copy-$$");
e6434134 37open(R, "copy-$$") or die "open copy-$$: $!"; $foo = <R>; close(R);
71be2cbc 38print "not " unless $foo eq "ok 3\n";
39print "ok 4\n";
e6434134 40unlink "copy-$$" or die "unlink: $!";
71be2cbc 41open(F,"file-$$");
42copy(\*F, "copy-$$");
e6434134 43close(F) or die "close: $!";
44open(R, "copy-$$") or die; $foo = <R>; close(R) or die "close: $!";
71be2cbc 45print "not " unless $foo eq "ok 3\n";
46print "ok 5\n";
e6434134 47unlink "copy-$$" or die "unlink: $!";
71be2cbc 48
49require IO::File;
50$fh = IO::File->new(">copy-$$") or die "Cannot open copy-$$:$!";
e6434134 51binmode $fh or die;
71be2cbc 52copy("file-$$",$fh);
e6434134 53$fh->close or die "close: $!";
71be2cbc 54open(R, "copy-$$") or die; $foo = <R>; close(R);
e6434134 55print "# foo=`$foo'\nnot " unless $foo eq "ok 3\n";
71be2cbc 56print "ok 6\n";
e6434134 57unlink "copy-$$" or die "unlink: $!";
71be2cbc 58require FileHandle;
59my $fh = FileHandle->new(">copy-$$") or die "Cannot open copy-$$:$!";
e6434134 60binmode $fh or die;
71be2cbc 61copy("file-$$",$fh);
62$fh->close;
63open(R, "copy-$$") or die; $foo = <R>; close(R);
64print "not " unless $foo eq "ok 3\n";
65print "ok 7\n";
e6434134 66unlink "file-$$" or die "unlink: $!";
441496b2 67
e6434134 68print "# moved missing file.\nnot " if move("file-$$", "copy-$$");
69print "# target disappeared.\nnot " if not -e "copy-$$";
71be2cbc 70print "ok 8\n";
441496b2 71
e6434134 72move "copy-$$", "file-$$" or print "# move did not succeed.\n";
73print "# not moved: $!\nnot " unless -e "file-$$" and not -e "copy-$$";
71be2cbc 74open(R, "file-$$") or die; $foo = <R>; close(R);
e6434134 75print "# foo=`$foo'\nnot " unless $foo eq "ok 3\n";
71be2cbc 76print "ok 9\n";
77
78copy "file-$$", "lib";
79open(R, "lib/file-$$") or die; $foo = <R>; close(R);
80print "not " unless $foo eq "ok 3\n";
81print "ok 10\n";
e6434134 82unlink "lib/file-$$" or die "unlink: $!";
71be2cbc 83
84move "file-$$", "lib";
e6434134 85open(R, "lib/file-$$") or die "open lib/file-$$: $!"; $foo = <R>; close(R);
71be2cbc 86print "not " unless $foo eq "ok 3\n" and not -e "file-$$";;
87print "ok 11\n";
e6434134 88unlink "lib/file-$$" or die "unlink: $!";
441496b2 89