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 require './test.pl'; 7*0Sstevel@tonic-gate} 8*0Sstevel@tonic-gate 9*0Sstevel@tonic-gate# supress VMS whinging about bad execs. 10*0Sstevel@tonic-gateuse vmsish qw(hushed); 11*0Sstevel@tonic-gate 12*0Sstevel@tonic-gate$| = 1; # flush stdout 13*0Sstevel@tonic-gate 14*0Sstevel@tonic-gate$ENV{LC_ALL} = 'C'; # Forge English error messages. 15*0Sstevel@tonic-gate$ENV{LANGUAGE} = 'C'; # Ditto in GNU. 16*0Sstevel@tonic-gate 17*0Sstevel@tonic-gatemy $Is_VMS = $^O eq 'VMS'; 18*0Sstevel@tonic-gatemy $Is_Win32 = $^O eq 'MSWin32'; 19*0Sstevel@tonic-gate 20*0Sstevel@tonic-gateskip_all("Tests mostly usesless on MacOS") if $^O eq 'MacOS'; 21*0Sstevel@tonic-gate 22*0Sstevel@tonic-gateplan(tests => 21); 23*0Sstevel@tonic-gate 24*0Sstevel@tonic-gatemy $Perl = which_perl(); 25*0Sstevel@tonic-gate 26*0Sstevel@tonic-gatemy $exit; 27*0Sstevel@tonic-gateSKIP: { 28*0Sstevel@tonic-gate skip("bug/feature of pdksh", 2) if $^O eq 'os2'; 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate my $tnum = curr_test(); 31*0Sstevel@tonic-gate $exit = system qq{$Perl -le "print q{ok $tnum - interp system(EXPR)"}}; 32*0Sstevel@tonic-gate next_test(); 33*0Sstevel@tonic-gate is( $exit, 0, ' exited 0' ); 34*0Sstevel@tonic-gate} 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gatemy $tnum = curr_test(); 37*0Sstevel@tonic-gate$exit = system qq{$Perl -le "print q{ok $tnum - split & direct system(EXPR)"}}; 38*0Sstevel@tonic-gatenext_test(); 39*0Sstevel@tonic-gateis( $exit, 0, ' exited 0' ); 40*0Sstevel@tonic-gate 41*0Sstevel@tonic-gate# On VMS and Win32 you need the quotes around the program or it won't work. 42*0Sstevel@tonic-gate# On Unix its the opposite. 43*0Sstevel@tonic-gatemy $quote = $Is_VMS || $Is_Win32 ? '"' : ''; 44*0Sstevel@tonic-gate$tnum = curr_test(); 45*0Sstevel@tonic-gate$exit = system $Perl, '-le', 46*0Sstevel@tonic-gate "${quote}print q{ok $tnum - system(PROG, LIST)}${quote}"; 47*0Sstevel@tonic-gatenext_test(); 48*0Sstevel@tonic-gateis( $exit, 0, ' exited 0' ); 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate 51*0Sstevel@tonic-gate# Some basic piped commands. Some OS's have trouble with "helpfully" 52*0Sstevel@tonic-gate# putting newlines on the end of piped output. So we split this into 53*0Sstevel@tonic-gate# newline insensitive and newline sensitive tests. 54*0Sstevel@tonic-gatemy $echo_out = `$Perl -e "print 'ok'" | $Perl -le "print <STDIN>"`; 55*0Sstevel@tonic-gate$echo_out =~ s/\n\n/\n/g; 56*0Sstevel@tonic-gateis( $echo_out, "ok\n", 'piped echo emulation'); 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gate{ 59*0Sstevel@tonic-gate # here we check if extra newlines are going to be slapped on 60*0Sstevel@tonic-gate # piped output. 61*0Sstevel@tonic-gate local $TODO = 'VMS sticks newlines on everything' if $Is_VMS; 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gate is( scalar `$Perl -e "print 'ok'"`, 64*0Sstevel@tonic-gate "ok", 'no extra newlines on ``' ); 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate is( scalar `$Perl -e "print 'ok'" | $Perl -e "print <STDIN>"`, 67*0Sstevel@tonic-gate "ok", 'no extra newlines on pipes'); 68*0Sstevel@tonic-gate 69*0Sstevel@tonic-gate is( scalar `$Perl -le "print 'ok'" | $Perl -le "print <STDIN>"`, 70*0Sstevel@tonic-gate "ok\n\n", 'doubled up newlines'); 71*0Sstevel@tonic-gate 72*0Sstevel@tonic-gate is( scalar `$Perl -e "print 'ok'" | $Perl -le "print <STDIN>"`, 73*0Sstevel@tonic-gate "ok\n", 'extra newlines on inside pipes'); 74*0Sstevel@tonic-gate 75*0Sstevel@tonic-gate is( scalar `$Perl -le "print 'ok'" | $Perl -e "print <STDIN>"`, 76*0Sstevel@tonic-gate "ok\n", 'extra newlines on outgoing pipes'); 77*0Sstevel@tonic-gate 78*0Sstevel@tonic-gate { 79*0Sstevel@tonic-gate local($/) = \2; 80*0Sstevel@tonic-gate $out = runperl(prog => 'print q{1234}'); 81*0Sstevel@tonic-gate is($out, "1234", 'ignore $/ when capturing output in scalar context'); 82*0Sstevel@tonic-gate } 83*0Sstevel@tonic-gate} 84*0Sstevel@tonic-gate 85*0Sstevel@tonic-gate 86*0Sstevel@tonic-gateis( system(qq{$Perl -e "exit 0"}), 0, 'Explicit exit of 0' ); 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gatemy $exit_one = $Is_VMS ? 4 << 8 : 1 << 8; 89*0Sstevel@tonic-gateis( system(qq{$Perl "-I../lib" -e "use vmsish qw(hushed); exit 1"}), $exit_one, 90*0Sstevel@tonic-gate 'Explicit exit of 1' ); 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate$rc = system { "lskdfj" } "lskdfj"; 93*0Sstevel@tonic-gateunless( ok($rc == 255 << 8 or $rc == -1 or $rc == 256 or $rc == 512) ) { 94*0Sstevel@tonic-gate print "# \$rc == $rc\n"; 95*0Sstevel@tonic-gate} 96*0Sstevel@tonic-gate 97*0Sstevel@tonic-gateunless ( ok( $! == 2 or $! =~ /\bno\b.*\bfile/i or 98*0Sstevel@tonic-gate $! == 13 or $! =~ /permission denied/i or 99*0Sstevel@tonic-gate $! == 22 or $! =~ /invalid argument/ ) ) { 100*0Sstevel@tonic-gate printf "# \$! eq %d, '%s'\n", $!, $!; 101*0Sstevel@tonic-gate} 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate 104*0Sstevel@tonic-gateis( `$Perl -le "print 'ok'"`, "ok\n", 'basic ``' ); 105*0Sstevel@tonic-gateis( <<`END`, "ok\n", '<<`HEREDOC`' ); 106*0Sstevel@tonic-gate$Perl -le "print 'ok'" 107*0Sstevel@tonic-gateEND 108*0Sstevel@tonic-gate 109*0Sstevel@tonic-gate 110*0Sstevel@tonic-gateTODO: { 111*0Sstevel@tonic-gate my $tnum = curr_test(); 112*0Sstevel@tonic-gate if( $^O =~ /Win32/ ) { 113*0Sstevel@tonic-gate print "not ok $tnum - exec failure doesn't terminate process " . 114*0Sstevel@tonic-gate "# TODO Win32 exec failure waits for user input\n"; 115*0Sstevel@tonic-gate next_test(); 116*0Sstevel@tonic-gate last TODO; 117*0Sstevel@tonic-gate } 118*0Sstevel@tonic-gate 119*0Sstevel@tonic-gate ok( !exec("lskdjfalksdjfdjfkls"), 120*0Sstevel@tonic-gate "exec failure doesn't terminate process"); 121*0Sstevel@tonic-gate} 122*0Sstevel@tonic-gate 123*0Sstevel@tonic-gatemy $test = curr_test(); 124*0Sstevel@tonic-gateexec $Perl, '-le', qq{${quote}print 'ok $test - exec PROG, LIST'${quote}}; 125*0Sstevel@tonic-gatefail("This should never be reached if the exec() worked"); 126