Commit | Line | Data |
8d063cd8 |
1 | #!./perl |
2 | |
9247405f |
3 | BEGIN: { |
4 | chdir 't' if -d 't'; |
5 | @INC = ('../lib'); |
972e7321 |
6 | require './test.pl'; |
9247405f |
7 | } |
8 | |
9 | # supress VMS whinging about bad execs. |
10 | use 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 |
17 | my $Is_VMS = $^O eq 'VMS'; |
18 | my $Is_Win32 = $^O eq 'MSWin32'; |
b6345914 |
19 | |
20 | plan(tests => 20); |
972e7321 |
21 | |
22 | my $Perl = which_perl(); |
68dc0745 |
23 | |
9247405f |
24 | my $exit; |
25 | SKIP: { |
26 | skip("bug/feature of pdksh", 2) if $^O eq 'os2'; |
27 | |
b6345914 |
28 | my $tnum = curr_test(); |
29 | $exit = system qq{$Perl -le "print q{ok $tnum - interp system(EXPR)"}}; |
9247405f |
30 | next_test(); |
31 | is( $exit, 0, ' exited 0' ); |
95e8664e |
32 | } |
33 | |
b6345914 |
34 | my $tnum = curr_test(); |
35 | $exit = system qq{$Perl -le "print q{ok $tnum - split & direct system(EXPR)"}}; |
9247405f |
36 | next_test(); |
37 | is( $exit, 0, ' exited 0' ); |
38 | |
e0d72a37 |
39 | # On VMS and Win32 you need the quotes around the program or it won't work. |
9247405f |
40 | # On Unix its the opposite. |
e0d72a37 |
41 | my $quote = $Is_VMS || $Is_Win32 ? '"' : ''; |
b6345914 |
42 | $tnum = curr_test(); |
972e7321 |
43 | $exit = system $Perl, '-le', |
b6345914 |
44 | "${quote}print q{ok $tnum - system(PROG, LIST)}${quote}"; |
9247405f |
45 | next_test(); |
46 | is( $exit, 0, ' exited 0' ); |
47 | |
8d063cd8 |
48 | |
b6345914 |
49 | # Some basic piped commands. Some OS's have trouble with "helpfully" |
50 | # putting newlines on the end of piped output. So we split this into |
51 | # newline insensitive and newline sensitive tests. |
52 | my $echo_out = `$Perl -e "print 'ok'" | $Perl -le "print <STDIN>"`; |
53 | $echo_out =~ s/\n\n/\n/g; |
54 | is( $echo_out, "ok\n", 'piped echo emulation'); |
55 | |
56 | { |
57 | # here we check if extra newlines are going to be slapped on |
58 | # piped output. |
59 | local $TODO = 'VMS sticks newlines on everything' if $Is_VMS; |
60 | |
61 | is( scalar `$Perl -e "print 'ok'"`, |
62 | "ok", 'no extra newlines on ``' ); |
63 | |
64 | is( scalar `$Perl -e "print 'ok'" | $Perl -e "print <STDIN>"`, |
65 | "ok", 'no extra newlines on pipes'); |
66 | |
67 | is( scalar `$Perl -le "print 'ok'" | $Perl -le "print <STDIN>"`, |
68 | "ok\n\n", 'doubled up newlines'); |
69 | |
70 | is( scalar `$Perl -e "print 'ok'" | $Perl -le "print <STDIN>"`, |
71 | "ok\n", 'extra newlines on inside pipes'); |
72 | |
73 | is( scalar `$Perl -le "print 'ok'" | $Perl -e "print <STDIN>"`, |
74 | "ok\n", 'extra newlines on outgoing pipes'); |
75 | } |
76 | |
77 | |
972e7321 |
78 | is( system(qq{$Perl -e "exit 0"}), 0, 'Explicit exit of 0' ); |
9247405f |
79 | |
b6345914 |
80 | my $exit_one = $Is_VMS ? 4 << 8 : 1 << 8; |
972e7321 |
81 | is( system(qq{$Perl "-I../lib" -e "use vmsish qw(hushed); exit 1"}), $exit_one, |
9247405f |
82 | 'Explicit exit of 1' ); |
83 | |
84 | |
85 | $rc = system "lskdfj"; |
86 | unless( ok($rc == 255 << 8 or $rc == -1 or $rc == 256) ) { |
87 | print "# \$rc == $rc\n"; |
ec40c0cd |
88 | } |
8d063cd8 |
89 | |
9247405f |
90 | unless ( ok( $! == 2 or $! =~ /\bno\b.*\bfile/i or |
91 | $! == 13 or $! =~ /permission denied/i or |
92 | $! == 22 or $! =~ /invalid argument/ ) ) { |
93 | printf "# \$! eq %d, '%s'\n", $!, $!; |
94 | } |
95 | |
972e7321 |
96 | |
97 | is( `$Perl -le "print 'ok'"`, "ok\n", 'basic ``' ); |
98 | is( <<`END`, "ok\n", '<<`HEREDOC`' ); |
99 | $Perl -le "print 'ok'" |
100 | END |
101 | |
102 | |
9247405f |
103 | TODO: { |
b6345914 |
104 | my $tnum = curr_test(); |
9247405f |
105 | if( $^O =~ /Win32/ ) { |
e0d72a37 |
106 | print "not ok $tnum - exec failure doesn't terminate process " . |
107 | "# TODO Win32 exec failure waits for user input\n"; |
108 | next_test(); |
9247405f |
109 | last TODO; |
110 | } |
378cc40b |
111 | |
9247405f |
112 | ok( !exec("lskdjfalksdjfdjfkls"), |
113 | "exec failure doesn't terminate process"); |
0994c4d0 |
114 | } |
378cc40b |
115 | |
972e7321 |
116 | my $test = curr_test(); |
117 | exec $Perl, '-le', qq{${quote}print 'ok $test - exec PROG, LIST'${quote}}; |
9247405f |
118 | fail("This should never be reached if the exec() worked"); |