1*0Sstevel@tonic-gate#!./perl 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gateBEGIN { 4*0Sstevel@tonic-gate chdir 't' if -d 't'; 5*0Sstevel@tonic-gate @INC = '../lib'; 6*0Sstevel@tonic-gate push @INC, "::lib:$MacPerl::Architecture" if $^O eq 'MacOS'; 7*0Sstevel@tonic-gate} 8*0Sstevel@tonic-gate 9*0Sstevel@tonic-gate$| = 1; 10*0Sstevel@tonic-gate 11*0Sstevel@tonic-gatemy @pass = (0,1); 12*0Sstevel@tonic-gatemy $tests = $^O eq 'MacOS' ? 17 : 14; 13*0Sstevel@tonic-gateprintf "1..%d\n", $tests * scalar(@pass); 14*0Sstevel@tonic-gate 15*0Sstevel@tonic-gateuse File::Copy; 16*0Sstevel@tonic-gateuse Config; 17*0Sstevel@tonic-gate 18*0Sstevel@tonic-gatefor my $pass (@pass) { 19*0Sstevel@tonic-gate 20*0Sstevel@tonic-gate my $loopconst = $pass*$tests; 21*0Sstevel@tonic-gate 22*0Sstevel@tonic-gate # First we create a file 23*0Sstevel@tonic-gate open(F, ">file-$$") or die; 24*0Sstevel@tonic-gate binmode F; # for DOSISH platforms, because test 3 copies to stdout 25*0Sstevel@tonic-gate printf F "ok %d\n", 3 + $loopconst; 26*0Sstevel@tonic-gate close F; 27*0Sstevel@tonic-gate 28*0Sstevel@tonic-gate copy "file-$$", "copy-$$"; 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate open(F, "copy-$$") or die; 31*0Sstevel@tonic-gate $foo = <F>; 32*0Sstevel@tonic-gate close(F); 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate print "not " if -s "file-$$" != -s "copy-$$"; 35*0Sstevel@tonic-gate printf "ok %d\n", 1 + $loopconst; 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gate print "not " unless $foo eq sprintf "ok %d\n", 3+$loopconst; 38*0Sstevel@tonic-gate printf "ok %d\n", 2+$loopconst; 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate binmode STDOUT unless $^O eq 'VMS'; # Copy::copy works in binary mode 41*0Sstevel@tonic-gate copy "copy-$$", \*STDOUT; 42*0Sstevel@tonic-gate unlink "copy-$$" or die "unlink: $!"; 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate open(F,"file-$$"); 45*0Sstevel@tonic-gate copy(*F, "copy-$$"); 46*0Sstevel@tonic-gate open(R, "copy-$$") or die "open copy-$$: $!"; $foo = <R>; close(R); 47*0Sstevel@tonic-gate print "not " unless $foo eq sprintf "ok %d\n", 3+$loopconst; 48*0Sstevel@tonic-gate printf "ok %d\n", 4+$loopconst; 49*0Sstevel@tonic-gate unlink "copy-$$" or die "unlink: $!"; 50*0Sstevel@tonic-gate open(F,"file-$$"); 51*0Sstevel@tonic-gate copy(\*F, "copy-$$"); 52*0Sstevel@tonic-gate close(F) or die "close: $!"; 53*0Sstevel@tonic-gate open(R, "copy-$$") or die; $foo = <R>; close(R) or die "close: $!"; 54*0Sstevel@tonic-gate print "not " unless $foo eq sprintf "ok %d\n", 3+$loopconst; 55*0Sstevel@tonic-gate printf "ok %d\n", 5+$loopconst; 56*0Sstevel@tonic-gate unlink "copy-$$" or die "unlink: $!"; 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gate require IO::File; 59*0Sstevel@tonic-gate $fh = IO::File->new(">copy-$$") or die "Cannot open copy-$$:$!"; 60*0Sstevel@tonic-gate binmode $fh or die; 61*0Sstevel@tonic-gate copy("file-$$",$fh); 62*0Sstevel@tonic-gate $fh->close or die "close: $!"; 63*0Sstevel@tonic-gate open(R, "copy-$$") or die; $foo = <R>; close(R); 64*0Sstevel@tonic-gate print "# foo=`$foo'\nnot " unless $foo eq sprintf "ok %d\n", 3+$loopconst; 65*0Sstevel@tonic-gate printf "ok %d\n", 6+$loopconst; 66*0Sstevel@tonic-gate unlink "copy-$$" or die "unlink: $!"; 67*0Sstevel@tonic-gate require FileHandle; 68*0Sstevel@tonic-gate my $fh = FileHandle->new(">copy-$$") or die "Cannot open copy-$$:$!"; 69*0Sstevel@tonic-gate binmode $fh or die; 70*0Sstevel@tonic-gate copy("file-$$",$fh); 71*0Sstevel@tonic-gate $fh->close; 72*0Sstevel@tonic-gate open(R, "copy-$$") or die; $foo = <R>; close(R); 73*0Sstevel@tonic-gate print "not " unless $foo eq sprintf "ok %d\n", 3+$loopconst; 74*0Sstevel@tonic-gate printf "ok %d\n", 7+$loopconst; 75*0Sstevel@tonic-gate unlink "file-$$" or die "unlink: $!"; 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate print "# moved missing file.\nnot " if move("file-$$", "copy-$$"); 78*0Sstevel@tonic-gate print "# target disappeared.\nnot " if not -e "copy-$$"; 79*0Sstevel@tonic-gate printf "ok %d\n", 8+$loopconst; 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gate move "copy-$$", "file-$$" or print "# move did not succeed.\n"; 82*0Sstevel@tonic-gate print "# not moved: $!\nnot " unless -e "file-$$" and not -e "copy-$$"; 83*0Sstevel@tonic-gate open(R, "file-$$") or die; $foo = <R>; close(R); 84*0Sstevel@tonic-gate print "# foo=`$foo'\nnot " unless $foo eq sprintf "ok %d\n", 3+$loopconst; 85*0Sstevel@tonic-gate printf "ok %d\n", 9+$loopconst; 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate my $test_i; 88*0Sstevel@tonic-gate if ($^O eq 'MacOS') { 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate copy "file-$$", "lib"; 91*0Sstevel@tonic-gate open(R, ":lib:file-$$") or die; $foo = <R>; close(R); 92*0Sstevel@tonic-gate print "not " unless $foo eq sprintf "ok %d\n", 3+$loopconst; 93*0Sstevel@tonic-gate printf "ok %d\n", 10+$loopconst; 94*0Sstevel@tonic-gate unlink ":lib:file-$$" or die "unlink: $!"; 95*0Sstevel@tonic-gate 96*0Sstevel@tonic-gate copy "file-$$", ":lib"; 97*0Sstevel@tonic-gate open(R, ":lib:file-$$") or die; $foo = <R>; close(R); 98*0Sstevel@tonic-gate print "not " unless $foo eq sprintf "ok %d\n", 3+$loopconst; 99*0Sstevel@tonic-gate printf "ok %d\n", 11+$loopconst; 100*0Sstevel@tonic-gate unlink ":lib:file-$$" or die "unlink: $!"; 101*0Sstevel@tonic-gate 102*0Sstevel@tonic-gate copy "file-$$", ":lib:"; 103*0Sstevel@tonic-gate open(R, ":lib:file-$$") or die; $foo = <R>; close(R); 104*0Sstevel@tonic-gate print "not " unless $foo eq sprintf "ok %d\n", 3+$loopconst; 105*0Sstevel@tonic-gate printf "ok %d\n", 12+$loopconst; 106*0Sstevel@tonic-gate unlink ":lib:file-$$" or die "unlink: $!"; 107*0Sstevel@tonic-gate 108*0Sstevel@tonic-gate unless (-e 'lib:') { # make sure there's no volume called 'lib' 109*0Sstevel@tonic-gate undef $@; 110*0Sstevel@tonic-gate eval { (copy "file-$$", "lib:") || die "'lib:' is not a volume name"; }; 111*0Sstevel@tonic-gate print "# Died: $@"; 112*0Sstevel@tonic-gate print "not " unless ( $@ =~ m|'lib:' is not a volume name| ); 113*0Sstevel@tonic-gate } 114*0Sstevel@tonic-gate printf "ok %d\n", 13+$loopconst; 115*0Sstevel@tonic-gate 116*0Sstevel@tonic-gate move "file-$$", ":lib:"; 117*0Sstevel@tonic-gate open(R, ":lib:file-$$") or die "open :lib:file-$$: $!"; $foo = <R>; close(R); 118*0Sstevel@tonic-gate print "not " unless $foo eq sprintf("ok %d\n", 3+$loopconst) 119*0Sstevel@tonic-gate and not -e "file-$$";; 120*0Sstevel@tonic-gate printf "ok %d\n", 14+$loopconst; 121*0Sstevel@tonic-gate 122*0Sstevel@tonic-gate eval { copy("copy-$$", "copy-$$") }; 123*0Sstevel@tonic-gate printf "ok %d\n", 15+$loopconst 124*0Sstevel@tonic-gate unless $@ =~ /are identical/ && -s "copy-$$"; 125*0Sstevel@tonic-gate 126*0Sstevel@tonic-gate unlink ":lib:file-$$" or die "unlink: $!"; 127*0Sstevel@tonic-gate 128*0Sstevel@tonic-gate $test_i = 15; 129*0Sstevel@tonic-gate } else { 130*0Sstevel@tonic-gate 131*0Sstevel@tonic-gate copy "file-$$", "lib"; 132*0Sstevel@tonic-gate open(R, "lib/file-$$") or die; $foo = <R>; close(R); 133*0Sstevel@tonic-gate print "not " unless $foo eq sprintf "ok %d\n", 3+$loopconst; 134*0Sstevel@tonic-gate printf "ok %d\n", 10+$loopconst; 135*0Sstevel@tonic-gate unlink "lib/file-$$" or die "unlink: $!"; 136*0Sstevel@tonic-gate 137*0Sstevel@tonic-gate move "file-$$", "lib"; 138*0Sstevel@tonic-gate open(R, "lib/file-$$") or die "open lib/file-$$: $!"; $foo = <R>; close(R); 139*0Sstevel@tonic-gate print "not " unless $foo eq sprintf("ok %d\n", 3+$loopconst) 140*0Sstevel@tonic-gate and not -e "file-$$";; 141*0Sstevel@tonic-gate printf "ok %d\n", 11+$loopconst; 142*0Sstevel@tonic-gate 143*0Sstevel@tonic-gate eval { copy("copy-$$", "copy-$$") }; 144*0Sstevel@tonic-gate printf "ok %d\n", 12+$loopconst 145*0Sstevel@tonic-gate unless $@ =~ /are identical/ && -s "copy-$$"; 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gate unlink "lib/file-$$" or die "unlink: $!"; 148*0Sstevel@tonic-gate 149*0Sstevel@tonic-gate $test_i = 12; 150*0Sstevel@tonic-gate } 151*0Sstevel@tonic-gate 152*0Sstevel@tonic-gate if ($Config{d_symlink}) { 153*0Sstevel@tonic-gate open(F, ">file-$$") or die $!; 154*0Sstevel@tonic-gate print F "dummy content\n"; 155*0Sstevel@tonic-gate close F; 156*0Sstevel@tonic-gate symlink("file-$$", "symlink-$$") or die $!; 157*0Sstevel@tonic-gate eval { copy("file-$$", "symlink-$$") }; 158*0Sstevel@tonic-gate print "not " if $@ !~ /are identical/ || -z "file-$$"; 159*0Sstevel@tonic-gate printf "ok %d\n", (++$test_i)+$loopconst; 160*0Sstevel@tonic-gate unlink "symlink-$$"; 161*0Sstevel@tonic-gate unlink "file-$$"; 162*0Sstevel@tonic-gate } else { 163*0Sstevel@tonic-gate printf "ok %d # Skipped: no symlinks on this platform\n", (++$test_i)+$loopconst; 164*0Sstevel@tonic-gate } 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate if ($Config{d_link}) { 167*0Sstevel@tonic-gate if ($^O ne 'MSWin32') { 168*0Sstevel@tonic-gate open(F, ">file-$$") or die $!; 169*0Sstevel@tonic-gate print F "dummy content\n"; 170*0Sstevel@tonic-gate close F; 171*0Sstevel@tonic-gate link("file-$$", "hardlink-$$") or die $!; 172*0Sstevel@tonic-gate eval { copy("file-$$", "hardlink-$$") }; 173*0Sstevel@tonic-gate print "not " if $@ !~ /are identical/ || -z "file-$$"; 174*0Sstevel@tonic-gate printf "ok %d\n", (++$test_i)+$loopconst; 175*0Sstevel@tonic-gate unlink "hardlink-$$"; 176*0Sstevel@tonic-gate unlink "file-$$"; 177*0Sstevel@tonic-gate } else { 178*0Sstevel@tonic-gate printf "ok %d # Skipped: can't test hardlinks on MSWin32\n", (++$test_i)+$loopconst; 179*0Sstevel@tonic-gate } 180*0Sstevel@tonic-gate } else { 181*0Sstevel@tonic-gate printf "ok %d # Skipped: no hardlinks on this platform\n", (++$test_i)+$loopconst; 182*0Sstevel@tonic-gate } 183*0Sstevel@tonic-gate 184*0Sstevel@tonic-gate} 185*0Sstevel@tonic-gate 186*0Sstevel@tonic-gate 187*0Sstevel@tonic-gateEND { 188*0Sstevel@tonic-gate 1 while unlink "file-$$"; 189*0Sstevel@tonic-gate if ($^O eq 'MacOS') { 190*0Sstevel@tonic-gate 1 while unlink ":lib:file-$$"; 191*0Sstevel@tonic-gate } else { 192*0Sstevel@tonic-gate 1 while unlink "lib/file-$$"; 193*0Sstevel@tonic-gate } 194*0Sstevel@tonic-gate} 195