9 # supress VMS whinging about bad execs.
10 use vmsish qw(hushed);
12 $| = 1; # flush stdout
14 $ENV{LC_ALL} = 'C'; # Forge English error messages.
15 $ENV{LANGUAGE} = 'C'; # Ditto in GNU.
17 my $Is_VMS = $^O eq 'VMS';
18 my $Is_Win32 = $^O eq 'MSWin32';
20 skip_all("Tests mostly usesless on MacOS") if $^O eq 'MacOS';
24 my $Perl = which_perl();
28 skip("bug/feature of pdksh", 2) if $^O eq 'os2';
30 my $tnum = curr_test();
31 $exit = system qq{$Perl -le "print q{ok $tnum - interp system(EXPR)"}};
33 is( $exit, 0, ' exited 0' );
36 my $tnum = curr_test();
37 $exit = system qq{$Perl -le "print q{ok $tnum - split & direct system(EXPR)"}};
39 is( $exit, 0, ' exited 0' );
41 # On VMS and Win32 you need the quotes around the program or it won't work.
42 # On Unix its the opposite.
43 my $quote = $Is_VMS || $Is_Win32 ? '"' : '';
45 $exit = system $Perl, '-le',
46 "${quote}print q{ok $tnum - system(PROG, LIST)}${quote}";
48 is( $exit, 0, ' exited 0' );
51 # Some basic piped commands. Some OS's have trouble with "helpfully"
52 # putting newlines on the end of piped output. So we split this into
53 # newline insensitive and newline sensitive tests.
54 my $echo_out = `$Perl -e "print 'ok'" | $Perl -le "print <STDIN>"`;
55 $echo_out =~ s/\n\n/\n/g;
56 is( $echo_out, "ok\n", 'piped echo emulation');
59 # here we check if extra newlines are going to be slapped on
61 local $TODO = 'VMS sticks newlines on everything' if $Is_VMS;
63 is( scalar `$Perl -e "print 'ok'"`,
64 "ok", 'no extra newlines on ``' );
66 is( scalar `$Perl -e "print 'ok'" | $Perl -e "print <STDIN>"`,
67 "ok", 'no extra newlines on pipes');
69 is( scalar `$Perl -le "print 'ok'" | $Perl -le "print <STDIN>"`,
70 "ok\n\n", 'doubled up newlines');
72 is( scalar `$Perl -e "print 'ok'" | $Perl -le "print <STDIN>"`,
73 "ok\n", 'extra newlines on inside pipes');
75 is( scalar `$Perl -le "print 'ok'" | $Perl -e "print <STDIN>"`,
76 "ok\n", 'extra newlines on outgoing pipes');
80 $out = runperl(prog => 'print q{1234}');
81 is($out, "1234", 'ignore $/ when capturing output in scalar context');
86 is( system(qq{$Perl -e "exit 0"}), 0, 'Explicit exit of 0' );
88 my $exit_one = $Is_VMS ? 4 << 8 : 1 << 8;
89 is( system(qq{$Perl "-I../lib" -e "use vmsish qw(hushed); exit 1"}), $exit_one,
90 'Explicit exit of 1' );
92 $rc = system { "lskdfj" } "lskdfj";
93 unless( ok($rc == 255 << 8 or $rc == -1 or $rc == 256 or $rc == 512) ) {
94 print "# \$rc == $rc\n";
97 unless ( ok( $! == 2 or $! =~ /\bno\b.*\bfile/i or
98 $! == 13 or $! =~ /permission denied/i or
99 $! == 22 or $! =~ /invalid argument/i ) ) {
100 printf "# \$! eq %d, '%s'\n", $!, $!;
104 is( `$Perl -le "print 'ok'"`, "ok\n", 'basic ``' );
105 is( <<`END`, "ok\n", '<<`HEREDOC`' );
106 $Perl -le "print 'ok'"
110 my $_ = qq($Perl -le "print 'ok'");
111 is( readpipe, "ok\n", 'readpipe default argument' );
115 my $tnum = curr_test();
116 if( $^O =~ /Win32/ ) {
117 print "not ok $tnum - exec failure doesn't terminate process " .
118 "# TODO Win32 exec failure waits for user input\n";
123 ok( !exec("lskdjfalksdjfdjfkls"),
124 "exec failure doesn't terminate process");
127 my $test = curr_test();
128 exec $Perl, '-le', qq{${quote}print 'ok $test - exec PROG, LIST'${quote}};
129 fail("This should never be reached if the exec() worked");