12 if (eval 'require VMS::Feature') {
13 $vms_exit_mode = !(VMS::Feature::current("posix_exit"));
15 my $env_unix_rpt = $ENV{'DECC$FILENAME_UNIX_REPORT'} || '';
16 my $env_posix_ex = $ENV{'PERL_VMS_POSIX_EXIT'} || '';
17 my $unix_rpt = $env_unix_rpt =~ /^[ET1]/i;
18 my $posix_ex = $env_posix_ex =~ /^[ET1]/i;
19 if (($unix_rpt || $posix_ex) ) {
28 # supress VMS whinging about bad execs.
29 use vmsish qw(hushed);
31 $| = 1; # flush stdout
33 $ENV{LC_ALL} = 'C'; # Forge English error messages.
34 $ENV{LANGUAGE} = 'C'; # Ditto in GNU.
36 my $Is_VMS = $^O eq 'VMS';
37 my $Is_Win32 = $^O eq 'MSWin32';
39 skip_all("Tests mostly usesless on MacOS") if $^O eq 'MacOS';
43 my $Perl = which_perl();
47 skip("bug/feature of pdksh", 2) if $^O eq 'os2';
49 my $tnum = curr_test();
50 $exit = system qq{$Perl -le "print q{ok $tnum - interp system(EXPR)"}};
52 is( $exit, 0, ' exited 0' );
55 my $tnum = curr_test();
56 $exit = system qq{$Perl -le "print q{ok $tnum - split & direct system(EXPR)"}};
58 is( $exit, 0, ' exited 0' );
60 # On VMS and Win32 you need the quotes around the program or it won't work.
61 # On Unix its the opposite.
62 my $quote = $Is_VMS || $Is_Win32 ? '"' : '';
64 $exit = system $Perl, '-le',
65 "${quote}print q{ok $tnum - system(PROG, LIST)}${quote}";
67 is( $exit, 0, ' exited 0' );
70 # Some basic piped commands. Some OS's have trouble with "helpfully"
71 # putting newlines on the end of piped output. So we split this into
72 # newline insensitive and newline sensitive tests.
73 my $echo_out = `$Perl -e "print 'ok'" | $Perl -le "print <STDIN>"`;
74 $echo_out =~ s/\n\n/\n/g;
75 is( $echo_out, "ok\n", 'piped echo emulation');
78 # here we check if extra newlines are going to be slapped on
80 local $TODO = 'VMS sticks newlines on everything' if $Is_VMS;
82 is( scalar `$Perl -e "print 'ok'"`,
83 "ok", 'no extra newlines on ``' );
85 is( scalar `$Perl -e "print 'ok'" | $Perl -e "print <STDIN>"`,
86 "ok", 'no extra newlines on pipes');
88 is( scalar `$Perl -le "print 'ok'" | $Perl -le "print <STDIN>"`,
89 "ok\n\n", 'doubled up newlines');
91 is( scalar `$Perl -e "print 'ok'" | $Perl -le "print <STDIN>"`,
92 "ok\n", 'extra newlines on inside pipes');
94 is( scalar `$Perl -le "print 'ok'" | $Perl -e "print <STDIN>"`,
95 "ok\n", 'extra newlines on outgoing pipes');
99 $out = runperl(prog => 'print q{1234}');
100 is($out, "1234", 'ignore $/ when capturing output in scalar context');
105 is( system(qq{$Perl -e "exit 0"}), 0, 'Explicit exit of 0' );
107 my $exit_one = $vms_exit_mode ? 4 << 8 : 1 << 8;
108 is( system(qq{$Perl "-I../lib" -e "use vmsish qw(hushed); exit 1"}), $exit_one,
109 'Explicit exit of 1' );
111 $rc = system { "lskdfj" } "lskdfj";
112 unless( ok($rc == 255 << 8 or $rc == -1 or $rc == 256 or $rc == 512) ) {
113 print "# \$rc == $rc\n";
116 unless ( ok( $! == 2 or $! =~ /\bno\b.*\bfile/i or
117 $! == 13 or $! =~ /permission denied/i or
118 $! == 22 or $! =~ /invalid argument/i ) ) {
119 printf "# \$! eq %d, '%s'\n", $!, $!;
123 is( `$Perl -le "print 'ok'"`, "ok\n", 'basic ``' );
124 is( <<`END`, "ok\n", '<<`HEREDOC`' );
125 $Perl -le "print 'ok'"
129 my $_ = qq($Perl -le "print 'ok'");
130 is( readpipe, "ok\n", 'readpipe default argument' );
134 my $tnum = curr_test();
135 if( $^O =~ /Win32/ ) {
136 print "not ok $tnum - exec failure doesn't terminate process " .
137 "# TODO Win32 exec failure waits for user input\n";
142 ok( !exec("lskdjfalksdjfdjfkls"),
143 "exec failure doesn't terminate process");
146 my $test = curr_test();
147 exec $Perl, '-le', qq{${quote}print 'ok $test - exec PROG, LIST'${quote}};
148 fail("This should never be reached if the exec() worked");