filecopy.t revision 7c478bd95313f5f23a4c958a745db2134aa03244
#!./perl
BEGIN {
chdir 't' if -d 't';
}
$| = 1;
my @pass = (0,1);
my $tests = 11;
my $loopconst = $pass*$tests;
# First we create a file
binmode F; # for DOSISH platforms, because test 3 copies to stdout
close F;
$foo = <F>;
print "not " if -s "file-$$" != -s "copy-$$";
printf "ok %d\n", 6+$loopconst;
unlink "copy-$$" or die "unlink: $!";
require FileHandle;
my $fh = FileHandle->new(">copy-$$") or die "Cannot open copy-$$:$!";
binmode $fh or die;
copy("file-$$",$fh);
$fh->close;
open(R, "copy-$$") or die; $foo = <R>; close(R);
print "not " unless $foo eq sprintf "ok %d\n", 3+$loopconst;
printf "ok %d\n", 7+$loopconst;
unlink "file-$$" or die "unlink: $!";
print "# moved missing file.\nnot " if move("file-$$", "copy-$$");
print "# target disappeared.\nnot " if not -e "copy-$$";
printf "ok %d\n", 8+$loopconst;
move "copy-$$", "file-$$" or print "# move did not succeed.\n";
print "# not moved: $!\nnot " unless -e "file-$$" and not -e "copy-$$";
open(R, "file-$$") or die; $foo = <R>; close(R);
}
END {
}