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