Re: Untested builtins
[p5sagit/p5-mst-13.2.git] / t / op / exec.t
CommitLineData
8d063cd8 1#!./perl
2
9247405f 3BEGIN: {
4 chdir 't' if -d 't';
5 @INC = ('../lib');
972e7321 6 require './test.pl';
9247405f 7}
8
9# supress VMS whinging about bad execs.
10use vmsish qw(hushed);
11
8d063cd8 12$| = 1; # flush stdout
68dc0745 13
9429f27a 14$ENV{LC_ALL} = 'C'; # Forge English error messages.
15$ENV{LANGUAGE} = 'C'; # Ditto in GNU.
16
e0d72a37 17my $Is_VMS = $^O eq 'VMS';
18my $Is_Win32 = $^O eq 'MSWin32';
b6345914 19
dc459aad 20skip_all("Tests mostly usesless on MacOS") if $^O eq 'MacOS';
21
fa326138 22plan(tests => 21);
972e7321 23
24my $Perl = which_perl();
68dc0745 25
9247405f 26my $exit;
27SKIP: {
28 skip("bug/feature of pdksh", 2) if $^O eq 'os2';
29
b6345914 30 my $tnum = curr_test();
31 $exit = system qq{$Perl -le "print q{ok $tnum - interp system(EXPR)"}};
9247405f 32 next_test();
33 is( $exit, 0, ' exited 0' );
95e8664e 34}
35
b6345914 36my $tnum = curr_test();
37$exit = system qq{$Perl -le "print q{ok $tnum - split & direct system(EXPR)"}};
9247405f 38next_test();
39is( $exit, 0, ' exited 0' );
40
e0d72a37 41# On VMS and Win32 you need the quotes around the program or it won't work.
9247405f 42# On Unix its the opposite.
e0d72a37 43my $quote = $Is_VMS || $Is_Win32 ? '"' : '';
b6345914 44$tnum = curr_test();
972e7321 45$exit = system $Perl, '-le',
b6345914 46 "${quote}print q{ok $tnum - system(PROG, LIST)}${quote}";
9247405f 47next_test();
48is( $exit, 0, ' exited 0' );
49
8d063cd8 50
b6345914 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.
54my $echo_out = `$Perl -e "print 'ok'" | $Perl -le "print <STDIN>"`;
55$echo_out =~ s/\n\n/\n/g;
56is( $echo_out, "ok\n", 'piped echo emulation');
57
58{
59 # here we check if extra newlines are going to be slapped on
60 # piped output.
61 local $TODO = 'VMS sticks newlines on everything' if $Is_VMS;
62
63 is( scalar `$Perl -e "print 'ok'"`,
64 "ok", 'no extra newlines on ``' );
65
66 is( scalar `$Perl -e "print 'ok'" | $Perl -e "print <STDIN>"`,
67 "ok", 'no extra newlines on pipes');
68
69 is( scalar `$Perl -le "print 'ok'" | $Perl -le "print <STDIN>"`,
70 "ok\n\n", 'doubled up newlines');
71
72 is( scalar `$Perl -e "print 'ok'" | $Perl -le "print <STDIN>"`,
73 "ok\n", 'extra newlines on inside pipes');
74
75 is( scalar `$Perl -le "print 'ok'" | $Perl -e "print <STDIN>"`,
76 "ok\n", 'extra newlines on outgoing pipes');
fa326138 77
78 {
79 local($/) = \2;
80 $out = runperl(prog => 'print q{1234}');
81 is($out, "1234", 'ignore $/ when capturing output in scalar context');
82 }
b6345914 83}
84
85
972e7321 86is( system(qq{$Perl -e "exit 0"}), 0, 'Explicit exit of 0' );
9247405f 87
b6345914 88my $exit_one = $Is_VMS ? 4 << 8 : 1 << 8;
972e7321 89is( system(qq{$Perl "-I../lib" -e "use vmsish qw(hushed); exit 1"}), $exit_one,
9247405f 90 'Explicit exit of 1' );
91
c623ac67 92$rc = system { "lskdfj" } "lskdfj";
6cd63c21 93$rc = 256 if ($rc == 5632) && $Is_VMS;
0dd6fc14 94unless( ok($rc == 255 << 8 or $rc == -1 or $rc == 256 or $rc == 512) ) {
9247405f 95 print "# \$rc == $rc\n";
ec40c0cd 96}
8d063cd8 97
9247405f 98unless ( ok( $! == 2 or $! =~ /\bno\b.*\bfile/i or
99 $! == 13 or $! =~ /permission denied/i or
100 $! == 22 or $! =~ /invalid argument/ ) ) {
101 printf "# \$! eq %d, '%s'\n", $!, $!;
102}
103
972e7321 104
105is( `$Perl -le "print 'ok'"`, "ok\n", 'basic ``' );
106is( <<`END`, "ok\n", '<<`HEREDOC`' );
107$Perl -le "print 'ok'"
108END
109
110
9247405f 111TODO: {
b6345914 112 my $tnum = curr_test();
9247405f 113 if( $^O =~ /Win32/ ) {
e0d72a37 114 print "not ok $tnum - exec failure doesn't terminate process " .
115 "# TODO Win32 exec failure waits for user input\n";
116 next_test();
9247405f 117 last TODO;
118 }
378cc40b 119
9247405f 120 ok( !exec("lskdjfalksdjfdjfkls"),
121 "exec failure doesn't terminate process");
0994c4d0 122}
378cc40b 123
972e7321 124my $test = curr_test();
125exec $Perl, '-le', qq{${quote}print 'ok $test - exec PROG, LIST'${quote}};
9247405f 126fail("This should never be reached if the exec() worked");