[t][TT #1610] Add tests for Parrot_compile_string
[parrot.git] / t / op / spawnw.t
blob724a08e74c6558840347987c5477e201defb7ccb
1 #!perl
2 # Copyright (C) 2001-2005, Parrot Foundation.
3 # $Id$
5 use strict;
6 use warnings;
7 use lib qw( . lib ../lib ../../lib );
8 use Test::More;
9 use Parrot::Test tests => 7;
11 =head1 NAME
13 t/op/spawnw.t - Run OS commands and tell about the exit code
15 =head1 SYNOPSIS
17         % prove t/op/spawnw.t
19 =head1 DESCRIPTION
21 Tests spawning external commands.
23 spawnw does not capture STDOUT and STDERR from the spawned command.
24 So only the exit code can be tested.
26 The returned value is actually returned from the 'waitpid' system call.
27 In order to get the exit code from the spawned process, it needs to be right
28 shifted by 8 bit.
30 TT #1271: Do not rely on the existence of Perl5 here. Spawn Parrot or some
31 other program which will exist on the target platform
33 =head1 TODO
35 Test negative return codes.
37 =head1 SEE ALSO
39 The special variable $? in Perl5.
41 =head1 AUTHOR
43 Nigel Sandever - L<nigelsandever@btconnect.com>
45 =cut
47 # perl command coded this way to avoid platform
48 # quoting issue.
50 # test string version of spawnw
52 pasm_output_is( <<'CODE', <<'OUTPUT', "exit code: 0" );
53         set     S1, 'perl -e "exit(0)"'
54         set     I1, 99
55         spawnw  I1, S1
56         shr     I2, I1, 8
57         print   "return code: "
58         print   I2
59         print   "\n"
60         end
61 CODE
62 return code: 0
63 OUTPUT
65 pasm_output_is( <<'CODE', <<'OUTPUT', "exit code: 123" );
66         set     S1, 'perl -e "exit(123)"'
67         set     I1, 99
68         spawnw  I1, S1
69         shr     I2, I1, 8
70         print   "return code: "
71         print   I2
72         print   "\n"
73         end
74 CODE
75 return code: 123
76 OUTPUT
78 pasm_output_is( <<'CODE', <<'OUTPUT', "exit code: 3" );
79         set     S1, 'perl -e "exit(3)"'
80         set     I1, 99
81         spawnw  I1, S1
82         shr     I2, I1, 8
83         print   "return code: "
84         print   I2
85         print   "\n"
86         end
87 CODE
88 return code: 3
89 OUTPUT
91 # test array version of spawnw
93 pasm_output_is( <<'CODE', <<'OUTPUT', "exit code: 0" );
94         new     P0, 'ResizablePMCArray'
95         set     P0, 3
96         set     P0[0], "perl"
97         set     P0[1], "-e"
98         set     P0[2], "exit(0)"
99         set     I1, 99
100         spawnw  I1, P0
101         shr     I2, I1, 8
102         print   "return code: "
103         print   I2
104         print   "\n"
105         end
106 CODE
107 return code: 0
108 OUTPUT
110 pasm_output_is( <<'CODE', <<'OUTPUT', "exit code: 123" );
111         new     P0, 'ResizablePMCArray'
112         set     P0, 3
113         set     P0[0], "perl"
114         set     P0[1], "-e"
115         set     P0[2], "exit(123)"
116         set     I1, 99
117         spawnw  I1, P0
118         shr     I2, I1, 8
119         print   "return code: "
120         print   I2
121         print   "\n"
122         end
123 CODE
124 return code: 123
125 OUTPUT
127 pasm_output_is( <<'CODE', <<'OUTPUT', "exit code: 3" );
128         new     P0, 'ResizablePMCArray'
129         set     P0, 3
130         set     P0[0], "perl"
131         set     P0[1], "-e"
132         set     P0[2], "exit(3)"
133         set     I1, 99
134         spawnw  I1, P0
135         shr     I2, I1, 8
136         print   "return code: "
137         print   I2
138         print   "\n"
139         end
140 CODE
141 return code: 3
142 OUTPUT
144 pir_output_is( <<'CODE', <<'OUTPUT', "grow argv buffer" );
145 .sub test :main
146         .local pmc args
148         $S0 = "exit length(qq{"
149         $I0 = 0
150 loop:
151         if $I0 >= 1000 goto end
152         $S0 = concat $S0, "A"
153         inc $I0
154         branch loop
155 end:
156         $S0 = concat $S0, "}) / 100"
157         new args, 'ResizablePMCArray'
158         push args, "perl"
159         push args, "-e"
160         push args, $S0
161         $I0 = spawnw args
162         shr $I1, $I0, 8
163         print   "return code: "
164         print   $I1
165         print   "\n"
166         end
167 .end
168 CODE
169 return code: 10
170 OUTPUT
172 # Local Variables:
173 #   mode: cperl
174 #   cperl-indent-level: 4
175 #   fill-column: 100
176 # End:
177 # vim: expandtab shiftwidth=4: