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_MPE = $^O eq 'mpeix';
24 $Is_miniperl = $ENV{PERL_CORE_MINITEST};
25 $Is_BeOS = $^O eq 'beos';
28 || ($Is_NetWare ? 'perl' :
30 $Is_MSWin32 ? '.\perl' :
34 # On VMS, environment variable changes are peristent after perl exits
35 delete $ENV{'FOO'} if $Is_VMS;
38 eval '$ENV{"FOO"} = "hi there";'; # check that ENV is inited inside eval
39 # cmd.exe will echo 'variable=value' but 4nt will echo just the value
41 if ($Is_MSWin32) { like `set FOO`, qr/^(?:FOO=)?hi there$/; }
42 elsif ($Is_VMS) { is `write sys\$output f\$trnlnm("FOO")`, "hi there\n"; }
43 else { is `echo \$FOO`, "hi there\n"; }
45 unlink 'ajslkdfpqjsjfk';
47 open(FOO,'ajslkdfpqjsjfk');
49 close FOO; # just mention it, squelch used-only-once
52 skip('SIGINT not safe on this platform', 5)
53 if $Is_MSWin32 || $Is_NetWare || $Is_Dos || $Is_MPE;
54 # the next tests are done in a subprocess because sh spits out a
55 # newline onto stderr when a child process kills itself with SIGINT.
56 # We use a pipe rather than system() because the VMS command buffer
57 # would overflow with a command that long.
59 open( CMDPIPE, "| $PERL");
61 print CMDPIPE <<'END';
63 $| = 1; # command buffering
65 $SIG{"INT"} = "ok3"; kill "INT",$$; sleep 1;
66 $SIG{"INT"} = "IGNORE"; kill "INT",$$; sleep 1; print "ok 4\n";
67 $SIG{"INT"} = "DEFAULT"; kill "INT",$$; sleep 1; print "not ok 4\n";
70 if (($x = pop(@_)) eq "INT") {
74 print "not ok 3 ($x @_)\n";
82 open( CMDPIPE, "| $PERL");
83 print CMDPIPE <<'END';
94 $| = 1; # command buffering
97 local $SIG{"INT"}=x();
98 print ""; # Needed to expose failure in 5.8.0 (why?)
102 kill "INT",$$; sleep 1;
108 $? >>= 8 if $^O eq 'VMS'; # POSIX status hiding in 2nd byte
109 my $todo = ($^O eq 'os2' ? ' # TODO: EMX v0.9d_fix4 bug: wrong nibble? ' : '');
110 print $? & 0xFF ? "ok 6$todo\n" : "not ok 6$todo\n";
112 open(CMDPIPE, "| $PERL");
113 print CMDPIPE <<'END';
115 sub PVBM () { 'foo' }
122 kill "INT", $$; sleep 1;
125 $? >>= 8 if $^O eq 'VMS';
126 print $? ? "not ok 7\n" : "ok 7\n";
128 curr_test(curr_test() + 5);
132 @val1 = @ENV{keys(%ENV)};
133 @val2 = values(%ENV);
134 is join(':',@val1), join(':',@val2);
135 cmp_ok @val1, '>', 1;
138 'foobarbaz' =~ /b(a)r/;
145 @a = qw(foo bar baz);
146 is "@a", "foo bar baz";
149 is "@a", "foo,bar,baz";
154 $h{'foo', 'bar'} = 1;
155 is((keys %h)[0], "foo\034bar");
159 $h{'foo', 'bar'} = 1;
160 is((keys %h)[0], 'fooxbar');
164 system qq[$PERL "-I../lib" -e "use vmsish qw(hushed); exit(0)"];
166 system qq[$PERL "-I../lib" -e "use vmsish qw(hushed); exit(1)"];
169 eval { die "foo\n" };
174 like ($@, qr/^Modification of a read-only value attempted/);
179 chomp($wd = `/usr/bin/fullpath -t`);
181 elsif($Is_Cygwin || $Config{'d_procselfexe'}) {
182 # Cygwin turns the symlink into the real file
185 $wd =~ /(.*)/; $wd = $1; # untaint
187 $wd = Cygwin::win_to_posix_path(Cygwin::posix_to_win_path($wd, 1));
191 $wd = Cwd::sys_cwd();
196 my $perl = $Is_VMS ? $^X : "$wd/perl";
198 my $middlemaybe = '';
200 $script = "$wd/show-shebang";
204 $perl = "$wd/perl.exe";
205 $script = "$wd/show-shebang.bat";
220 $script = "./show-shebang";
223 $script = "[]show-shebang";
226 $middlemaybe = <<'EOX'
227 $^X = Cygwin::win_to_posix_path(Cygwin::posix_to_win_path($^X, 1));
228 $0 = Cygwin::win_to_posix_path(Cygwin::posix_to_win_path($0, 1));
231 if ($^O eq 'os390' or $^O eq 'posix-bc' or $^O eq 'vmesa') { # no shebang
233 eval 'exec ./perl -S \$0 \${1+"\$\@"}'
237 $s1 = "\$^X is $perl, \$0 is $script\n";
238 ok open(SCRIPT, ">$script") or diag "Can't write to $script: $!";
239 ok print(SCRIPT $headmaybe . <<EOB . $middlemaybe . <<'EOF' . $tailmaybe) or diag $!;
242 print "\$^X is $^X, \$0 is $0\n";
244 ok close(SCRIPT) or diag $!;
245 ok chmod(0755, $script) or diag $!;
246 $_ = $Is_VMS ? `$perl $script` : `$script`;
247 s/\.exe//i if $Is_Dos or $Is_Cygwin or $Is_os2;
248 s{./$script}{$script} if $Is_BeOS; # revert BeOS execvp() side-effect
249 s{\bminiperl\b}{perl}; # so that test doesn't fail with miniperl
250 s{is perl}{is $perl}; # for systems where $^X is only a basename
252 if ($Is_MSWin32 || $Is_os2) {
257 $_ = `$perl $script`;
258 s/\.exe//i if $Is_Dos or $Is_os2 or $Is_Cygwin;
259 s{./$perl}{$perl} if $Is_BeOS; # revert BeOS execvp() side-effect
261 if ($Is_MSWin32 || $Is_os2) {
266 ok unlink($script) or diag $!;
270 cmp_ok $], '>=', 5.00319;
272 cmp_ok $^T, '>', 850000000;
274 # Test change 25062 is working
275 my $orig_osname = $^O;
278 is $^O, $orig_osname, 'Assigning $^I does not clobber $^O';
283 skip("%ENV manipulations fail or aren't safe on $^O", 4)
284 if $Is_VMS || $Is_Dos;
287 skip("clearing \%ENV is not safe when running under valgrind")
288 if $ENV{PERL_VALGRIND};
291 $PDL = $ENV{PERL_DESTRUCT_LEVEL} || 0;
295 $ENV{PERL_DESTRUCT_LEVEL} = $PDL || 0;
297 is `set foo 2>NUL`, "";
299 is `echo \$foo`, "\n";
303 $ENV{__NoNeSuCh} = "foo";
305 # cmd.exe will echo 'variable=value' but 4nt will echo just the value
308 like `set __NoNeSuCh`, qr/^(?:__NoNeSuCh=)?foo$/;
310 is `echo \$__NoNeSuCh`, "foo\n";
313 skip("\$0 check only on Linux and FreeBSD", 2)
314 unless $^O =~ /^(linux|freebsd)$/
315 && open CMDLINE, "/proc/$$/cmdline";
317 chomp(my $line = scalar <CMDLINE>);
318 my $me = (split /\0/, $line)[0];
319 is $me, $0, 'altering $0 is effective (testing with /proc/)';
322 my $mydollarzero = sub {
324 $0 = $arg if defined $arg;
325 # In FreeBSD the ps -o command= will cause
326 # an empty header line, grab only the last line.
327 my $ps = (`ps -o command= -p $$`)[-1];
330 printf "# 0[%s]ps[%s]\n", $0, $ps;
333 my $ps = $mydollarzero->("x");
334 ok(!$ps # we allow that something goes wrong with the ps command
335 # In Linux 2.4 we would get an exact match ($ps eq 'x') but
336 # in Linux 2.2 there seems to be something funny going on:
337 # it seems as if the original length of the argv[] would
338 # be stored in the proc struct and then used by ps(1),
339 # no matter what characters we use to pad the argv[].
340 # (And if we use \0:s, they are shown as spaces.) Sigh.
342 # FreeBSD cannot get rid of both the leading "perl :"
343 # and the trailing " (perl)": some FreeBSD versions
344 # can get rid of the first one.
345 || ($^O eq 'freebsd' && $ps =~ m/^(?:perl: )?x(?: \(perl\))?$/),
346 'altering $0 is effective (testing with `ps`)');
353 local $SIG{'__WARN__'} = sub { $ok = 0; $warn = join '', @_; $warn =~ s/\n$//; };
355 local $TODO = $Is_VMS ? "'\$!=undef' does throw a warning" : '';
359 # test case-insignificance of %ENV (these tests must be enabled only
360 # when perl is compiled with -DENV_IS_CASELESS)
362 skip('no caseless %ENV support', 4) unless $Is_MSWin32 || $Is_NetWare;
367 is scalar(keys(%ENV)), 1;
368 ok exists $ENV{'FOo'};
369 is delete $ENV{'foO'}, 'baz';
370 is scalar(keys(%ENV)), 0;
374 skip ("miniperl can't rely on loading %Errno", 2) if $Is_miniperl;
377 # Make sure Errno hasn't been prematurely autoloaded
381 # Test auto-loading of Errno when %! is used
390 skip ("miniperl can't rely on loading %Errno") if $Is_miniperl;
391 # Make sure that Errno loading doesn't clobber $!
394 delete $INC{"Errno.pm"};
396 open(FOO, "nonesuch"); # Generate ENOENT
397 my %errs = %{"!"}; # Cause Errno.pm to be loaded at run-time
403 eval " BEGIN { ok ! defined \$^S } ";
406 my $taint = ${^TAINT};
407 is ${^TAINT}, $taint;
408 eval { ${^TAINT} = 1 };
409 is ${^TAINT}, $taint;
411 # 5.6.1 had a bug: @+ and @- were not properly interpolated
412 # into double-quoted strings
413 # 20020414 mjd-perl-patch+@plover.com
414 "I like pie" =~ /(I) (like) (pie)/;
416 is "@+", "10 1 6 10";
418 # Tests for the magic get of $\
431 $ok = "a$\b" eq "aa\0bb";
436 # Test for bug [perl #27839]
445 is $x, "@y", "return a magic array ($x) vs (@y)";
448 # Test for bug [perl #36434]
449 # Can not do this test on VMS, EPOC, and SYMBIAN according to comments
450 # in mg.c/Perl_magic_clear_all_env()
452 skip('Can\'t make assignment to \%ENV on this system', 3) if $Is_VMS;
456 # This used to be __PACKAGE__, but that causes recursive
457 # inheritance, which is detected earlier now and broke
459 eval { push @ISA, __FILE__ };
460 is $@, '', 'Push a constant on a magic array';
462 eval { %ENV = (PATH => __PACKAGE__) };
463 is $@, '', 'Assign a constant to a magic hash';
465 eval { my %h = qw(A B); %ENV = (PATH => (keys %h)[0]) };
466 is $@, '', 'Assign a shared key to a magic hash';
470 # Tests for Perl_magic_clearsig
471 foreach my $sig (qw(__WARN__ INT)) {
472 $SIG{$sig} = lc $sig;
473 is $SIG{$sig}, 'main::' . lc $sig, "Can assign to $sig";
474 is delete $SIG{$sig}, 'main::' . lc $sig, "Can delete from $sig";
475 is $SIG{$sig}, undef, "$sig is now gone";
476 is delete $SIG{$sig}, undef, "$sig remains gone";
479 # And now one which doesn't exist;
481 no warnings 'signal';
482 $SIG{HUNGRY} = 'mmm, pie';
484 is $SIG{HUNGRY}, 'mmm, pie', 'Can assign to HUNGRY';
485 is delete $SIG{HUNGRY}, 'mmm, pie', 'Can delete from HUNGRY';
486 is $SIG{HUNGRY}, undef, "HUNGRY is now gone";
487 is delete $SIG{HUNGRY}, undef, "HUNGRY remains gone";
489 # Test deleting signals that we never set
490 foreach my $sig (qw(__DIE__ _BOGUS_HOOK KILL THIRSTY)) {
491 is $SIG{$sig}, undef, "$sig is not present";
492 is delete $SIG{$sig}, undef, "delete of $sig returns undef";