Non-VMS-fixed and Win32-skipped version of
[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');
6}
7
8# supress VMS whinging about bad execs.
9use vmsish qw(hushed);
10
8d063cd8 11$| = 1; # flush stdout
68dc0745 12
9429f27a 13$ENV{LC_ALL} = 'C'; # Forge English error messages.
14$ENV{LANGUAGE} = 'C'; # Ditto in GNU.
15
9247405f 16require './test.pl';
17plan(tests => 12);
68dc0745 18
9247405f 19my $exit;
20SKIP: {
21 skip("bug/feature of pdksh", 2) if $^O eq 'os2';
22
23 $exit = system qq{$^X -le "print q{ok 1 - interpreted system(EXPR)"}};
24 next_test();
25 is( $exit, 0, ' exited 0' );
95e8664e 26}
27
9247405f 28$exit = system qq{$^X -le "print q{ok 3 - split & direct call system(EXPR)"}};
29next_test();
30is( $exit, 0, ' exited 0' );
31
32# On VMS you need the quotes around the program or it won't work.
33# On Unix its the opposite.
34my $quote = $^O eq 'VMS' ? '"' : '';
35$exit = system $^X, '-le',
36 "${quote}print q{ok 5 - system(PROG, LIST)}${quote}";
37next_test();
38is( $exit, 0, ' exited 0' );
39
8d063cd8 40
9247405f 41is( system(qq{$^X -e "exit 0"}), 0, 'Explicit exit of 0' );
42
43my $exit_one = $^O eq 'VMS' ? 4 << 8 : 1 << 8;
44is( system(qq{$^X "-I../lib" -e "use vmsish qw(hushed); exit 1"}), $exit_one,
45 'Explicit exit of 1' );
46
47
48$rc = system "lskdfj";
49unless( ok($rc == 255 << 8 or $rc == -1 or $rc == 256) ) {
50 print "# \$rc == $rc\n";
ec40c0cd 51}
8d063cd8 52
9247405f 53unless ( ok( $! == 2 or $! =~ /\bno\b.*\bfile/i or
54 $! == 13 or $! =~ /permission denied/i or
55 $! == 22 or $! =~ /invalid argument/ ) ) {
56 printf "# \$! eq %d, '%s'\n", $!, $!;
57}
58
59TODO: {
60 if( $^O =~ /Win32/ ) {
61 print "not ok 11 - exec failure doesn't terminate process # TODO Win32 exec failure waits for user input\n";
62 last TODO;
63 }
378cc40b 64
9247405f 65 ok( !exec("lskdjfalksdjfdjfkls"),
66 "exec failure doesn't terminate process");
0994c4d0 67}
378cc40b 68
9247405f 69exec $^X, '-le', qq{${quote}print 'ok 12 - exec PROG, LIST'${quote}};
70fail("This should never be reached if the exec() worked");