shared hash keys and ++/--
[p5sagit/p5-mst-13.2.git] / t / op / exec.t
1 #!./perl
2
3 BEGIN: {
4     chdir 't' if -d 't';
5     @INC = ('../lib');
6 }
7
8 # supress VMS whinging about bad execs.
9 use vmsish qw(hushed);
10
11 $| = 1;                         # flush stdout
12
13 $ENV{LC_ALL}   = 'C';           # Forge English error messages.
14 $ENV{LANGUAGE} = 'C';           # Ditto in GNU.
15
16 require './test.pl';
17 plan(tests => 12);
18
19 my $exit;
20 SKIP: {
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' );
26 }
27
28 $exit = system qq{$^X -le "print q{ok 3 - split & direct call system(EXPR)"}};
29 next_test();
30 is( $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.
34 my $quote = $^O eq 'VMS' ? '"' : '';
35 $exit = system $^X, '-le', 
36                "${quote}print q{ok 5 - system(PROG, LIST)}${quote}";
37 next_test();
38 is( $exit, 0, '  exited 0' );
39
40
41 is( system(qq{$^X -e "exit 0"}), 0,     'Explicit exit of 0' );
42
43 my $exit_one = $^O eq 'VMS' ? 4 << 8 : 1 << 8;
44 is( 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";
49 unless( ok($rc == 255 << 8 or $rc == -1 or $rc == 256) ) {
50     print "# \$rc == $rc\n";
51 }
52
53 unless ( 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
59 TODO: {
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     }
64
65     ok( !exec("lskdjfalksdjfdjfkls"), 
66         "exec failure doesn't terminate process");
67 }
68
69 exec $^X, '-le', qq{${quote}print 'ok 12 - exec PROG, LIST'${quote}};
70 fail("This should never be reached if the exec() worked");