7 $ENV{PATH} = '/bin' if ${^TAINT};
8 $SIG{__WARN__} = sub { die "Dying on warning: ", @_ };
17 $Is_MSWin32 = $^O eq 'MSWin32';
18 $Is_NetWare = $^O eq 'NetWare';
19 $Is_VMS = $^O eq 'VMS';
20 $Is_Dos = $^O eq 'dos';
21 $Is_os2 = $^O eq 'os2';
22 $Is_Cygwin = $^O eq 'cygwin';
23 $Is_MacOS = $^O eq 'MacOS';
24 $Is_MPE = $^O eq 'mpeix';
25 $Is_miniperl = $ENV{PERL_CORE_MINITEST};
26 $Is_BeOS = $^O eq 'beos';
29 || ($Is_NetWare ? 'perl' :
30 ($Is_MacOS || $Is_VMS) ? $^X :
31 $Is_MSWin32 ? '.\perl' :
35 # On VMS, environment variable changes are peristent after perl exits
36 delete $ENV{'FOO'} if $Is_VMS;
39 eval '$ENV{"FOO"} = "hi there";'; # check that ENV is inited inside eval
40 # cmd.exe will echo 'variable=value' but 4nt will echo just the value
42 if ($Is_MSWin32) { like `set FOO`, qr/^(?:FOO=)?hi there$/; }
43 elsif ($Is_MacOS) { ok "1 # skipped", 1; }
44 elsif ($Is_VMS) { is `write sys\$output f\$trnlnm("FOO")`, "hi there\n"; }
45 else { is `echo \$FOO`, "hi there\n"; }
47 unlink 'ajslkdfpqjsjfk';
49 open(FOO,'ajslkdfpqjsjfk');
51 close FOO; # just mention it, squelch used-only-once
54 skip('SIGINT not safe on this platform', 5)
55 if $Is_MSWin32 || $Is_NetWare || $Is_Dos || $Is_MPE || $Is_MacOS;
56 # the next tests are done in a subprocess because sh spits out a
57 # newline onto stderr when a child process kills itself with SIGINT.
58 # We use a pipe rather than system() because the VMS command buffer
59 # would overflow with a command that long.
61 open( CMDPIPE, "| $PERL");
63 print CMDPIPE <<'END';
65 $| = 1; # command buffering
67 $SIG{"INT"} = "ok3"; kill "INT",$$; sleep 1;
68 $SIG{"INT"} = "IGNORE"; kill "INT",$$; sleep 1; print "ok 4\n";
69 $SIG{"INT"} = "DEFAULT"; kill "INT",$$; sleep 1; print "not ok 4\n";
72 if (($x = pop(@_)) eq "INT") {
76 print "not ok 3 ($x @_)\n";
84 open( CMDPIPE, "| $PERL");
85 print CMDPIPE <<'END';
96 $| = 1; # command buffering
99 local $SIG{"INT"}=x();
100 print ""; # Needed to expose failure in 5.8.0 (why?)
104 kill "INT",$$; sleep 1;
110 $? >>= 8 if $^O eq 'VMS'; # POSIX status hiding in 2nd byte
111 my $todo = ($^O eq 'os2' ? ' # TODO: EMX v0.9d_fix4 bug: wrong nibble? ' : '');
112 print $? & 0xFF ? "ok 6$todo\n" : "not ok 6$todo\n";
114 open(CMDPIPE, "| $PERL");
115 print CMDPIPE <<'END';
117 sub PVBM () { 'foo' }
124 kill "INT", $$; sleep 1;
127 $? >>= 8 if $^O eq 'VMS';
128 print $? ? "not ok 7\n" : "ok 7\n";
130 curr_test(curr_test() + 5);
134 @val1 = @ENV{keys(%ENV)};
135 @val2 = values(%ENV);
136 is join(':',@val1), join(':',@val2);
137 cmp_ok @val1, '>', 1;
140 'foobarbaz' =~ /b(a)r/;
147 @a = qw(foo bar baz);
148 is "@a", "foo bar baz";
151 is "@a", "foo,bar,baz";
156 $h{'foo', 'bar'} = 1;
157 is((keys %h)[0], "foo\034bar");
161 $h{'foo', 'bar'} = 1;
162 is((keys %h)[0], 'fooxbar');
167 skip('$? + system are broken on MacPerl', 2) if $Is_MacOS;
168 system qq[$PERL "-I../lib" -e "use vmsish qw(hushed); exit(0)"];
170 system qq[$PERL "-I../lib" -e "use vmsish qw(hushed); exit(1)"];
174 eval { die "foo\n" };
179 like ($@, qr/^Modification of a read-only value attempted/);
184 chomp($wd = `/usr/bin/fullpath -t`);
186 elsif($Is_Cygwin || $Config{'d_procselfexe'}) {
187 # Cygwin turns the symlink into the real file
190 $wd =~ /(.*)/; $wd = $1; # untaint
192 $wd = Cygwin::win_to_posix_path(Cygwin::posix_to_win_path($wd, 1));
196 $wd = Cwd::sys_cwd();
204 my $perl = ($Is_MacOS || $Is_VMS) ? $^X : "$wd/perl";
206 my $middlemaybe = '';
208 $script = "$wd/show-shebang";
212 $perl = "$wd/perl.exe";
213 $script = "$wd/show-shebang.bat";
228 $script = "./show-shebang";
231 $script = ":show-shebang";
234 $script = "[]show-shebang";
237 $middlemaybe = <<'EOX'
238 $^X = Cygwin::win_to_posix_path(Cygwin::posix_to_win_path($^X, 1));
239 $0 = Cygwin::win_to_posix_path(Cygwin::posix_to_win_path($0, 1));
242 if ($^O eq 'os390' or $^O eq 'posix-bc' or $^O eq 'vmesa') { # no shebang
244 eval 'exec ./perl -S \$0 \${1+"\$\@"}'
248 $s1 = "\$^X is $perl, \$0 is $script\n";
249 ok open(SCRIPT, ">$script") or diag "Can't write to $script: $!";
250 ok print(SCRIPT $headmaybe . <<EOB . $middlemaybe . <<'EOF' . $tailmaybe) or diag $!;
253 print "\$^X is $^X, \$0 is $0\n";
255 ok close(SCRIPT) or diag $!;
256 ok chmod(0755, $script) or diag $!;
257 $_ = ($Is_MacOS || $Is_VMS) ? `$perl $script` : `$script`;
258 s/\.exe//i if $Is_Dos or $Is_Cygwin or $Is_os2;
259 s{./$script}{$script} if $Is_BeOS; # revert BeOS execvp() side-effect
260 s{\bminiperl\b}{perl}; # so that test doesn't fail with miniperl
261 s{is perl}{is $perl}; # for systems where $^X is only a basename
263 if ($Is_MSWin32 || $Is_os2) {
268 $_ = `$perl $script`;
269 s/\.exe//i if $Is_Dos or $Is_os2 or $Is_Cygwin;
270 s{./$perl}{$perl} if $Is_BeOS; # revert BeOS execvp() side-effect
272 if ($Is_MSWin32 || $Is_os2) {
277 ok unlink($script) or diag $!;
281 cmp_ok $], '>=', 5.00319;
283 cmp_ok $^T, '>', 850000000;
285 # Test change 25062 is working
286 my $orig_osname = $^O;
289 is $^O, $orig_osname, 'Assigning $^I does not clobber $^O';
294 skip("%ENV manipulations fail or aren't safe on $^O", 4)
295 if $Is_VMS || $Is_Dos || $Is_MacOS;
298 skip("clearing \%ENV is not safe when running under valgrind")
299 if $ENV{PERL_VALGRIND};
302 $PDL = $ENV{PERL_DESTRUCT_LEVEL} || 0;
306 $ENV{PERL_DESTRUCT_LEVEL} = $PDL || 0;
308 is `set foo 2>NUL`, "";
310 is `echo \$foo`, "\n";
314 $ENV{__NoNeSuCh} = "foo";
316 # cmd.exe will echo 'variable=value' but 4nt will echo just the value
319 like `set __NoNeSuCh`, qr/^(?:__NoNeSuCh=)?foo$/;
321 is `echo \$__NoNeSuCh`, "foo\n";
324 skip("\$0 check only on Linux and FreeBSD", 2)
325 unless $^O =~ /^(linux|freebsd)$/
326 && open CMDLINE, "/proc/$$/cmdline";
328 chomp(my $line = scalar <CMDLINE>);
329 my $me = (split /\0/, $line)[0];
330 is $me, $0, 'altering $0 is effective (testing with /proc/)';
333 my $mydollarzero = sub {
335 $0 = $arg if defined $arg;
336 # In FreeBSD the ps -o command= will cause
337 # an empty header line, grab only the last line.
338 my $ps = (`ps -o command= -p $$`)[-1];
341 printf "# 0[%s]ps[%s]\n", $0, $ps;
344 my $ps = $mydollarzero->("x");
345 ok(!$ps # we allow that something goes wrong with the ps command
346 # In Linux 2.4 we would get an exact match ($ps eq 'x') but
347 # in Linux 2.2 there seems to be something funny going on:
348 # it seems as if the original length of the argv[] would
349 # be stored in the proc struct and then used by ps(1),
350 # no matter what characters we use to pad the argv[].
351 # (And if we use \0:s, they are shown as spaces.) Sigh.
353 # FreeBSD cannot get rid of both the leading "perl :"
354 # and the trailing " (perl)": some FreeBSD versions
355 # can get rid of the first one.
356 || ($^O eq 'freebsd' && $ps =~ m/^(?:perl: )?x(?: \(perl\))?$/),
357 'altering $0 is effective (testing with `ps`)');
364 local $SIG{'__WARN__'} = sub { $ok = 0; $warn = join '', @_; $warn =~ s/\n$//; };
366 local $TODO = $Is_VMS ? "'\$!=undef' does throw a warning" : '';
370 # test case-insignificance of %ENV (these tests must be enabled only
371 # when perl is compiled with -DENV_IS_CASELESS)
373 skip('no caseless %ENV support', 4) unless $Is_MSWin32 || $Is_NetWare;
378 is scalar(keys(%ENV)), 1;
379 ok exists $ENV{'FOo'};
380 is delete $ENV{'foO'}, 'baz';
381 is scalar(keys(%ENV)), 0;
385 skip ("miniperl can't rely on loading %Errno", 2) if $Is_miniperl;
388 # Make sure Errno hasn't been prematurely autoloaded
392 # Test auto-loading of Errno when %! is used
401 skip ("miniperl can't rely on loading %Errno") if $Is_miniperl;
402 # Make sure that Errno loading doesn't clobber $!
405 delete $INC{"Errno.pm"};
407 open(FOO, "nonesuch"); # Generate ENOENT
408 my %errs = %{"!"}; # Cause Errno.pm to be loaded at run-time
414 eval " BEGIN { ok ! defined \$^S } ";
417 my $taint = ${^TAINT};
418 is ${^TAINT}, $taint;
419 eval { ${^TAINT} = 1 };
420 is ${^TAINT}, $taint;
422 # 5.6.1 had a bug: @+ and @- were not properly interpolated
423 # into double-quoted strings
424 # 20020414 mjd-perl-patch+@plover.com
425 "I like pie" =~ /(I) (like) (pie)/;
427 is "@+", "10 1 6 10";
429 # Tests for the magic get of $\
442 $ok = "a$\b" eq "aa\0bb";
447 # Test for bug [perl #27839]
456 is $x, "@y", "return a magic array ($x) vs (@y)";
459 # Test for bug [perl #36434]
460 # Can not do this test on VMS, EPOC, and SYMBIAN according to comments
461 # in mg.c/Perl_magic_clear_all_env()
463 skip('Can\'t make assignment to \%ENV on this system', 3) if $Is_VMS;
467 # This used to be __PACKAGE__, but that causes recursive
468 # inheritance, which is detected earlier now and broke
470 eval { push @ISA, __FILE__ };
471 is $@, '', 'Push a constant on a magic array';
473 eval { %ENV = (PATH => __PACKAGE__) };
474 is $@, '', 'Assign a constant to a magic hash';
476 eval { my %h = qw(A B); %ENV = (PATH => (keys %h)[0]) };
477 is $@, '', 'Assign a shared key to a magic hash';
481 # Tests for Perl_magic_clearsig
482 foreach my $sig (qw(__WARN__ INT)) {
483 $SIG{$sig} = lc $sig;
484 is $SIG{$sig}, 'main::' . lc $sig, "Can assign to $sig";
485 is delete $SIG{$sig}, 'main::' . lc $sig, "Can delete from $sig";
486 is $SIG{$sig}, undef, "$sig is now gone";
487 is delete $SIG{$sig}, undef, "$sig remains gone";
490 # And now one which doesn't exist;
492 no warnings 'signal';
493 $SIG{HUNGRY} = 'mmm, pie';
495 is $SIG{HUNGRY}, 'mmm, pie', 'Can assign to HUNGRY';
496 is delete $SIG{HUNGRY}, 'mmm, pie', 'Can delete from HUNGRY';
497 is $SIG{HUNGRY}, undef, "HUNGRY is now gone";
498 is delete $SIG{HUNGRY}, undef, "HUNGRY remains gone";
500 # Test deleting signals that we never set
501 foreach my $sig (qw(__DIE__ _BOGUS_HOOK KILL THIRSTY)) {
502 is $SIG{$sig}, undef, "$sig is not present";
503 is delete $SIG{$sig}, undef, "delete of $sig returns undef";