7 $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' :
34 eval '$ENV{"FOO"} = "hi there";'; # check that ENV is inited inside eval
35 # cmd.exe will echo 'variable=value' but 4nt will echo just the value
37 if ($Is_MSWin32) { like `set FOO`, qr/^(?:FOO=)?hi there$/; }
38 elsif ($Is_MacOS) { ok "1 # skipped", 1; }
39 elsif ($Is_VMS) { is `write sys\$output f\$trnlnm("FOO")`, "hi there\n"; }
40 else { is `echo \$FOO`, "hi there\n"; }
42 unlink 'ajslkdfpqjsjfk';
44 open(FOO,'ajslkdfpqjsjfk');
46 close FOO; # just mention it, squelch used-only-once
49 skip('SIGINT not safe on this platform', 5)
50 if $Is_MSWin32 || $Is_NetWare || $Is_Dos || $Is_MPE || $Is_MacOS;
51 # the next tests are done in a subprocess because sh spits out a
52 # newline onto stderr when a child process kills itself with SIGINT.
53 # We use a pipe rather than system() because the VMS command buffer
54 # would overflow with a command that long.
56 open( CMDPIPE, "| $PERL");
58 print CMDPIPE <<'END';
60 $| = 1; # command buffering
62 $SIG{"INT"} = "ok3"; kill "INT",$$; sleep 1;
63 $SIG{"INT"} = "IGNORE"; kill "INT",$$; sleep 1; print "ok 4\n";
64 $SIG{"INT"} = "DEFAULT"; kill "INT",$$; sleep 1; print "not ok 4\n";
67 if (($x = pop(@_)) eq "INT") {
71 print "not ok 3 ($x @_)\n";
79 open( CMDPIPE, "| $PERL");
80 print CMDPIPE <<'END';
91 $| = 1; # command buffering
94 local $SIG{"INT"}=x();
95 print ""; # Needed to expose failure in 5.8.0 (why?)
99 kill "INT",$$; sleep 1;
105 $? >>= 8 if $^O eq 'VMS'; # POSIX status hiding in 2nd byte
106 my $todo = ($^O eq 'os2' ? ' # TODO: EMX v0.9d_fix4 bug: wrong nibble? ' : '');
107 print $? & 0xFF ? "ok 6$todo\n" : "not ok 6$todo\n";
109 open(CMDPIPE, "| $PERL");
110 print CMDPIPE <<'END';
112 sub PVBM () { 'foo' }
119 kill "INT", $$; sleep 1;
122 $? >>= 8 if $^O eq 'VMS';
123 print $? ? "not ok 7\n" : "ok 7\n";
125 curr_test(curr_test() + 5);
129 @val1 = @ENV{keys(%ENV)};
130 @val2 = values(%ENV);
131 is join(':',@val1), join(':',@val2);
132 cmp_ok @val1, '>', 1;
135 'foobarbaz' =~ /b(a)r/;
142 @a = qw(foo bar baz);
143 is "@a", "foo bar baz";
146 is "@a", "foo,bar,baz";
151 $h{'foo', 'bar'} = 1;
152 is((keys %h)[0], "foo\034bar");
156 $h{'foo', 'bar'} = 1;
157 is((keys %h)[0], 'fooxbar');
162 skip('$? + system are broken on MacPerl', 2) if $Is_MacOS;
163 system qq[$PERL "-I../lib" -e "use vmsish qw(hushed); exit(0)"];
165 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
186 $wd = Cygwin::win_to_posix_path(Cygwin::posix_to_win_path($wd, 1));
190 $wd = Cwd::sys_cwd();
198 my $perl = ($Is_MacOS || $Is_VMS) ? $^X : "$wd/perl";
200 my $middlemaybe = '';
202 $script = "$wd/show-shebang";
206 $perl = "$wd/perl.exe";
207 $script = "$wd/show-shebang.bat";
222 $script = "./show-shebang";
225 $script = ":show-shebang";
228 $script = "[]show-shebang";
231 $middlemaybe = <<'EOX'
232 $^X = Cygwin::win_to_posix_path(Cygwin::posix_to_win_path($^X, 1));
233 $0 = Cygwin::win_to_posix_path(Cygwin::posix_to_win_path($0, 1));
236 if ($^O eq 'os390' or $^O eq 'posix-bc' or $^O eq 'vmesa') { # no shebang
238 eval 'exec ./perl -S \$0 \${1+"\$\@"}'
242 $s1 = "\$^X is $perl, \$0 is $script\n";
243 ok open(SCRIPT, ">$script") or diag $!;
244 ok print(SCRIPT $headmaybe . <<EOB . $middlemaybe . <<'EOF' . $tailmaybe) or diag $!;
247 print "\$^X is $^X, \$0 is $0\n";
249 ok close(SCRIPT) or diag $!;
250 ok chmod(0755, $script) or diag $!;
251 $_ = ($Is_MacOS || $Is_VMS) ? `$perl $script` : `$script`;
252 s/\.exe//i if $Is_Dos or $Is_Cygwin or $Is_os2;
253 s{./$script}{$script} if $Is_BeOS; # revert BeOS execvp() side-effect
254 s{\bminiperl\b}{perl}; # so that test doesn't fail with miniperl
255 s{is perl}{is $perl}; # for systems where $^X is only a basename
257 if ($Is_MSWin32 || $Is_os2) {
262 $_ = `$perl $script`;
263 s/\.exe//i if $Is_Dos or $Is_os2 or $Is_Cygwin;
264 s{./$perl}{$perl} if $Is_BeOS; # revert BeOS execvp() side-effect
266 if ($Is_MSWin32 || $Is_os2) {
271 ok unlink($script) or diag $!;
275 cmp_ok $], '>=', 5.00319;
277 cmp_ok $^T, '>', 850000000;
279 # Test change 25062 is working
280 my $orig_osname = $^O;
283 is $^O, $orig_osname, 'Assigning $^I does not clobber $^O';
288 skip("%ENV manipulations fail or aren't safe on $^O", 4)
289 if $Is_VMS || $Is_Dos || $Is_MacOS;
292 skip("clearing \%ENV is not safe when running under valgrind")
293 if $ENV{PERL_VALGRIND};
296 $PDL = $ENV{PERL_DESTRUCT_LEVEL} || 0;
300 $ENV{PERL_DESTRUCT_LEVEL} = $PDL || 0;
302 is `set foo 2>NUL`, "";
304 is `echo \$foo`, "\n";
308 $ENV{__NoNeSuCh} = "foo";
310 # cmd.exe will echo 'variable=value' but 4nt will echo just the value
313 like `set __NoNeSuCh`, qr/^(?:__NoNeSuCh=)?foo$/;
315 is `echo \$__NoNeSuCh`, "foo\n";
318 skip("\$0 check only on Linux and FreeBSD", 2)
319 unless $^O =~ /^(linux|freebsd)$/
320 && open CMDLINE, "/proc/$$/cmdline";
322 chomp(my $line = scalar <CMDLINE>);
323 my $me = (split /\0/, $line)[0];
324 is $me, $0, 'altering $0 is effective (testing with /proc/)';
327 my $mydollarzero = sub {
329 $0 = $arg if defined $arg;
330 # In FreeBSD the ps -o command= will cause
331 # an empty header line, grab only the last line.
332 my $ps = (`ps -o command= -p $$`)[-1];
335 printf "# 0[%s]ps[%s]\n", $0, $ps;
338 my $ps = $mydollarzero->("x");
339 ok(!$ps # we allow that something goes wrong with the ps command
340 # In Linux 2.4 we would get an exact match ($ps eq 'x') but
341 # in Linux 2.2 there seems to be something funny going on:
342 # it seems as if the original length of the argv[] would
343 # be stored in the proc struct and then used by ps(1),
344 # no matter what characters we use to pad the argv[].
345 # (And if we use \0:s, they are shown as spaces.) Sigh.
347 # FreeBSD cannot get rid of both the leading "perl :"
348 # and the trailing " (perl)": some FreeBSD versions
349 # can get rid of the first one.
350 || ($^O eq 'freebsd' && $ps =~ m/^(?:perl: )?x(?: \(perl\))?$/),
351 'altering $0 is effective (testing with `ps`)');
358 local $SIG{'__WARN__'} = sub { $ok = 0; $warn = join '', @_; };
360 local $TODO = $Is_VMS ? "'\$!=undef' does throw a warning" : '';
364 # test case-insignificance of %ENV (these tests must be enabled only
365 # when perl is compiled with -DENV_IS_CASELESS)
367 skip('no caseless %ENV support', 4) unless $Is_MSWin32 || $Is_NetWare;
372 is scalar(keys(%ENV)), 1;
373 ok exists $ENV{'FOo'};
374 is delete $ENV{'foO'}, 'baz';
375 is scalar(keys(%ENV)), 0;
379 skip ("miniperl can't rely on loading %Errno", 2) if $Is_miniperl;
382 # Make sure Errno hasn't been prematurely autoloaded
386 # Test auto-loading of Errno when %! is used
395 skip ("miniperl can't rely on loading %Errno") if $Is_miniperl;
396 # Make sure that Errno loading doesn't clobber $!
399 delete $INC{"Errno.pm"};
401 open(FOO, "nonesuch"); # Generate ENOENT
402 my %errs = %{"!"}; # Cause Errno.pm to be loaded at run-time
408 eval " BEGIN { ok ! defined \$^S } ";
412 eval { ${^TAINT} = 1 };
415 # 5.6.1 had a bug: @+ and @- were not properly interpolated
416 # into double-quoted strings
417 # 20020414 mjd-perl-patch+@plover.com
418 "I like pie" =~ /(I) (like) (pie)/;
420 is "@+", "10 1 6 10";
422 # Tests for the magic get of $\
435 $ok = "a$\b" eq "aa\0bb";
440 # Test for bug [perl #27839]
449 is $x, "@y", "return a magic array ($x) vs (@y)";
452 # Test for bug [perl #36434]
453 # Can not do this test on VMS, EPOC, and SYMBIAN according to comments
454 # in mg.c/Perl_magic_clear_all_env()
456 skip('Can\'t make assignment to \%ENV on this system', 3) if $Is_VMS;
460 # This used to be __PACKAGE__, but that causes recursive
461 # inheritance, which is detected earlier now and broke
463 eval { push @ISA, __FILE__ };
464 is $@, '', 'Push a constant on a magic array';
466 eval { %ENV = (PATH => __PACKAGE__) };
467 is $@, '', 'Assign a constant to a magic hash';
469 eval { my %h = qw(A B); %ENV = (PATH => (keys %h)[0]) };
470 is $@, '', 'Assign a shared key to a magic hash';