This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
skip the defined *+ and *- tests on miniperl
[perl5.git] / t / op / magic.t
CommitLineData
8d063cd8
LW
1#!./perl
2
90ce63d5 3BEGIN {
90ce63d5
RS
4 $| = 1;
5 chdir 't' if -d 't';
20822f61 6 @INC = '../lib';
5e9f035f
FC
7 require './test.pl';
8 plan (tests => 145);
9}
10
11# Test that defined() returns true for magic variables created on the fly,
12# even before they have been created.
13# This must come first, even before turning on warnings or setting up
14# $SIG{__WARN__}, to avoid invalidating the tests. warnings.pm currently
15# does not mention any special variables, but that could easily change.
16BEGIN {
811a7562
TC
17 # not available in miniperl
18 my %non_mini = map { $_ => 1 } qw(+ -);
5e9f035f
FC
19 for (qw(
20 SIG ^OPEN ^TAINT ^UNICODE ^UTF8LOCALE ^WARNING_BITS 1 2 3 4 5 6 7 8
21 9 42 & ` ' : ? ! _ - # [ ^ ~ = % . ( ) < > \ / $ | + ; ] ^A ^C ^D
22 ^E ^F ^H ^I ^L ^N ^O ^P ^S ^T ^V ^W
23 )) {
24 my $v = $_;
25 # avoid using any global vars here:
26 if ($v =~ s/^\^(?=.)//) {
27 for(substr $v, 0, 1) {
28 $_ = chr ord() - 64;
29 }
30 }
811a7562
TC
31 SKIP:
32 {
33 skip_if_miniperl("the module for *$_ may not be available in "
34 . "miniperl", 1) if $non_mini{$_};
35 ok defined *$v, "*$_ appears to be defined at the outset";
36 }
5e9f035f
FC
37 }
38}
39
40# This must be in a separate BEGIN block, as the mere mention of ${^TAINT}
41# will invalidate the test for it.
42BEGIN {
0409250f 43 $ENV{PATH} = '/bin' if ${^TAINT};
774d564b 44 $SIG{__WARN__} = sub { die "Dying on warning: ", @_ };
90ce63d5 45}
8d063cd8 46
9f1b1f2d 47use warnings;
04fee9b5 48use Config;
9f1b1f2d 49
0bee926d 50
43651d81
NC
51$Is_MSWin32 = $^O eq 'MSWin32';
52$Is_NetWare = $^O eq 'NetWare';
53$Is_VMS = $^O eq 'VMS';
54$Is_Dos = $^O eq 'dos';
55$Is_os2 = $^O eq 'os2';
56$Is_Cygwin = $^O eq 'cygwin';
43651d81 57$Is_MPE = $^O eq 'mpeix';
dbc1d986 58$Is_BeOS = $^O eq 'beos';
be708cc0 59
c8d62b71
RGS
60$PERL = $ENV{PERL}
61 || ($Is_NetWare ? 'perl' :
7b903762 62 $Is_VMS ? $^X :
c8d62b71
RGS
63 $Is_MSWin32 ? '.\perl' :
64 './perl');
68dc0745 65
8df0e0ed
JM
66END {
67 # On VMS, environment variable changes are peristent after perl exits
68 delete $ENV{'FOO'} if $Is_VMS;
69}
70
39e571d4 71eval '$ENV{"FOO"} = "hi there";'; # check that ENV is inited inside eval
26f6e342
NK
72# cmd.exe will echo 'variable=value' but 4nt will echo just the value
73# -- Nikola Knezevic
b2978f4e 74if ($Is_MSWin32) { like `set FOO`, qr/^(?:FOO=)?hi there$/; }
b2978f4e
NC
75elsif ($Is_VMS) { is `write sys\$output f\$trnlnm("FOO")`, "hi there\n"; }
76else { is `echo \$FOO`, "hi there\n"; }
8d063cd8 77
ba2406eb 78unlink_all 'ajslkdfpqjsjfk';
8d063cd8 79$! = 0;
90ce63d5 80open(FOO,'ajslkdfpqjsjfk');
b2978f4e 81isnt($!, 0);
90ce63d5 82close FOO; # just mention it, squelch used-only-once
8d063cd8 83
b2978f4e
NC
84SKIP: {
85 skip('SIGINT not safe on this platform', 5)
7b903762 86 if $Is_MSWin32 || $Is_NetWare || $Is_Dos || $Is_MPE;
c363d00c
CB
87 # the next tests are done in a subprocess because sh spits out a
88 # newline onto stderr when a child process kills itself with SIGINT.
04fee9b5 89 # We use a pipe rather than system() because the VMS command buffer
c363d00c
CB
90 # would overflow with a command that long.
91
5e9f035f
FC
92 # For easy interpolation of test numbers:
93 $next_test = curr_test() - 1;
94 sub TIEARRAY {bless[]}
95 sub FETCH { $next_test + pop }
96 tie my @tn, __PACKAGE__;
97
c363d00c
CB
98 open( CMDPIPE, "| $PERL");
99
5e9f035f 100 print CMDPIPE "\$t1 = $tn[1]; \$t2 = $tn[2];\n", <<'END';
378cc40b 101
79072805 102 $| = 1; # command buffering
378cc40b 103
5e9f035f
FC
104 $SIG{"INT"} = "ok1"; kill "INT",$$; sleep 1;
105 $SIG{"INT"} = "IGNORE"; kill "INT",$$; sleep 1; print "ok $t2\n";
106 $SIG{"INT"} = "DEFAULT"; kill "INT",$$; sleep 1; print" not ok $t2\n";
79072805 107
5e9f035f 108 sub ok1 {
79072805 109 if (($x = pop(@_)) eq "INT") {
5e9f035f 110 print "ok $t1\n";
79072805
LW
111 }
112 else {
5e9f035f 113 print "not ok $t1 ($x @_)\n";
79072805
LW
114 }
115 }
116
117END
c363d00c
CB
118
119 close CMDPIPE;
120
2d4fcd5e 121 open( CMDPIPE, "| $PERL");
5e9f035f 122 print CMDPIPE "\$t3 = $tn[3];\n", <<'END';
2d4fcd5e
AJ
123
124 { package X;
125 sub DESTROY {
126 kill "INT",$$;
127 }
128 }
129 sub x {
130 my $x=bless [], 'X';
131 return sub { $x };
132 }
133 $| = 1; # command buffering
5e9f035f 134 $SIG{"INT"} = "ok3";
2d4fcd5e
AJ
135 {
136 local $SIG{"INT"}=x();
137 print ""; # Needed to expose failure in 5.8.0 (why?)
138 }
139 sleep 1;
140 delete $SIG{"INT"};
141 kill "INT",$$; sleep 1;
5e9f035f
FC
142 sub ok3 {
143 print "ok $t3\n";
2d4fcd5e
AJ
144 }
145END
146 close CMDPIPE;
bb4e15c8 147 $? >>= 8 if $^O eq 'VMS'; # POSIX status hiding in 2nd byte
639cf43b 148 my $todo = ($^O eq 'os2' ? ' # TODO: EMX v0.9d_fix4 bug: wrong nibble? ' : '');
5e9f035f 149 print $? & 0xFF ? "ok $tn[4]$todo\n" : "not ok $tn[4]$todo\n";
2d4fcd5e 150
6e592b3a
BM
151 open(CMDPIPE, "| $PERL");
152 print CMDPIPE <<'END';
153
154 sub PVBM () { 'foo' }
155 index 'foo', PVBM;
156 my $pvbm = PVBM;
157
158 sub foo { exit 0 }
159
160 $SIG{"INT"} = $pvbm;
161 kill "INT", $$; sleep 1;
162END
163 close CMDPIPE;
164 $? >>= 8 if $^O eq 'VMS';
5e9f035f 165 print $? ? "not ok $tn[5]\n" : "ok $tn[5]\n";
6e592b3a 166
b2978f4e 167 curr_test(curr_test() + 5);
68dc0745 168}
a687059c 169
68dc0745
PP
170# can we slice ENV?
171@val1 = @ENV{keys(%ENV)};
a687059c 172@val2 = values(%ENV);
b2978f4e
NC
173is join(':',@val1), join(':',@val2);
174cmp_ok @val1, '>', 1;
90ce63d5
RS
175
176# regex vars
177'foobarbaz' =~ /b(a)r/;
b2978f4e
NC
178is $`, 'foo';
179is $&, 'bar';
180is $', 'baz';
181is $+, 'a';
90ce63d5
RS
182
183# $"
184@a = qw(foo bar baz);
b2978f4e 185is "@a", "foo bar baz";
90ce63d5
RS
186{
187 local $" = ',';
b2978f4e 188 is "@a", "foo,bar,baz";
90ce63d5 189}
a687059c 190
90ce63d5
RS
191# $;
192%h = ();
193$h{'foo', 'bar'} = 1;
b2978f4e 194is((keys %h)[0], "foo\034bar");
90ce63d5
RS
195{
196 local $; = 'x';
197 %h = ();
198 $h{'foo', 'bar'} = 1;
b2978f4e 199 is((keys %h)[0], 'fooxbar');
90ce63d5 200}
ed6116ce 201
90ce63d5 202# $?, $@, $$
7b903762
RGS
203system qq[$PERL "-I../lib" -e "use vmsish qw(hushed); exit(0)"];
204is $?, 0;
205system qq[$PERL "-I../lib" -e "use vmsish qw(hushed); exit(1)"];
206isnt $?, 0;
90ce63d5
RS
207
208eval { die "foo\n" };
b2978f4e 209is $@, "foo\n";
90ce63d5 210
b2978f4e 211cmp_ok($$, '>', 0);
41e07bbc 212my $pid = $$;
9cdac2a2
FC
213eval { $$ = 42 };
214is $$, 42, '$$ can be modified';
215SKIP: {
216 skip "no fork", 1 unless $Config{d_fork};
217 (my $kidpid = open my $fh, "-|") // skip "cannot fork: $!", 1;
218 if($kidpid) { # parent
219 my $kiddollars = <$fh>;
220 close $fh or die "cannot close pipe from kid proc: $!";
221 is $kiddollars, $kidpid, '$$ is reset on fork';
222 }
223 else { # child
224 print $$;
225 $::NO_ENDING = 1; # silence "Looks like you only ran..."
226 exit;
227 }
228}
41e07bbc 229$$ = $pid; # Tests below use $$
90ce63d5
RS
230
231# $^X and $0
ed37317b 232{
3e3baf6d 233 if ($^O eq 'qnx') {
7fbf1995 234 chomp($wd = `/usr/bin/fullpath -t`);
68dc0745 235 }
04fee9b5 236 elsif($Is_Cygwin || $Config{'d_procselfexe'}) {
1cab015a
FE
237 # Cygwin turns the symlink into the real file
238 chomp($wd = `pwd`);
239 $wd =~ s#/t$##;
0409250f 240 $wd =~ /(.*)/; $wd = $1; # untaint
6178c52a
JH
241 if ($Is_Cygwin) {
242 $wd = Cygwin::win_to_posix_path(Cygwin::posix_to_win_path($wd, 1));
243 }
1cab015a 244 }
ed344e4f
IZ
245 elsif($Is_os2) {
246 $wd = Cwd::sys_cwd();
247 }
68dc0745
PP
248 else {
249 $wd = '.';
250 }
0f77baf6 251 my $perl = $Is_VMS || $Config{d_procselfexe} ? $^X : "$wd/perl";
ed37317b 252 my $headmaybe = '';
6178c52a 253 my $middlemaybe = '';
ed37317b 254 my $tailmaybe = '';
68dc0745 255 $script = "$wd/show-shebang";
ed37317b
TB
256 if ($Is_MSWin32) {
257 chomp($wd = `cd`);
8ac9c18d
GS
258 $wd =~ s|\\|/|g;
259 $perl = "$wd/perl.exe";
260 $script = "$wd/show-shebang.bat";
ed37317b
TB
261 $headmaybe = <<EOH ;
262\@rem ='
263\@echo off
264$perl -x \%0
265goto endofperl
266\@rem ';
267EOH
268 $tailmaybe = <<EOT ;
269
270__END__
271:endofperl
272EOT
273 }
ed344e4f
IZ
274 elsif ($Is_os2) {
275 $script = "./show-shebang";
276 }
c363d00c
CB
277 elsif ($Is_VMS) {
278 $script = "[]show-shebang";
be708cc0 279 }
6178c52a
JH
280 elsif ($Is_Cygwin) {
281 $middlemaybe = <<'EOX'
282$^X = Cygwin::win_to_posix_path(Cygwin::posix_to_win_path($^X, 1));
283$0 = Cygwin::win_to_posix_path(Cygwin::posix_to_win_path($0, 1));
284EOX
285 }
a1a0e61e 286 if ($^O eq 'os390' or $^O eq 'posix-bc' or $^O eq 'vmesa') { # no shebang
9d116dd7
JH
287 $headmaybe = <<EOH ;
288 eval 'exec ./perl -S \$0 \${1+"\$\@"}'
289 if 0;
290EOH
291 }
2eecd615 292 $s1 = "\$^X is $perl, \$0 is $script\n";
0409250f 293 ok open(SCRIPT, ">$script") or diag "Can't write to $script: $!";
b2978f4e 294 ok print(SCRIPT $headmaybe . <<EOB . $middlemaybe . <<'EOF' . $tailmaybe) or diag $!;
0f77baf6 295#!$perl
774d564b 296EOB
90ce63d5
RS
297print "\$^X is $^X, \$0 is $0\n";
298EOF
b2978f4e
NC
299 ok close(SCRIPT) or diag $!;
300 ok chmod(0755, $script) or diag $!;
7b903762 301 $_ = $Is_VMS ? `$perl $script` : `$script`;
ed344e4f 302 s/\.exe//i if $Is_Dos or $Is_Cygwin or $Is_os2;
dbc1d986 303 s{./$script}{$script} if $Is_BeOS; # revert BeOS execvp() side-effect
ed37317b 304 s{is perl}{is $perl}; # for systems where $^X is only a basename
a6c40364 305 s{\\}{/}g;
b2978f4e
NC
306 if ($Is_MSWin32 || $Is_os2) {
307 is uc $_, uc $s1;
308 } else {
309 is $_, $s1;
310 }
ed37317b 311 $_ = `$perl $script`;
4bbb7126 312 s/\.exe//i if $Is_Dos or $Is_os2 or $Is_Cygwin;
dbc1d986 313 s{./$perl}{$perl} if $Is_BeOS; # revert BeOS execvp() side-effect
a6c40364 314 s{\\}{/}g;
b2978f4e
NC
315 if ($Is_MSWin32 || $Is_os2) {
316 is uc $_, uc $s1;
317 } else {
318 is $_, $s1;
319 }
320 ok unlink($script) or diag $!;
ba2406eb
BG
321 # CHECK
322 # Could this be replaced with:
323 # unlink_all($script);
68dc0745 324}
ed6116ce 325
90ce63d5 326# $], $^O, $^T
b2978f4e 327cmp_ok $], '>=', 5.00319;
0bee926d 328ok $^O;
b2978f4e 329cmp_ok $^T, '>', 850000000;
66b1d557 330
881ddac4
SH
331# Test change 25062 is working
332my $orig_osname = $^O;
333{
334local $^I = '.bak';
b2978f4e 335is $^O, $orig_osname, 'Assigning $^I does not clobber $^O';
881ddac4
SH
336}
337$^O = $orig_osname;
338
065144c6
TC
339{
340 #RT #72422
341 foreach my $p (0, 1) {
342 fresh_perl_is(<<"EOP", '2 4 8', undef, "test \$^P = $p");
343\$DB::single = 2;
344\$DB::trace = 4;
345\$DB::signal = 8;
346\$^P = $p;
347print "\$DB::single \$DB::trace \$DB::signal";
348EOP
349 }
350}
351
7636ea95
AB
352# Check that assigning to $0 on Linux sets the process name with both
353# argv[0] assignment and by calling prctl()
354{
355 SKIP: {
356 skip "We don't have prctl() here", 2 unless $Config{d_prctl_set_name};
357
358 # We don't really need these tests. prctl() is tested in the
359 # Kernel, but test it anyway for our sanity. If something doesn't
360 # work (like if the system doesn't have a ps(1) for whatever
361 # reason) just bail out gracefully.
362 my $maybe_ps = sub {
363 my ($cmd) = @_;
364 local ($?, $!);
365
366 no warnings;
367 my $res = `$cmd`;
368 skip "Couldn't shell out to `$cmd', returned code $?", 2 if $?;
369 return $res;
370 };
371
372 my $name = "Good Morning, Dave";
373 $0 = $name;
374
375 chomp(my $argv0 = $maybe_ps->("ps h $$"));
376 chomp(my $prctl = $maybe_ps->("ps hc $$"));
377
378 like($argv0, $name, "Set process name through argv[0] ($argv0)");
379 like($prctl, substr($name, 0, 15), "Set process name through prctl() ($prctl)");
380 }
381}
382
c7213721 383{
a45269de
MS
384 my $ok = 1;
385 my $warn = '';
ae8ade65 386 local $SIG{'__WARN__'} = sub { $ok = 0; $warn = join '', @_; $warn =~ s/\n$//; };
78987ded 387 $! = undef;
b2978f4e
NC
388 local $TODO = $Is_VMS ? "'\$!=undef' does throw a warning" : '';
389 ok($ok, $warn);
78987ded
HS
390}
391
b2978f4e 392SKIP: {
d3d1232e 393 skip_if_miniperl("miniperl can't rely on loading %Errno", 2);
126c71c8
YST
394 no warnings 'void';
395
d2c93421
RH
396# Make sure Errno hasn't been prematurely autoloaded
397
b79f7545 398 ok !keys %Errno::;
d2c93421
RH
399
400# Test auto-loading of Errno when %! is used
401
126c71c8
YST
402 ok scalar eval q{
403 %!;
902fde96 404 scalar %Errno::;
126c71c8
YST
405 }, $@;
406}
d2c93421 407
b2978f4e 408SKIP: {
d3d1232e 409 skip_if_miniperl("miniperl can't rely on loading %Errno", 1);
43651d81 410 # Make sure that Errno loading doesn't clobber $!
d2c93421 411
43651d81
NC
412 undef %Errno::;
413 delete $INC{"Errno.pm"};
d2c93421 414
43651d81
NC
415 open(FOO, "nonesuch"); # Generate ENOENT
416 my %errs = %{"!"}; # Cause Errno.pm to be loaded at run-time
417 ok ${"!"}{ENOENT};
418}
a4268c0a 419
ccdda9cb 420# Check that we don't auto-load packages
976bd1ee
DM
421SKIP: {
422 skip "staticly linked; may be preloaded", 4 unless $Config{usedl};
423 foreach (['powie::!', 'Errno'],
424 ['powie::+', 'Tie::Hash::NamedCapture']) {
425 my ($symbol, $package) = @$_;
426 foreach my $scalar_first ('', '$$symbol;') {
427 my $desc = qq{Referencing %{"$symbol"}};
428 $desc .= qq{ after mentioning \${"$symbol"}} if $scalar_first;
429 $desc .= " doesn't load $package";
430
431 fresh_perl_is(<<"EOP", 0, {}, $desc);
ccdda9cb
NC
432use strict qw(vars subs);
433my \$symbol = '$symbol';
434$scalar_first;
4351 if %{\$symbol};
436print scalar %${package}::;
437EOP
976bd1ee 438 }
ccdda9cb
NC
439 }
440}
441
b2978f4e
NC
442is $^S, 0;
443eval { is $^S,1 };
b0e6f864 444eval " BEGIN { ok ! defined \$^S } ";
b2978f4e 445is $^S, 0;
7c36658b 446
0409250f
RGS
447my $taint = ${^TAINT};
448is ${^TAINT}, $taint;
7c36658b 449eval { ${^TAINT} = 1 };
0409250f 450is ${^TAINT}, $taint;
9aa702ec
MJD
451
452# 5.6.1 had a bug: @+ and @- were not properly interpolated
453# into double-quoted strings
454# 20020414 mjd-perl-patch+@plover.com
b64ebf53 455"I like pie" =~ /(I) (like) (pie)/;
b2978f4e
NC
456is "@-", "0 0 2 7";
457is "@+", "10 1 6 10";
9aa702ec 458
f28098ff
RGS
459# Tests for the magic get of $\
460{
461 my $ok = 0;
462 # [perl #19330]
463 {
464 local $\ = undef;
465 $\++; $\++;
466 $ok = $\ eq 2;
467 }
468 ok $ok;
469 $ok = 0;
470 {
471 local $\ = "a\0b";
472 $ok = "a$\b" eq "aa\0bb";
473 }
474 ok $ok;
475}
547d1dd8 476
4c9140ed 477# Test for bug [perl #36434]
b2978f4e
NC
478# Can not do this test on VMS, EPOC, and SYMBIAN according to comments
479# in mg.c/Perl_magic_clear_all_env()
480SKIP: {
481 skip('Can\'t make assignment to \%ENV on this system', 3) if $Is_VMS;
482
4c9140ed
RGS
483 local @ISA;
484 local %ENV;
e1a479c5
BB
485 # This used to be __PACKAGE__, but that causes recursive
486 # inheritance, which is detected earlier now and broke
487 # this test
488 eval { push @ISA, __FILE__ };
b2978f4e 489 is $@, '', 'Push a constant on a magic array';
4c9140ed
RGS
490 $@ and print "# $@";
491 eval { %ENV = (PATH => __PACKAGE__) };
b2978f4e 492 is $@, '', 'Assign a constant to a magic hash';
d8084ca5
DM
493 $@ and print "# $@";
494 eval { my %h = qw(A B); %ENV = (PATH => (keys %h)[0]) };
b2978f4e 495 is $@, '', 'Assign a shared key to a magic hash';
4c9140ed
RGS
496 $@ and print "# $@";
497}
179c85a2
NC
498
499# Tests for Perl_magic_clearsig
500foreach my $sig (qw(__WARN__ INT)) {
501 $SIG{$sig} = lc $sig;
502 is $SIG{$sig}, 'main::' . lc $sig, "Can assign to $sig";
503 is delete $SIG{$sig}, 'main::' . lc $sig, "Can delete from $sig";
504 is $SIG{$sig}, undef, "$sig is now gone";
505 is delete $SIG{$sig}, undef, "$sig remains gone";
506}
507
508# And now one which doesn't exist;
509{
510 no warnings 'signal';
511 $SIG{HUNGRY} = 'mmm, pie';
512}
513is $SIG{HUNGRY}, 'mmm, pie', 'Can assign to HUNGRY';
514is delete $SIG{HUNGRY}, 'mmm, pie', 'Can delete from HUNGRY';
515is $SIG{HUNGRY}, undef, "HUNGRY is now gone";
516is delete $SIG{HUNGRY}, undef, "HUNGRY remains gone";
517
518# Test deleting signals that we never set
c8be058c 519foreach my $sig (qw(__DIE__ _BOGUS_HOOK KILL THIRSTY)) {
179c85a2
NC
520 is $SIG{$sig}, undef, "$sig is not present";
521 is delete $SIG{$sig}, undef, "delete of $sig returns undef";
522}
be1cf43c
NC
523
524{
525 $! = 9999;
526 is int $!, 9999, q{[perl #72850] Core dump in bleadperl from perl -e '$! = 9999; $a = $!;'};
527
528}
4c0f30d6 529
61ec922c
NC
530# ^^^^^^^^^ New tests go here ^^^^^^^^^
531
532SKIP: {
533 skip("%ENV manipulations fail or aren't safe on $^O", 4)
534 if $Is_VMS || $Is_Dos;
535
536 SKIP: {
537 skip("clearing \%ENV is not safe when running under valgrind")
538 if $ENV{PERL_VALGRIND};
539
540 $PATH = $ENV{PATH};
541 $PDL = $ENV{PERL_DESTRUCT_LEVEL} || 0;
542 $ENV{foo} = "bar";
543 %ENV = ();
544 $ENV{PATH} = $PATH;
545 $ENV{PERL_DESTRUCT_LEVEL} = $PDL || 0;
546 if ($Is_MSWin32) {
547 is `set foo 2>NUL`, "";
548 } else {
549 is `echo \$foo`, "\n";
550 }
551 }
552
553 $ENV{__NoNeSuCh} = "foo";
554 $0 = "bar";
555# cmd.exe will echo 'variable=value' but 4nt will echo just the value
556# -- Nikola Knezevic
557 if ($Is_MSWin32) {
558 like `set __NoNeSuCh`, qr/^(?:__NoNeSuCh=)?foo$/;
559 } else {
560 is `echo \$__NoNeSuCh`, "foo\n";
561 }
562 SKIP: {
563 skip("\$0 check only on Linux and FreeBSD", 2)
564 unless $^O =~ /^(linux|freebsd)$/
565 && open CMDLINE, "/proc/$$/cmdline";
566
567 chomp(my $line = scalar <CMDLINE>);
568 my $me = (split /\0/, $line)[0];
569 is $me, $0, 'altering $0 is effective (testing with /proc/)';
570 close CMDLINE;
571 # perlbug #22811
572 my $mydollarzero = sub {
573 my($arg) = shift;
574 $0 = $arg if defined $arg;
575 # In FreeBSD the ps -o command= will cause
576 # an empty header line, grab only the last line.
577 my $ps = (`ps -o command= -p $$`)[-1];
578 return if $?;
579 chomp $ps;
580 printf "# 0[%s]ps[%s]\n", $0, $ps;
581 $ps;
582 };
583 my $ps = $mydollarzero->("x");
584 ok(!$ps # we allow that something goes wrong with the ps command
585 # In Linux 2.4 we would get an exact match ($ps eq 'x') but
586 # in Linux 2.2 there seems to be something funny going on:
587 # it seems as if the original length of the argv[] would
588 # be stored in the proc struct and then used by ps(1),
589 # no matter what characters we use to pad the argv[].
590 # (And if we use \0:s, they are shown as spaces.) Sigh.
591 || $ps =~ /^x\s*$/
592 # FreeBSD cannot get rid of both the leading "perl :"
593 # and the trailing " (perl)": some FreeBSD versions
594 # can get rid of the first one.
595 || ($^O eq 'freebsd' && $ps =~ m/^(?:perl: )?x(?: \(perl\))?$/),
596 'altering $0 is effective (testing with `ps`)');
597 }
598}
599
600# test case-insignificance of %ENV (these tests must be enabled only
601# when perl is compiled with -DENV_IS_CASELESS)
602SKIP: {
603 skip('no caseless %ENV support', 4) unless $Is_MSWin32 || $Is_NetWare;
604
605 %ENV = ();
606 $ENV{'Foo'} = 'bar';
607 $ENV{'fOo'} = 'baz';
608 is scalar(keys(%ENV)), 1;
609 ok exists $ENV{'FOo'};
610 is delete $ENV{'foO'}, 'baz';
611 is scalar(keys(%ENV)), 0;
612}
613
614__END__
615
616# Put new tests before the various ENV tests, as they blow %ENV away.