magic.t revision 7c478bd95313f5f23a4c958a745db2134aa03244
#!./perl
BEGIN {
$| = 1;
chdir 't' if -d 't';
}
use warnings;
sub ok {
print "ok $n\n";
}
else {
print "not ok $n\n";
}
}
print "1..35\n";
eval '$ENV{"FOO"} = "hi there";'; # check that ENV is inited inside eval
$! = 0;
ok 2, $!, $!;
}
else {
# the next tests are embedded inside system simply because sh spits out
# a newline onto stderr when a child process kills itself with SIGINT.
$| = 1; # command buffering
sub ok3 {
print "ok 3\n";
}
else {
print "not ok 3 ($x @_)\n";
}
}
}
# can we slice ENV?
# regex vars
'foobarbaz' =~ /b(a)r/;
# $"
{
local $" = ',';
}
# $;
%h = ();
$h{'foo', 'bar'} = 1;
{
local $; = 'x';
%h = ();
$h{'foo', 'bar'} = 1;
ok 14, (keys %h)[0] eq 'fooxbar', (keys %h)[0];
}
# $?, $@, $$
ok 15, $? == 0, $?;
ok 16, $? != 0, $?;
ok 18, $$ > 0, $$;
# $^X and $0
{
if ($^O eq 'qnx') {
}
elsif($Is_Cygwin) {
# Cygwin turns the symlink into the real file
$wd =~ s#/t$##;
}
elsif($Is_os2) {
$wd = Cwd::sys_cwd();
}
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) {
}
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 20, print(SCRIPT $headmaybe . <<EOB . <<'EOF' . $tailmaybe), $!;
#!$wd/perl
EOB
EOF
ok 21, close(SCRIPT), $!;
ok 22, 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 24, (($Is_MSWin32 || $Is_os2) ? uc($_) eq uc($s1) : $_ eq $s1), " :$_:!=:$s1: after `$perl $script`";
ok 25, unlink($script), $!;
}
# $], $^O, $^T
ok 26, $] >= 5.00319, $];
ok 27, $^O;
ok 28, $^T > 850000000, $^T;
ok "29 # skipped", 1;
}
else {
$PDL = $ENV{PERL_DESTRUCT_LEVEL} || 0;
$ENV{PERL_DESTRUCT_LEVEL} = $PDL || 0;
$0 = "bar";
}
{
$! = undef;
print "ok 31\n";
}
# test case-insignificance of %ENV (these tests must be enabled only
# when perl is compiled with -DENV_IS_CASELESS)
}
else {
}