magic.t revision 7c478bd95313f5f23a4c958a745db2134aa03244
#!./perl
BEGIN {
$| = 1;
chdir 't' if -d 't';
}
use warnings;
use Config;
my $test = 1;
sub ok {
# You have to do it this way or VMS will get confused.
}
$test++;
return $ok;
}
sub skip {
$test++;
return 1;
}
print "1..54\n";
'./perl');
eval '$ENV{"FOO"} = "hi there";'; # check that ENV is inited inside eval
# cmd.exe will echo 'variable=value' but 4nt will echo just the value
# -- Nikola Knezevic
$! = 0;
ok $!, $!;
}
else {
# the next tests are done in a subprocess because sh spits out a
# newline onto stderr when a child process kills itself with SIGINT.
# We use a pipe rather than system() because the VMS command buffer
# would overflow with a command that long.
$| = 1; # command buffering
sub ok3 {
print "ok 3\n";
}
else {
print "not ok 3 ($x @_)\n";
}
}
{ package X;
sub DESTROY {
kill "INT",$$;
}
}
sub x {
return sub { $x };
}
$| = 1; # command buffering
{
print ""; # Needed to expose failure in 5.8.0 (why?)
}
sleep 1;
sub ok5 {
print "ok 5\n";
}
$test += 4;
}
# can we slice ENV?
# regex vars
'foobarbaz' =~ /b(a)r/;
# $"
{
local $" = ',';
}
# $;
%h = ();
$h{'foo', 'bar'} = 1;
{
local $; = 'x';
%h = ();
$h{'foo', 'bar'} = 1;
ok((keys %h)[0] eq 'fooxbar', (keys %h)[0]);
}
# $?, $@, $$
if ($Is_MacOS) {
skip('$? + system are broken on MacPerl') for 1..2;
}
else {
ok $? == 0, $?;
ok $? != 0, $?;
}
ok $$ > 0, $$;
eval { $$++ };
ok $@ =~ /^Modification of a read-only value attempted/;
# $^X and $0
{
if ($^O eq 'qnx') {
}
elsif($Is_Cygwin || $Config{'d_procselfexe'}) {
# Cygwin turns the symlink into the real file
$wd =~ s#/t$##;
}
elsif($Is_os2) {
$wd = Cwd::sys_cwd();
}
elsif($Is_MacOS) {
$wd = ':';
}
else {
$wd = '.';
}
my $headmaybe = '';
my $tailmaybe = '';
if ($Is_MSWin32) {
$wd =~ s|\\|/|g;
$headmaybe = <<EOH ;
\@rem ='
\@echo off
$perl -x \%0
goto endofperl
\@rem ';
EOH
$tailmaybe = <<EOT ;
__END__
:endofperl
EOT
}
elsif ($Is_os2) {
}
elsif ($Is_MacOS) {
}
elsif ($Is_VMS) {
}
if ($^O eq 'os390' or $^O eq 'posix-bc' or $^O eq 'vmesa') { # no shebang
$headmaybe = <<EOH ;
eval 'exec ./perl -S \$0 \${1+"\$\@"}'
if 0;
EOH
}
ok print(SCRIPT $headmaybe . <<EOB . <<'EOF' . $tailmaybe), $!;
#!$wd/perl
EOB
EOF
ok close(SCRIPT), $!;
ok chmod(0755, $script), $!;
s/\.exe//i if $Is_Dos or $Is_Cygwin or $Is_os2;
s{\bminiperl\b}{perl}; # so that test doesn't fail with miniperl
s{is perl}{is $perl}; # for systems where $^X is only a basename
s{\\}{/}g;
s{\\}{/}g;
ok((($Is_MSWin32 || $Is_os2) ? uc($_) eq uc($s1) : $_ eq $s1), " :$_:!=:$s1: after `$perl $script`");
ok unlink($script), $!;
}
# $], $^O, $^T
ok $] >= 5.00319, $];
ok $^O;
ok $^T > 850000000, $^T;
}
else {
if ($ENV{PERL_VALGRIND}) {
skip("clearing \%ENV is not safe when running under valgrind");
} else {
$PATH = $ENV{PATH};
$PDL = $ENV{PERL_DESTRUCT_LEVEL} || 0;
$ENV{foo} = "bar";
%ENV = ();
$ENV{PATH} = $PATH;
$ENV{PERL_DESTRUCT_LEVEL} = $PDL || 0;
ok ($Is_MSWin32 ? (`set foo 2>NUL` eq "")
: (`echo \$foo` eq "\n") );
}
$ENV{__NoNeSuCh} = "foo";
$0 = "bar";
# -- Nikola Knezevic
ok ($Is_MSWin32 ? (`set __NoNeSuCh` =~ /^(?:__NoNeSuCh=)?foo$/)
: (`echo \$__NoNeSuCh` eq "foo\n") );
if ($^O =~ /^(linux|freebsd)$/ &&
open CMDLINE, "/proc/$$/cmdline") {
chomp(my $line = scalar <CMDLINE>);
my $me = (split /\0/, $line)[0];
close CMDLINE;
# perlbug #22811
my $mydollarzero = sub {
my($arg) = shift;
$0 = $arg if defined $arg;
# In FreeBSD the ps -o command= will cause
# an empty header line, grab only the last line.
my $ps = (`ps -o command= -p $$`)[-1];
return if $?;
chomp $ps;
printf "# 0[%s]ps[%s]\n", $0, $ps;
$ps;
};
my $ps = $mydollarzero->("x");
ok(!$ps # we allow that something goes wrong with the ps command
# In Linux 2.4 we would get an exact match ($ps eq 'x') but
# in Linux 2.2 there seems to be something funny going on:
# it seems as if the original length of the argv[] would
# be stored in the proc struct and then used by ps(1),
# no matter what characters we use to pad the argv[].
# (And if we use \0:s, they are shown as spaces.) Sigh.
|| $ps =~ /^x\s*$/
# FreeBSD cannot get rid of both the leading "perl :"
# and the trailing " (perl)": some FreeBSD versions
# can get rid of the first one.
} else {
skip("\$0 check only on Linux and FreeBSD") for 0, 1;
}
}
{
my $ok = 1;
my $warn = '';
$! = undef;
}
# test case-insignificance of %ENV (these tests must be enabled only
# when perl is compiled with -DENV_IS_CASELESS)
if ($Is_MSWin32 || $Is_NetWare) {
%ENV = ();
ok (scalar(keys(%ENV)) == 1);
ok (scalar(keys(%ENV)) == 0);
}
else {
}
if ($Is_miniperl) {
} else {
no warnings 'void';
# Make sure Errno hasn't been prematurely autoloaded
ok !defined %Errno::;
# Test auto-loading of Errno when %! is used
ok scalar eval q{
%!;
defined %Errno::;
}, $@;
}
if ($Is_miniperl) {
} else {
# Make sure that Errno loading doesn't clobber $!
}
eval { ok $^S == 1 };
eval " BEGIN { ok ! defined \$^S } ";
eval { ${^TAINT} = 1 };
# 5.6.1 had a bug: @+ and @- were not properly interpolated
# into double-quoted strings
# 20020414 mjd-perl-patch+@plover.com
# Tests for the magic get of $\
{
my $ok = 0;
# [perl #19330]
{
local $\ = undef;
$\++; $\++;
}
$ok = 0;
{
local $\ = "a\0b";
}
}
# Test for bug [perl #27839]
{
my $x;
sub f {
"abc" =~ /(.)./;
$x = "@+";
return @+;
};
my @y = f();
}