1N/A#!./perl
1N/A
1N/ABEGIN {
1N/A chdir 't' if -d 't';
1N/A @INC = '../lib';
1N/A push @INC, "::lib:$MacPerl::Architecture" if $^O eq 'MacOS';
1N/A}
1N/A
1N/A$| = 1;
1N/A
1N/Amy @pass = (0,1);
1N/Amy $tests = $^O eq 'MacOS' ? 17 : 14;
1N/Aprintf "1..%d\n", $tests * scalar(@pass);
1N/A
1N/Ause File::Copy;
1N/Ause Config;
1N/A
1N/Afor my $pass (@pass) {
1N/A
1N/A my $loopconst = $pass*$tests;
1N/A
1N/A # First we create a file
1N/A open(F, ">file-$$") or die;
1N/A binmode F; # for DOSISH platforms, because test 3 copies to stdout
1N/A printf F "ok %d\n", 3 + $loopconst;
1N/A close F;
1N/A
1N/A copy "file-$$", "copy-$$";
1N/A
1N/A open(F, "copy-$$") or die;
1N/A $foo = <F>;
1N/A close(F);
1N/A
1N/A print "not " if -s "file-$$" != -s "copy-$$";
1N/A printf "ok %d\n", 1 + $loopconst;
1N/A
1N/A print "not " unless $foo eq sprintf "ok %d\n", 3+$loopconst;
1N/A printf "ok %d\n", 2+$loopconst;
1N/A
1N/A binmode STDOUT unless $^O eq 'VMS'; # Copy::copy works in binary mode
1N/A copy "copy-$$", \*STDOUT;
1N/A unlink "copy-$$" or die "unlink: $!";
1N/A
1N/A open(F,"file-$$");
1N/A copy(*F, "copy-$$");
1N/A open(R, "copy-$$") or die "open copy-$$: $!"; $foo = <R>; close(R);
1N/A print "not " unless $foo eq sprintf "ok %d\n", 3+$loopconst;
1N/A printf "ok %d\n", 4+$loopconst;
1N/A unlink "copy-$$" or die "unlink: $!";
1N/A open(F,"file-$$");
1N/A copy(\*F, "copy-$$");
1N/A close(F) or die "close: $!";
1N/A open(R, "copy-$$") or die; $foo = <R>; close(R) or die "close: $!";
1N/A print "not " unless $foo eq sprintf "ok %d\n", 3+$loopconst;
1N/A printf "ok %d\n", 5+$loopconst;
1N/A unlink "copy-$$" or die "unlink: $!";
1N/A
1N/A require IO::File;
1N/A $fh = IO::File->new(">copy-$$") or die "Cannot open copy-$$:$!";
1N/A binmode $fh or die;
1N/A copy("file-$$",$fh);
1N/A $fh->close or die "close: $!";
1N/A open(R, "copy-$$") or die; $foo = <R>; close(R);
1N/A print "# foo=`$foo'\nnot " unless $foo eq sprintf "ok %d\n", 3+$loopconst;
1N/A printf "ok %d\n", 6+$loopconst;
1N/A unlink "copy-$$" or die "unlink: $!";
1N/A require FileHandle;
1N/A my $fh = FileHandle->new(">copy-$$") or die "Cannot open copy-$$:$!";
1N/A binmode $fh or die;
1N/A copy("file-$$",$fh);
1N/A $fh->close;
1N/A open(R, "copy-$$") or die; $foo = <R>; close(R);
1N/A print "not " unless $foo eq sprintf "ok %d\n", 3+$loopconst;
1N/A printf "ok %d\n", 7+$loopconst;
1N/A unlink "file-$$" or die "unlink: $!";
1N/A
1N/A print "# moved missing file.\nnot " if move("file-$$", "copy-$$");
1N/A print "# target disappeared.\nnot " if not -e "copy-$$";
1N/A printf "ok %d\n", 8+$loopconst;
1N/A
1N/A move "copy-$$", "file-$$" or print "# move did not succeed.\n";
1N/A print "# not moved: $!\nnot " unless -e "file-$$" and not -e "copy-$$";
1N/A open(R, "file-$$") or die; $foo = <R>; close(R);
1N/A print "# foo=`$foo'\nnot " unless $foo eq sprintf "ok %d\n", 3+$loopconst;
1N/A printf "ok %d\n", 9+$loopconst;
1N/A
1N/A my $test_i;
1N/A if ($^O eq 'MacOS') {
1N/A
1N/A copy "file-$$", "lib";
1N/A open(R, ":lib:file-$$") or die; $foo = <R>; close(R);
1N/A print "not " unless $foo eq sprintf "ok %d\n", 3+$loopconst;
1N/A printf "ok %d\n", 10+$loopconst;
1N/A unlink ":lib:file-$$" or die "unlink: $!";
1N/A
1N/A copy "file-$$", ":lib";
1N/A open(R, ":lib:file-$$") or die; $foo = <R>; close(R);
1N/A print "not " unless $foo eq sprintf "ok %d\n", 3+$loopconst;
1N/A printf "ok %d\n", 11+$loopconst;
1N/A unlink ":lib:file-$$" or die "unlink: $!";
1N/A
1N/A copy "file-$$", ":lib:";
1N/A open(R, ":lib:file-$$") or die; $foo = <R>; close(R);
1N/A print "not " unless $foo eq sprintf "ok %d\n", 3+$loopconst;
1N/A printf "ok %d\n", 12+$loopconst;
1N/A unlink ":lib:file-$$" or die "unlink: $!";
1N/A
1N/A unless (-e 'lib:') { # make sure there's no volume called 'lib'
1N/A undef $@;
1N/A eval { (copy "file-$$", "lib:") || die "'lib:' is not a volume name"; };
1N/A print "# Died: $@";
1N/A print "not " unless ( $@ =~ m|'lib:' is not a volume name| );
1N/A }
1N/A printf "ok %d\n", 13+$loopconst;
1N/A
1N/A move "file-$$", ":lib:";
1N/A open(R, ":lib:file-$$") or die "open :lib:file-$$: $!"; $foo = <R>; close(R);
1N/A print "not " unless $foo eq sprintf("ok %d\n", 3+$loopconst)
1N/A and not -e "file-$$";;
1N/A printf "ok %d\n", 14+$loopconst;
1N/A
1N/A eval { copy("copy-$$", "copy-$$") };
1N/A printf "ok %d\n", 15+$loopconst
1N/A unless $@ =~ /are identical/ && -s "copy-$$";
1N/A
1N/A unlink ":lib:file-$$" or die "unlink: $!";
1N/A
1N/A $test_i = 15;
1N/A } else {
1N/A
1N/A copy "file-$$", "lib";
1N/A open(R, "lib/file-$$") or die; $foo = <R>; close(R);
1N/A print "not " unless $foo eq sprintf "ok %d\n", 3+$loopconst;
1N/A printf "ok %d\n", 10+$loopconst;
1N/A unlink "lib/file-$$" or die "unlink: $!";
1N/A
1N/A move "file-$$", "lib";
1N/A open(R, "lib/file-$$") or die "open lib/file-$$: $!"; $foo = <R>; close(R);
1N/A print "not " unless $foo eq sprintf("ok %d\n", 3+$loopconst)
1N/A and not -e "file-$$";;
1N/A printf "ok %d\n", 11+$loopconst;
1N/A
1N/A eval { copy("copy-$$", "copy-$$") };
1N/A printf "ok %d\n", 12+$loopconst
1N/A unless $@ =~ /are identical/ && -s "copy-$$";
1N/A
1N/A unlink "lib/file-$$" or die "unlink: $!";
1N/A
1N/A $test_i = 12;
1N/A }
1N/A
1N/A if ($Config{d_symlink}) {
1N/A open(F, ">file-$$") or die $!;
1N/A print F "dummy content\n";
1N/A close F;
1N/A symlink("file-$$", "symlink-$$") or die $!;
1N/A eval { copy("file-$$", "symlink-$$") };
1N/A print "not " if $@ !~ /are identical/ || -z "file-$$";
1N/A printf "ok %d\n", (++$test_i)+$loopconst;
1N/A unlink "symlink-$$";
1N/A unlink "file-$$";
1N/A } else {
1N/A printf "ok %d # Skipped: no symlinks on this platform\n", (++$test_i)+$loopconst;
1N/A }
1N/A
1N/A if ($Config{d_link}) {
1N/A if ($^O ne 'MSWin32') {
1N/A open(F, ">file-$$") or die $!;
1N/A print F "dummy content\n";
1N/A close F;
1N/A link("file-$$", "hardlink-$$") or die $!;
1N/A eval { copy("file-$$", "hardlink-$$") };
1N/A print "not " if $@ !~ /are identical/ || -z "file-$$";
1N/A printf "ok %d\n", (++$test_i)+$loopconst;
1N/A unlink "hardlink-$$";
1N/A unlink "file-$$";
1N/A } else {
1N/A printf "ok %d # Skipped: can't test hardlinks on MSWin32\n", (++$test_i)+$loopconst;
1N/A }
1N/A } else {
1N/A printf "ok %d # Skipped: no hardlinks on this platform\n", (++$test_i)+$loopconst;
1N/A }
1N/A
1N/A}
1N/A
1N/A
1N/AEND {
1N/A 1 while unlink "file-$$";
1N/A if ($^O eq 'MacOS') {
1N/A 1 while unlink ":lib:file-$$";
1N/A } else {
1N/A 1 while unlink "lib/file-$$";
1N/A }
1N/A}