Commit | Line | Data |
---|---|---|
8d063cd8 LW |
1 | #!./perl |
2 | ||
90ce63d5 | 3 | BEGIN { |
90ce63d5 RS |
4 | $| = 1; |
5 | chdir 't' if -d 't'; | |
20822f61 | 6 | @INC = '../lib'; |
774d564b | 7 | $SIG{__WARN__} = sub { die "Dying on warning: ", @_ }; |
90ce63d5 | 8 | } |
8d063cd8 | 9 | |
9f1b1f2d | 10 | use warnings; |
04fee9b5 | 11 | use Config; |
9f1b1f2d | 12 | |
0bee926d | 13 | my $test = 1; |
90ce63d5 | 14 | sub ok { |
0bee926d MS |
15 | my($ok, $info, $todo) = @_; |
16 | ||
17 | # You have to do it this way or VMS will get confused. | |
18 | printf "%s $test%s\n", $ok ? "ok" : "not ok", | |
19 | $todo ? " # TODO $todo" : ''; | |
20 | ||
21 | unless( $ok ) { | |
22 | printf "# Failed test at line %d\n", (caller)[2]; | |
09fdc078 | 23 | print "# $info\n" if defined $info; |
90ce63d5 | 24 | } |
0bee926d MS |
25 | |
26 | $test++; | |
27 | return $ok; | |
28 | } | |
29 | ||
30 | sub skip { | |
31 | my($reason) = @_; | |
32 | ||
33 | printf "ok $test # skipped%s\n", defined $reason ? ": $reason" : ''; | |
34 | ||
35 | $test++; | |
36 | return 1; | |
90ce63d5 RS |
37 | } |
38 | ||
ecce83c2 | 39 | print "1..53\n"; |
0bee926d | 40 | |
3e3baf6d | 41 | $Is_MSWin32 = $^O eq 'MSWin32'; |
2986a63f | 42 | $Is_NetWare = $^O eq 'NetWare'; |
3e3baf6d | 43 | $Is_VMS = $^O eq 'VMS'; |
be708cc0 JH |
44 | $Is_Dos = $^O eq 'dos'; |
45 | $Is_os2 = $^O eq 'os2'; | |
46 | $Is_Cygwin = $^O eq 'cygwin'; | |
47 | $Is_MacOS = $^O eq 'MacOS'; | |
dc22e1c4 | 48 | $Is_MPE = $^O eq 'mpeix'; |
be708cc0 | 49 | |
c363d00c CB |
50 | $PERL = ($Is_NetWare ? 'perl' : |
51 | ($Is_MacOS || $Is_VMS) ? $^X : | |
52 | $Is_MSWin32 ? '.\perl' : | |
be708cc0 | 53 | './perl'); |
68dc0745 | 54 | |
39e571d4 | 55 | eval '$ENV{"FOO"} = "hi there";'; # check that ENV is inited inside eval |
26f6e342 NK |
56 | # cmd.exe will echo 'variable=value' but 4nt will echo just the value |
57 | # -- Nikola Knezevic | |
8efe09f7 | 58 | if ($Is_MSWin32) { ok `set FOO` =~ /^(?:FOO=)?hi there$/; } |
be708cc0 | 59 | elsif ($Is_MacOS) { ok "1 # skipped", 1; } |
c363d00c | 60 | elsif ($Is_VMS) { ok `write sys\$output f\$trnlnm("FOO")` eq "hi there\n"; } |
be708cc0 | 61 | else { ok `echo \$FOO` eq "hi there\n"; } |
8d063cd8 | 62 | |
bf38876a | 63 | unlink 'ajslkdfpqjsjfk'; |
8d063cd8 | 64 | $! = 0; |
90ce63d5 | 65 | open(FOO,'ajslkdfpqjsjfk'); |
0bee926d | 66 | ok $!, $!; |
90ce63d5 | 67 | close FOO; # just mention it, squelch used-only-once |
8d063cd8 | 68 | |
be708cc0 | 69 | if ($Is_MSWin32 || $Is_NetWare || $Is_Dos || $Is_MPE || $Is_MacOS) { |
2d4fcd5e | 70 | skip('SIGINT not safe on this platform') for 1..4; |
68dc0745 | 71 | } |
72 | else { | |
c363d00c CB |
73 | # the next tests are done in a subprocess because sh spits out a |
74 | # newline onto stderr when a child process kills itself with SIGINT. | |
04fee9b5 | 75 | # We use a pipe rather than system() because the VMS command buffer |
c363d00c CB |
76 | # would overflow with a command that long. |
77 | ||
78 | open( CMDPIPE, "| $PERL"); | |
79 | ||
80 | print CMDPIPE <<'END'; | |
378cc40b | 81 | |
79072805 | 82 | $| = 1; # command buffering |
378cc40b | 83 | |
b715f106 MB |
84 | $SIG{"INT"} = "ok3"; kill "INT",$$; sleep 1; |
85 | $SIG{"INT"} = "IGNORE"; kill "INT",$$; sleep 1; print "ok 4\n"; | |
0bee926d | 86 | $SIG{"INT"} = "DEFAULT"; kill "INT",$$; sleep 1; print "not ok 4\n"; |
79072805 LW |
87 | |
88 | sub ok3 { | |
89 | if (($x = pop(@_)) eq "INT") { | |
90 | print "ok 3\n"; | |
91 | } | |
92 | else { | |
652ed9f8 | 93 | print "not ok 3 ($x @_)\n"; |
79072805 LW |
94 | } |
95 | } | |
96 | ||
97 | END | |
c363d00c CB |
98 | |
99 | close CMDPIPE; | |
100 | ||
2d4fcd5e AJ |
101 | open( CMDPIPE, "| $PERL"); |
102 | print CMDPIPE <<'END'; | |
103 | ||
104 | { package X; | |
105 | sub DESTROY { | |
106 | kill "INT",$$; | |
107 | } | |
108 | } | |
109 | sub x { | |
110 | my $x=bless [], 'X'; | |
111 | return sub { $x }; | |
112 | } | |
113 | $| = 1; # command buffering | |
114 | $SIG{"INT"} = "ok5"; | |
115 | { | |
116 | local $SIG{"INT"}=x(); | |
117 | print ""; # Needed to expose failure in 5.8.0 (why?) | |
118 | } | |
119 | sleep 1; | |
120 | delete $SIG{"INT"}; | |
121 | kill "INT",$$; sleep 1; | |
122 | sub ok5 { | |
123 | print "ok 5\n"; | |
124 | } | |
125 | END | |
126 | close CMDPIPE; | |
bb4e15c8 | 127 | $? >>= 8 if $^O eq 'VMS'; # POSIX status hiding in 2nd byte |
2d4fcd5e AJ |
128 | print $? & 0xFF ? "ok 6\n" : "not ok 6\n"; |
129 | ||
130 | $test += 4; | |
68dc0745 | 131 | } |
a687059c | 132 | |
68dc0745 | 133 | # can we slice ENV? |
134 | @val1 = @ENV{keys(%ENV)}; | |
a687059c | 135 | @val2 = values(%ENV); |
0bee926d MS |
136 | ok join(':',@val1) eq join(':',@val2); |
137 | ok @val1 > 1; | |
90ce63d5 RS |
138 | |
139 | # regex vars | |
140 | 'foobarbaz' =~ /b(a)r/; | |
0bee926d MS |
141 | ok $` eq 'foo', $`; |
142 | ok $& eq 'bar', $&; | |
143 | ok $' eq 'baz', $'; | |
144 | ok $+ eq 'a', $+; | |
90ce63d5 RS |
145 | |
146 | # $" | |
147 | @a = qw(foo bar baz); | |
0bee926d | 148 | ok "@a" eq "foo bar baz", "@a"; |
90ce63d5 RS |
149 | { |
150 | local $" = ','; | |
0bee926d | 151 | ok "@a" eq "foo,bar,baz", "@a"; |
90ce63d5 | 152 | } |
a687059c | 153 | |
90ce63d5 RS |
154 | # $; |
155 | %h = (); | |
156 | $h{'foo', 'bar'} = 1; | |
0bee926d | 157 | ok((keys %h)[0] eq "foo\034bar", (keys %h)[0]); |
90ce63d5 RS |
158 | { |
159 | local $; = 'x'; | |
160 | %h = (); | |
161 | $h{'foo', 'bar'} = 1; | |
0bee926d | 162 | ok((keys %h)[0] eq 'fooxbar', (keys %h)[0]); |
90ce63d5 | 163 | } |
ed6116ce | 164 | |
90ce63d5 | 165 | # $?, $@, $$ |
dc459aad JH |
166 | if ($Is_MacOS) { |
167 | skip('$? + system are broken on MacPerl') for 1..2; | |
168 | } | |
169 | else { | |
170 | system qq[$PERL "-I../lib" -e "use vmsish qw(hushed); exit(0)"]; | |
171 | ok $? == 0, $?; | |
172 | system qq[$PERL "-I../lib" -e "use vmsish qw(hushed); exit(1)"]; | |
173 | ok $? != 0, $?; | |
174 | } | |
90ce63d5 RS |
175 | |
176 | eval { die "foo\n" }; | |
0bee926d | 177 | ok $@ eq "foo\n", $@; |
90ce63d5 | 178 | |
0bee926d | 179 | ok $$ > 0, $$; |
306196c3 MS |
180 | eval { $$++ }; |
181 | ok $@ =~ /^Modification of a read-only value attempted/; | |
90ce63d5 RS |
182 | |
183 | # $^X and $0 | |
ed37317b | 184 | { |
3e3baf6d | 185 | if ($^O eq 'qnx') { |
7fbf1995 | 186 | chomp($wd = `/usr/bin/fullpath -t`); |
68dc0745 | 187 | } |
04fee9b5 | 188 | elsif($Is_Cygwin || $Config{'d_procselfexe'}) { |
1cab015a EF |
189 | # Cygwin turns the symlink into the real file |
190 | chomp($wd = `pwd`); | |
191 | $wd =~ s#/t$##; | |
192 | } | |
ed344e4f IZ |
193 | elsif($Is_os2) { |
194 | $wd = Cwd::sys_cwd(); | |
195 | } | |
be708cc0 JH |
196 | elsif($Is_MacOS) { |
197 | $wd = ':'; | |
198 | } | |
68dc0745 | 199 | else { |
200 | $wd = '.'; | |
201 | } | |
c363d00c | 202 | my $perl = ($Is_MacOS || $Is_VMS) ? $^X : "$wd/perl"; |
ed37317b TB |
203 | my $headmaybe = ''; |
204 | my $tailmaybe = ''; | |
68dc0745 | 205 | $script = "$wd/show-shebang"; |
ed37317b TB |
206 | if ($Is_MSWin32) { |
207 | chomp($wd = `cd`); | |
8ac9c18d GS |
208 | $wd =~ s|\\|/|g; |
209 | $perl = "$wd/perl.exe"; | |
210 | $script = "$wd/show-shebang.bat"; | |
ed37317b TB |
211 | $headmaybe = <<EOH ; |
212 | \@rem =' | |
213 | \@echo off | |
214 | $perl -x \%0 | |
215 | goto endofperl | |
216 | \@rem '; | |
217 | EOH | |
218 | $tailmaybe = <<EOT ; | |
219 | ||
220 | __END__ | |
221 | :endofperl | |
222 | EOT | |
223 | } | |
ed344e4f IZ |
224 | elsif ($Is_os2) { |
225 | $script = "./show-shebang"; | |
226 | } | |
be708cc0 JH |
227 | elsif ($Is_MacOS) { |
228 | $script = ":show-shebang"; | |
229 | } | |
c363d00c CB |
230 | elsif ($Is_VMS) { |
231 | $script = "[]show-shebang"; | |
be708cc0 | 232 | } |
a1a0e61e | 233 | if ($^O eq 'os390' or $^O eq 'posix-bc' or $^O eq 'vmesa') { # no shebang |
9d116dd7 JH |
234 | $headmaybe = <<EOH ; |
235 | eval 'exec ./perl -S \$0 \${1+"\$\@"}' | |
236 | if 0; | |
237 | EOH | |
238 | } | |
2eecd615 | 239 | $s1 = "\$^X is $perl, \$0 is $script\n"; |
0bee926d MS |
240 | ok open(SCRIPT, ">$script"), $!; |
241 | ok print(SCRIPT $headmaybe . <<EOB . <<'EOF' . $tailmaybe), $!; | |
774d564b | 242 | #!$wd/perl |
243 | EOB | |
90ce63d5 RS |
244 | print "\$^X is $^X, \$0 is $0\n"; |
245 | EOF | |
0bee926d MS |
246 | ok close(SCRIPT), $!; |
247 | ok chmod(0755, $script), $!; | |
c363d00c | 248 | $_ = ($Is_MacOS || $Is_VMS) ? `$perl $script` : `$script`; |
ed344e4f | 249 | s/\.exe//i if $Is_Dos or $Is_Cygwin or $Is_os2; |
68dc0745 | 250 | s{\bminiperl\b}{perl}; # so that test doesn't fail with miniperl |
ed37317b | 251 | s{is perl}{is $perl}; # for systems where $^X is only a basename |
a6c40364 | 252 | s{\\}{/}g; |
0bee926d | 253 | ok((($Is_MSWin32 || $Is_os2) ? uc($_) eq uc($s1) : $_ eq $s1), " :$_:!=:$s1:"); |
ed37317b | 254 | $_ = `$perl $script`; |
ed344e4f | 255 | s/\.exe//i if $Is_Dos or $Is_os2; |
a6c40364 | 256 | s{\\}{/}g; |
0bee926d | 257 | ok((($Is_MSWin32 || $Is_os2) ? uc($_) eq uc($s1) : $_ eq $s1), " :$_:!=:$s1: after `$perl $script`"); |
22fc9b38 | 258 | ok unlink($script), $!; |
68dc0745 | 259 | } |
ed6116ce | 260 | |
90ce63d5 | 261 | # $], $^O, $^T |
0bee926d MS |
262 | ok $] >= 5.00319, $]; |
263 | ok $^O; | |
264 | ok $^T > 850000000, $^T; | |
66b1d557 | 265 | |
be708cc0 | 266 | if ($Is_VMS || $Is_Dos || $Is_MacOS) { |
44d95355 | 267 | skip("%ENV manipulations fail or aren't safe on $^O") for 1..4; |
66b1d557 HM |
268 | } |
269 | else { | |
3e3baf6d | 270 | $PATH = $ENV{PATH}; |
7ddf2a0a | 271 | $PDL = $ENV{PERL_DESTRUCT_LEVEL} || 0; |
3e3baf6d TB |
272 | $ENV{foo} = "bar"; |
273 | %ENV = (); | |
274 | $ENV{PATH} = $PATH; | |
7ddf2a0a | 275 | $ENV{PERL_DESTRUCT_LEVEL} = $PDL || 0; |
0bee926d | 276 | ok ($Is_MSWin32 ? (`set foo 2>NUL` eq "") |
3e3baf6d TB |
277 | : (`echo \$foo` eq "\n") ); |
278 | ||
ec00bdd8 | 279 | $ENV{__NoNeSuCh} = "foo"; |
3e3baf6d | 280 | $0 = "bar"; |
26f6e342 NK |
281 | # cmd.exe will echo 'variable=value' but 4nt will echo just the value |
282 | # -- Nikola Knezevic | |
8efe09f7 | 283 | ok ($Is_MSWin32 ? (`set __NoNeSuCh` =~ /^(?:__NoNeSuCh=)?foo$/) |
ec00bdd8 | 284 | : (`echo \$__NoNeSuCh` eq "foo\n") ); |
09fdc078 SR |
285 | if ($^O =~ /^(linux|freebsd)$/ && |
286 | open CMDLINE, "/proc/$$/cmdline") { | |
287 | chomp(my $line = scalar <CMDLINE>); | |
288 | my $me = (split /\0/, $line)[0]; | |
ecce83c2 | 289 | ok($me eq $0, 'altering $0 is effective (testing with /proc/)'); |
09fdc078 | 290 | close CMDLINE; |
ecce83c2 JH |
291 | # perlbug #22811 |
292 | my $mydollarzero = sub { | |
293 | my($arg) = shift; | |
294 | $0 = $arg if defined $arg; | |
fbd3c14b SR |
295 | # In FreeBSD the ps -o command= will cause |
296 | # an empty header line, grab only the last line. | |
297 | my $ps = (`ps -o command= -p $$`)[-1]; | |
ecce83c2 JH |
298 | return if $?; |
299 | chomp $ps; | |
300 | printf "# 0[%s]ps[%s]\n", $0, $ps; | |
301 | $ps; | |
302 | }; | |
303 | my $ps = $mydollarzero->("x"); | |
e26ae24d | 304 | ok(!$ps # we allow that something goes wrong with the ps command |
80bca1b4 JH |
305 | # In Linux 2.4 we would get an exact match ($ps eq 'x') but |
306 | # in Linux 2.2 there seems to be something funny going on: | |
307 | # it seems as if the original length of the argv[] would | |
308 | # be stored in the proc struct and then used by ps(1), | |
309 | # no matter what characters we use to pad the argv[]. | |
310 | # (And if we use \0:s, they are shown as spaces.) Sigh. | |
311 | || $ps =~ /^x\s*$/ | |
6a4647a3 JH |
312 | # FreeBSD cannot get rid of both the leading "perl :" |
313 | # and the trailing " (perl)": some FreeBSD versions | |
314 | # can get rid of the first one. | |
d2e0b13f | 315 | || ($^O eq 'freebsd' && $ps =~ m/^(?:perl: )?x(?: \(perl\))?$/), |
e26ae24d | 316 | 'altering $0 is effective (testing with `ps`)'); |
09fdc078 | 317 | } else { |
651aa52e | 318 | skip("\$0 check only on Linux and FreeBSD") for 0, 1; |
09fdc078 | 319 | } |
66b1d557 | 320 | } |
3e3baf6d | 321 | |
c7213721 | 322 | { |
a45269de MS |
323 | my $ok = 1; |
324 | my $warn = ''; | |
325 | local $SIG{'__WARN__'} = sub { $ok = 0; $warn = join '', @_; }; | |
78987ded | 326 | $! = undef; |
a45269de | 327 | ok($ok, $warn, $Is_VMS ? "'\$!=undef' does throw a warning" : ''); |
78987ded HS |
328 | } |
329 | ||
902173a3 GS |
330 | # test case-insignificance of %ENV (these tests must be enabled only |
331 | # when perl is compiled with -DENV_IS_CASELESS) | |
2986a63f | 332 | if ($Is_MSWin32 || $Is_NetWare) { |
902173a3 GS |
333 | %ENV = (); |
334 | $ENV{'Foo'} = 'bar'; | |
335 | $ENV{'fOo'} = 'baz'; | |
0bee926d MS |
336 | ok (scalar(keys(%ENV)) == 1); |
337 | ok exists($ENV{'FOo'}); | |
338 | ok (delete($ENV{'foO'}) eq 'baz'); | |
339 | ok (scalar(keys(%ENV)) == 0); | |
902173a3 GS |
340 | } |
341 | else { | |
0bee926d | 342 | skip('no caseless %ENV support') for 1..4; |
902173a3 | 343 | } |
d2c93421 | 344 | |
126c71c8 YST |
345 | { |
346 | no warnings 'void'; | |
347 | ||
d2c93421 RH |
348 | # Make sure Errno hasn't been prematurely autoloaded |
349 | ||
126c71c8 | 350 | ok !defined %Errno::; |
d2c93421 RH |
351 | |
352 | # Test auto-loading of Errno when %! is used | |
353 | ||
126c71c8 YST |
354 | ok scalar eval q{ |
355 | %!; | |
356 | defined %Errno::; | |
357 | }, $@; | |
358 | } | |
d2c93421 RH |
359 | |
360 | ||
361 | # Make sure that Errno loading doesn't clobber $! | |
362 | ||
363 | undef %Errno::; | |
364 | delete $INC{"Errno.pm"}; | |
365 | ||
366 | open(FOO, "nonesuch"); # Generate ENOENT | |
367 | my %errs = %{"!"}; # Cause Errno.pm to be loaded at run-time | |
0bee926d | 368 | ok ${"!"}{ENOENT}; |
a4268c0a | 369 | |
b0e6f864 | 370 | ok $^S == 0 && defined $^S; |
0bee926d | 371 | eval { ok $^S == 1 }; |
b0e6f864 RGS |
372 | eval " BEGIN { ok ! defined \$^S } "; |
373 | ok $^S == 0 && defined $^S; | |
7c36658b MS |
374 | |
375 | ok ${^TAINT} == 0; | |
376 | eval { ${^TAINT} = 1 }; | |
377 | ok ${^TAINT} == 0; | |
9aa702ec MJD |
378 | |
379 | # 5.6.1 had a bug: @+ and @- were not properly interpolated | |
380 | # into double-quoted strings | |
381 | # 20020414 mjd-perl-patch+@plover.com | |
b64ebf53 JH |
382 | "I like pie" =~ /(I) (like) (pie)/; |
383 | ok "@-" eq "0 0 2 7"; | |
384 | ok "@+" eq "10 1 6 10"; | |
9aa702ec | 385 | |
f28098ff RGS |
386 | # Tests for the magic get of $\ |
387 | { | |
388 | my $ok = 0; | |
389 | # [perl #19330] | |
390 | { | |
391 | local $\ = undef; | |
392 | $\++; $\++; | |
393 | $ok = $\ eq 2; | |
394 | } | |
395 | ok $ok; | |
396 | $ok = 0; | |
397 | { | |
398 | local $\ = "a\0b"; | |
399 | $ok = "a$\b" eq "aa\0bb"; | |
400 | } | |
401 | ok $ok; | |
402 | } |