xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/t/op/magic.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!./perl
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gateBEGIN {
4*0Sstevel@tonic-gate    $| = 1;
5*0Sstevel@tonic-gate    chdir 't' if -d 't';
6*0Sstevel@tonic-gate    @INC = '../lib';
7*0Sstevel@tonic-gate    $SIG{__WARN__} = sub { die "Dying on warning: ", @_ };
8*0Sstevel@tonic-gate}
9*0Sstevel@tonic-gate
10*0Sstevel@tonic-gateuse warnings;
11*0Sstevel@tonic-gateuse Config;
12*0Sstevel@tonic-gate
13*0Sstevel@tonic-gatemy $test = 1;
14*0Sstevel@tonic-gatesub ok {
15*0Sstevel@tonic-gate    my($ok, $info, $todo) = @_;
16*0Sstevel@tonic-gate
17*0Sstevel@tonic-gate    # You have to do it this way or VMS will get confused.
18*0Sstevel@tonic-gate    printf "%s $test%s\n", $ok ? "ok" : "not ok",
19*0Sstevel@tonic-gate                           $todo ? " # TODO $todo" : '';
20*0Sstevel@tonic-gate
21*0Sstevel@tonic-gate    unless( $ok ) {
22*0Sstevel@tonic-gate        printf "# Failed test at line %d\n", (caller)[2];
23*0Sstevel@tonic-gate        print  "# $info\n" if defined $info;
24*0Sstevel@tonic-gate    }
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate    $test++;
27*0Sstevel@tonic-gate    return $ok;
28*0Sstevel@tonic-gate}
29*0Sstevel@tonic-gate
30*0Sstevel@tonic-gatesub skip {
31*0Sstevel@tonic-gate    my($reason) = @_;
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gate    printf "ok $test # skipped%s\n", defined $reason ? ": $reason" : '';
34*0Sstevel@tonic-gate
35*0Sstevel@tonic-gate    $test++;
36*0Sstevel@tonic-gate    return 1;
37*0Sstevel@tonic-gate}
38*0Sstevel@tonic-gate
39*0Sstevel@tonic-gateprint "1..54\n";
40*0Sstevel@tonic-gate
41*0Sstevel@tonic-gate$Is_MSWin32  = $^O eq 'MSWin32';
42*0Sstevel@tonic-gate$Is_NetWare  = $^O eq 'NetWare';
43*0Sstevel@tonic-gate$Is_VMS      = $^O eq 'VMS';
44*0Sstevel@tonic-gate$Is_Dos      = $^O eq 'dos';
45*0Sstevel@tonic-gate$Is_os2      = $^O eq 'os2';
46*0Sstevel@tonic-gate$Is_Cygwin   = $^O eq 'cygwin';
47*0Sstevel@tonic-gate$Is_MacOS    = $^O eq 'MacOS';
48*0Sstevel@tonic-gate$Is_MPE      = $^O eq 'mpeix';
49*0Sstevel@tonic-gate$Is_miniperl = $ENV{PERL_CORE_MINITEST};
50*0Sstevel@tonic-gate
51*0Sstevel@tonic-gate$PERL = ($Is_NetWare            ? 'perl'   :
52*0Sstevel@tonic-gate	 ($Is_MacOS || $Is_VMS) ? $^X      :
53*0Sstevel@tonic-gate	 $Is_MSWin32            ? '.\perl' :
54*0Sstevel@tonic-gate	 './perl');
55*0Sstevel@tonic-gate
56*0Sstevel@tonic-gateeval '$ENV{"FOO"} = "hi there";';	# check that ENV is inited inside eval
57*0Sstevel@tonic-gate# cmd.exe will echo 'variable=value' but 4nt will echo just the value
58*0Sstevel@tonic-gate# -- Nikola Knezevic
59*0Sstevel@tonic-gateif ($Is_MSWin32)  { ok `set FOO` =~ /^(?:FOO=)?hi there$/; }
60*0Sstevel@tonic-gateelsif ($Is_MacOS) { ok "1 # skipped", 1; }
61*0Sstevel@tonic-gateelsif ($Is_VMS)   { ok `write sys\$output f\$trnlnm("FOO")` eq "hi there\n"; }
62*0Sstevel@tonic-gateelse              { ok `echo \$FOO` eq "hi there\n"; }
63*0Sstevel@tonic-gate
64*0Sstevel@tonic-gateunlink 'ajslkdfpqjsjfk';
65*0Sstevel@tonic-gate$! = 0;
66*0Sstevel@tonic-gateopen(FOO,'ajslkdfpqjsjfk');
67*0Sstevel@tonic-gateok $!, $!;
68*0Sstevel@tonic-gateclose FOO; # just mention it, squelch used-only-once
69*0Sstevel@tonic-gate
70*0Sstevel@tonic-gateif ($Is_MSWin32 || $Is_NetWare || $Is_Dos || $Is_MPE || $Is_MacOS) {
71*0Sstevel@tonic-gate    skip('SIGINT not safe on this platform') for 1..4;
72*0Sstevel@tonic-gate}
73*0Sstevel@tonic-gateelse {
74*0Sstevel@tonic-gate  # the next tests are done in a subprocess because sh spits out a
75*0Sstevel@tonic-gate  # newline onto stderr when a child process kills itself with SIGINT.
76*0Sstevel@tonic-gate  # We use a pipe rather than system() because the VMS command buffer
77*0Sstevel@tonic-gate  # would overflow with a command that long.
78*0Sstevel@tonic-gate
79*0Sstevel@tonic-gate    open( CMDPIPE, "| $PERL");
80*0Sstevel@tonic-gate
81*0Sstevel@tonic-gate    print CMDPIPE <<'END';
82*0Sstevel@tonic-gate
83*0Sstevel@tonic-gate    $| = 1;		# command buffering
84*0Sstevel@tonic-gate
85*0Sstevel@tonic-gate    $SIG{"INT"} = "ok3";     kill "INT",$$; sleep 1;
86*0Sstevel@tonic-gate    $SIG{"INT"} = "IGNORE";  kill "INT",$$; sleep 1; print "ok 4\n";
87*0Sstevel@tonic-gate    $SIG{"INT"} = "DEFAULT"; kill "INT",$$; sleep 1; print "not ok 4\n";
88*0Sstevel@tonic-gate
89*0Sstevel@tonic-gate    sub ok3 {
90*0Sstevel@tonic-gate	if (($x = pop(@_)) eq "INT") {
91*0Sstevel@tonic-gate	    print "ok 3\n";
92*0Sstevel@tonic-gate	}
93*0Sstevel@tonic-gate	else {
94*0Sstevel@tonic-gate	    print "not ok 3 ($x @_)\n";
95*0Sstevel@tonic-gate	}
96*0Sstevel@tonic-gate    }
97*0Sstevel@tonic-gate
98*0Sstevel@tonic-gateEND
99*0Sstevel@tonic-gate
100*0Sstevel@tonic-gate    close CMDPIPE;
101*0Sstevel@tonic-gate
102*0Sstevel@tonic-gate    open( CMDPIPE, "| $PERL");
103*0Sstevel@tonic-gate    print CMDPIPE <<'END';
104*0Sstevel@tonic-gate
105*0Sstevel@tonic-gate    { package X;
106*0Sstevel@tonic-gate	sub DESTROY {
107*0Sstevel@tonic-gate	    kill "INT",$$;
108*0Sstevel@tonic-gate	}
109*0Sstevel@tonic-gate    }
110*0Sstevel@tonic-gate    sub x {
111*0Sstevel@tonic-gate	my $x=bless [], 'X';
112*0Sstevel@tonic-gate	return sub { $x };
113*0Sstevel@tonic-gate    }
114*0Sstevel@tonic-gate    $| = 1;		# command buffering
115*0Sstevel@tonic-gate    $SIG{"INT"} = "ok5";
116*0Sstevel@tonic-gate    {
117*0Sstevel@tonic-gate	local $SIG{"INT"}=x();
118*0Sstevel@tonic-gate	print ""; # Needed to expose failure in 5.8.0 (why?)
119*0Sstevel@tonic-gate    }
120*0Sstevel@tonic-gate    sleep 1;
121*0Sstevel@tonic-gate    delete $SIG{"INT"};
122*0Sstevel@tonic-gate    kill "INT",$$; sleep 1;
123*0Sstevel@tonic-gate    sub ok5 {
124*0Sstevel@tonic-gate	print "ok 5\n";
125*0Sstevel@tonic-gate    }
126*0Sstevel@tonic-gateEND
127*0Sstevel@tonic-gate    close CMDPIPE;
128*0Sstevel@tonic-gate    $? >>= 8 if $^O eq 'VMS'; # POSIX status hiding in 2nd byte
129*0Sstevel@tonic-gate    my $todo = ($^O eq 'os2' ? ' # TODO: EMX v0.9d_fix4 bug: wrong nibble? ' : '');
130*0Sstevel@tonic-gate    print $? & 0xFF ? "ok 6$todo\n" : "not ok 6$todo\n";
131*0Sstevel@tonic-gate
132*0Sstevel@tonic-gate    $test += 4;
133*0Sstevel@tonic-gate}
134*0Sstevel@tonic-gate
135*0Sstevel@tonic-gate# can we slice ENV?
136*0Sstevel@tonic-gate@val1 = @ENV{keys(%ENV)};
137*0Sstevel@tonic-gate@val2 = values(%ENV);
138*0Sstevel@tonic-gateok join(':',@val1) eq join(':',@val2);
139*0Sstevel@tonic-gateok @val1 > 1;
140*0Sstevel@tonic-gate
141*0Sstevel@tonic-gate# regex vars
142*0Sstevel@tonic-gate'foobarbaz' =~ /b(a)r/;
143*0Sstevel@tonic-gateok $` eq 'foo', $`;
144*0Sstevel@tonic-gateok $& eq 'bar', $&;
145*0Sstevel@tonic-gateok $' eq 'baz', $';
146*0Sstevel@tonic-gateok $+ eq 'a', $+;
147*0Sstevel@tonic-gate
148*0Sstevel@tonic-gate# $"
149*0Sstevel@tonic-gate@a = qw(foo bar baz);
150*0Sstevel@tonic-gateok "@a" eq "foo bar baz", "@a";
151*0Sstevel@tonic-gate{
152*0Sstevel@tonic-gate    local $" = ',';
153*0Sstevel@tonic-gate    ok "@a" eq "foo,bar,baz", "@a";
154*0Sstevel@tonic-gate}
155*0Sstevel@tonic-gate
156*0Sstevel@tonic-gate# $;
157*0Sstevel@tonic-gate%h = ();
158*0Sstevel@tonic-gate$h{'foo', 'bar'} = 1;
159*0Sstevel@tonic-gateok((keys %h)[0] eq "foo\034bar", (keys %h)[0]);
160*0Sstevel@tonic-gate{
161*0Sstevel@tonic-gate    local $; = 'x';
162*0Sstevel@tonic-gate    %h = ();
163*0Sstevel@tonic-gate    $h{'foo', 'bar'} = 1;
164*0Sstevel@tonic-gate    ok((keys %h)[0] eq 'fooxbar', (keys %h)[0]);
165*0Sstevel@tonic-gate}
166*0Sstevel@tonic-gate
167*0Sstevel@tonic-gate# $?, $@, $$
168*0Sstevel@tonic-gateif ($Is_MacOS) {
169*0Sstevel@tonic-gate    skip('$? + system are broken on MacPerl') for 1..2;
170*0Sstevel@tonic-gate}
171*0Sstevel@tonic-gateelse {
172*0Sstevel@tonic-gate    system qq[$PERL "-I../lib" -e "use vmsish qw(hushed); exit(0)"];
173*0Sstevel@tonic-gate    ok $? == 0, $?;
174*0Sstevel@tonic-gate    system qq[$PERL "-I../lib" -e "use vmsish qw(hushed); exit(1)"];
175*0Sstevel@tonic-gate    ok $? != 0, $?;
176*0Sstevel@tonic-gate}
177*0Sstevel@tonic-gate
178*0Sstevel@tonic-gateeval { die "foo\n" };
179*0Sstevel@tonic-gateok $@ eq "foo\n", $@;
180*0Sstevel@tonic-gate
181*0Sstevel@tonic-gateok $$ > 0, $$;
182*0Sstevel@tonic-gateeval { $$++ };
183*0Sstevel@tonic-gateok $@ =~ /^Modification of a read-only value attempted/;
184*0Sstevel@tonic-gate
185*0Sstevel@tonic-gate# $^X and $0
186*0Sstevel@tonic-gate{
187*0Sstevel@tonic-gate    if ($^O eq 'qnx') {
188*0Sstevel@tonic-gate	chomp($wd = `/usr/bin/fullpath -t`);
189*0Sstevel@tonic-gate    }
190*0Sstevel@tonic-gate    elsif($Is_Cygwin || $Config{'d_procselfexe'}) {
191*0Sstevel@tonic-gate       # Cygwin turns the symlink into the real file
192*0Sstevel@tonic-gate       chomp($wd = `pwd`);
193*0Sstevel@tonic-gate       $wd =~ s#/t$##;
194*0Sstevel@tonic-gate    }
195*0Sstevel@tonic-gate    elsif($Is_os2) {
196*0Sstevel@tonic-gate       $wd = Cwd::sys_cwd();
197*0Sstevel@tonic-gate    }
198*0Sstevel@tonic-gate    elsif($Is_MacOS) {
199*0Sstevel@tonic-gate       $wd = ':';
200*0Sstevel@tonic-gate    }
201*0Sstevel@tonic-gate    else {
202*0Sstevel@tonic-gate	$wd = '.';
203*0Sstevel@tonic-gate    }
204*0Sstevel@tonic-gate    my $perl = ($Is_MacOS || $Is_VMS) ? $^X : "$wd/perl";
205*0Sstevel@tonic-gate    my $headmaybe = '';
206*0Sstevel@tonic-gate    my $tailmaybe = '';
207*0Sstevel@tonic-gate    $script = "$wd/show-shebang";
208*0Sstevel@tonic-gate    if ($Is_MSWin32) {
209*0Sstevel@tonic-gate	chomp($wd = `cd`);
210*0Sstevel@tonic-gate	$wd =~ s|\\|/|g;
211*0Sstevel@tonic-gate	$perl = "$wd/perl.exe";
212*0Sstevel@tonic-gate	$script = "$wd/show-shebang.bat";
213*0Sstevel@tonic-gate	$headmaybe = <<EOH ;
214*0Sstevel@tonic-gate\@rem ='
215*0Sstevel@tonic-gate\@echo off
216*0Sstevel@tonic-gate$perl -x \%0
217*0Sstevel@tonic-gategoto endofperl
218*0Sstevel@tonic-gate\@rem ';
219*0Sstevel@tonic-gateEOH
220*0Sstevel@tonic-gate	$tailmaybe = <<EOT ;
221*0Sstevel@tonic-gate
222*0Sstevel@tonic-gate__END__
223*0Sstevel@tonic-gate:endofperl
224*0Sstevel@tonic-gateEOT
225*0Sstevel@tonic-gate    }
226*0Sstevel@tonic-gate    elsif ($Is_os2) {
227*0Sstevel@tonic-gate      $script = "./show-shebang";
228*0Sstevel@tonic-gate    }
229*0Sstevel@tonic-gate    elsif ($Is_MacOS) {
230*0Sstevel@tonic-gate      $script = ":show-shebang";
231*0Sstevel@tonic-gate    }
232*0Sstevel@tonic-gate    elsif ($Is_VMS) {
233*0Sstevel@tonic-gate      $script = "[]show-shebang";
234*0Sstevel@tonic-gate    }
235*0Sstevel@tonic-gate    if ($^O eq 'os390' or $^O eq 'posix-bc' or $^O eq 'vmesa') {  # no shebang
236*0Sstevel@tonic-gate	$headmaybe = <<EOH ;
237*0Sstevel@tonic-gate    eval 'exec ./perl -S \$0 \${1+"\$\@"}'
238*0Sstevel@tonic-gate        if 0;
239*0Sstevel@tonic-gateEOH
240*0Sstevel@tonic-gate    }
241*0Sstevel@tonic-gate    $s1 = "\$^X is $perl, \$0 is $script\n";
242*0Sstevel@tonic-gate    ok open(SCRIPT, ">$script"), $!;
243*0Sstevel@tonic-gate    ok print(SCRIPT $headmaybe . <<EOB . <<'EOF' . $tailmaybe), $!;
244*0Sstevel@tonic-gate#!$wd/perl
245*0Sstevel@tonic-gateEOB
246*0Sstevel@tonic-gateprint "\$^X is $^X, \$0 is $0\n";
247*0Sstevel@tonic-gateEOF
248*0Sstevel@tonic-gate    ok close(SCRIPT), $!;
249*0Sstevel@tonic-gate    ok chmod(0755, $script), $!;
250*0Sstevel@tonic-gate    $_ = ($Is_MacOS || $Is_VMS) ? `$perl $script` : `$script`;
251*0Sstevel@tonic-gate    s/\.exe//i if $Is_Dos or $Is_Cygwin or $Is_os2;
252*0Sstevel@tonic-gate    s{\bminiperl\b}{perl}; # so that test doesn't fail with miniperl
253*0Sstevel@tonic-gate    s{is perl}{is $perl}; # for systems where $^X is only a basename
254*0Sstevel@tonic-gate    s{\\}{/}g;
255*0Sstevel@tonic-gate    ok((($Is_MSWin32 || $Is_os2) ? uc($_) eq uc($s1) : $_ eq $s1), " :$_:!=:$s1:");
256*0Sstevel@tonic-gate    $_ = `$perl $script`;
257*0Sstevel@tonic-gate    s/\.exe//i if $Is_Dos or $Is_os2;
258*0Sstevel@tonic-gate    s{\\}{/}g;
259*0Sstevel@tonic-gate    ok((($Is_MSWin32 || $Is_os2) ? uc($_) eq uc($s1) : $_ eq $s1), " :$_:!=:$s1: after `$perl $script`");
260*0Sstevel@tonic-gate    ok unlink($script), $!;
261*0Sstevel@tonic-gate}
262*0Sstevel@tonic-gate
263*0Sstevel@tonic-gate# $], $^O, $^T
264*0Sstevel@tonic-gateok $] >= 5.00319, $];
265*0Sstevel@tonic-gateok $^O;
266*0Sstevel@tonic-gateok $^T > 850000000, $^T;
267*0Sstevel@tonic-gate
268*0Sstevel@tonic-gateif ($Is_VMS || $Is_Dos || $Is_MacOS) {
269*0Sstevel@tonic-gate    skip("%ENV manipulations fail or aren't safe on $^O") for 1..4;
270*0Sstevel@tonic-gate}
271*0Sstevel@tonic-gateelse {
272*0Sstevel@tonic-gate	if ($ENV{PERL_VALGRIND}) {
273*0Sstevel@tonic-gate	    skip("clearing \%ENV is not safe when running under valgrind");
274*0Sstevel@tonic-gate	} else {
275*0Sstevel@tonic-gate	    $PATH = $ENV{PATH};
276*0Sstevel@tonic-gate	    $PDL = $ENV{PERL_DESTRUCT_LEVEL} || 0;
277*0Sstevel@tonic-gate	    $ENV{foo} = "bar";
278*0Sstevel@tonic-gate	    %ENV = ();
279*0Sstevel@tonic-gate	    $ENV{PATH} = $PATH;
280*0Sstevel@tonic-gate	    $ENV{PERL_DESTRUCT_LEVEL} = $PDL || 0;
281*0Sstevel@tonic-gate	    ok ($Is_MSWin32 ? (`set foo 2>NUL` eq "")
282*0Sstevel@tonic-gate			    : (`echo \$foo` eq "\n") );
283*0Sstevel@tonic-gate	}
284*0Sstevel@tonic-gate
285*0Sstevel@tonic-gate	$ENV{__NoNeSuCh} = "foo";
286*0Sstevel@tonic-gate	$0 = "bar";
287*0Sstevel@tonic-gate# cmd.exe will echo 'variable=value' but 4nt will echo just the value
288*0Sstevel@tonic-gate# -- Nikola Knezevic
289*0Sstevel@tonic-gate       ok ($Is_MSWin32 ? (`set __NoNeSuCh` =~ /^(?:__NoNeSuCh=)?foo$/)
290*0Sstevel@tonic-gate			    : (`echo \$__NoNeSuCh` eq "foo\n") );
291*0Sstevel@tonic-gate	if ($^O =~ /^(linux|freebsd)$/ &&
292*0Sstevel@tonic-gate	    open CMDLINE, "/proc/$$/cmdline") {
293*0Sstevel@tonic-gate	    chomp(my $line = scalar <CMDLINE>);
294*0Sstevel@tonic-gate	    my $me = (split /\0/, $line)[0];
295*0Sstevel@tonic-gate	    ok($me eq $0, 'altering $0 is effective (testing with /proc/)');
296*0Sstevel@tonic-gate	    close CMDLINE;
297*0Sstevel@tonic-gate            # perlbug #22811
298*0Sstevel@tonic-gate            my $mydollarzero = sub {
299*0Sstevel@tonic-gate              my($arg) = shift;
300*0Sstevel@tonic-gate              $0 = $arg if defined $arg;
301*0Sstevel@tonic-gate	      # In FreeBSD the ps -o command= will cause
302*0Sstevel@tonic-gate	      # an empty header line, grab only the last line.
303*0Sstevel@tonic-gate              my $ps = (`ps -o command= -p $$`)[-1];
304*0Sstevel@tonic-gate              return if $?;
305*0Sstevel@tonic-gate              chomp $ps;
306*0Sstevel@tonic-gate              printf "# 0[%s]ps[%s]\n", $0, $ps;
307*0Sstevel@tonic-gate              $ps;
308*0Sstevel@tonic-gate            };
309*0Sstevel@tonic-gate            my $ps = $mydollarzero->("x");
310*0Sstevel@tonic-gate            ok(!$ps  # we allow that something goes wrong with the ps command
311*0Sstevel@tonic-gate	       # In Linux 2.4 we would get an exact match ($ps eq 'x') but
312*0Sstevel@tonic-gate	       # in Linux 2.2 there seems to be something funny going on:
313*0Sstevel@tonic-gate	       # it seems as if the original length of the argv[] would
314*0Sstevel@tonic-gate	       # be stored in the proc struct and then used by ps(1),
315*0Sstevel@tonic-gate	       # no matter what characters we use to pad the argv[].
316*0Sstevel@tonic-gate	       # (And if we use \0:s, they are shown as spaces.)  Sigh.
317*0Sstevel@tonic-gate               || $ps =~ /^x\s*$/
318*0Sstevel@tonic-gate	       # FreeBSD cannot get rid of both the leading "perl :"
319*0Sstevel@tonic-gate	       # and the trailing " (perl)": some FreeBSD versions
320*0Sstevel@tonic-gate	       # can get rid of the first one.
321*0Sstevel@tonic-gate	       || ($^O eq 'freebsd' && $ps =~ m/^(?:perl: )?x(?: \(perl\))?$/),
322*0Sstevel@tonic-gate		       'altering $0 is effective (testing with `ps`)');
323*0Sstevel@tonic-gate	} else {
324*0Sstevel@tonic-gate	    skip("\$0 check only on Linux and FreeBSD") for 0, 1;
325*0Sstevel@tonic-gate	}
326*0Sstevel@tonic-gate}
327*0Sstevel@tonic-gate
328*0Sstevel@tonic-gate{
329*0Sstevel@tonic-gate    my $ok = 1;
330*0Sstevel@tonic-gate    my $warn = '';
331*0Sstevel@tonic-gate    local $SIG{'__WARN__'} = sub { $ok = 0; $warn = join '', @_; };
332*0Sstevel@tonic-gate    $! = undef;
333*0Sstevel@tonic-gate    ok($ok, $warn, $Is_VMS ? "'\$!=undef' does throw a warning" : '');
334*0Sstevel@tonic-gate}
335*0Sstevel@tonic-gate
336*0Sstevel@tonic-gate# test case-insignificance of %ENV (these tests must be enabled only
337*0Sstevel@tonic-gate# when perl is compiled with -DENV_IS_CASELESS)
338*0Sstevel@tonic-gateif ($Is_MSWin32 || $Is_NetWare) {
339*0Sstevel@tonic-gate    %ENV = ();
340*0Sstevel@tonic-gate    $ENV{'Foo'} = 'bar';
341*0Sstevel@tonic-gate    $ENV{'fOo'} = 'baz';
342*0Sstevel@tonic-gate    ok (scalar(keys(%ENV)) == 1);
343*0Sstevel@tonic-gate    ok exists($ENV{'FOo'});
344*0Sstevel@tonic-gate    ok (delete($ENV{'foO'}) eq 'baz');
345*0Sstevel@tonic-gate    ok (scalar(keys(%ENV)) == 0);
346*0Sstevel@tonic-gate}
347*0Sstevel@tonic-gateelse {
348*0Sstevel@tonic-gate    skip('no caseless %ENV support') for 1..4;
349*0Sstevel@tonic-gate}
350*0Sstevel@tonic-gate
351*0Sstevel@tonic-gateif ($Is_miniperl) {
352*0Sstevel@tonic-gate    skip ("miniperl can't rely on loading %Errno") for 1..2;
353*0Sstevel@tonic-gate} else {
354*0Sstevel@tonic-gate   no warnings 'void';
355*0Sstevel@tonic-gate
356*0Sstevel@tonic-gate# Make sure Errno hasn't been prematurely autoloaded
357*0Sstevel@tonic-gate
358*0Sstevel@tonic-gate   ok !defined %Errno::;
359*0Sstevel@tonic-gate
360*0Sstevel@tonic-gate# Test auto-loading of Errno when %! is used
361*0Sstevel@tonic-gate
362*0Sstevel@tonic-gate   ok scalar eval q{
363*0Sstevel@tonic-gate      %!;
364*0Sstevel@tonic-gate      defined %Errno::;
365*0Sstevel@tonic-gate   }, $@;
366*0Sstevel@tonic-gate}
367*0Sstevel@tonic-gate
368*0Sstevel@tonic-gateif ($Is_miniperl) {
369*0Sstevel@tonic-gate    skip ("miniperl can't rely on loading %Errno");
370*0Sstevel@tonic-gate} else {
371*0Sstevel@tonic-gate    # Make sure that Errno loading doesn't clobber $!
372*0Sstevel@tonic-gate
373*0Sstevel@tonic-gate    undef %Errno::;
374*0Sstevel@tonic-gate    delete $INC{"Errno.pm"};
375*0Sstevel@tonic-gate
376*0Sstevel@tonic-gate    open(FOO, "nonesuch"); # Generate ENOENT
377*0Sstevel@tonic-gate    my %errs = %{"!"}; # Cause Errno.pm to be loaded at run-time
378*0Sstevel@tonic-gate    ok ${"!"}{ENOENT};
379*0Sstevel@tonic-gate}
380*0Sstevel@tonic-gate
381*0Sstevel@tonic-gateok $^S == 0 && defined $^S;
382*0Sstevel@tonic-gateeval { ok $^S == 1 };
383*0Sstevel@tonic-gateeval " BEGIN { ok ! defined \$^S } ";
384*0Sstevel@tonic-gateok $^S == 0 && defined $^S;
385*0Sstevel@tonic-gate
386*0Sstevel@tonic-gateok ${^TAINT} == 0;
387*0Sstevel@tonic-gateeval { ${^TAINT} = 1 };
388*0Sstevel@tonic-gateok ${^TAINT} == 0;
389*0Sstevel@tonic-gate
390*0Sstevel@tonic-gate# 5.6.1 had a bug: @+ and @- were not properly interpolated
391*0Sstevel@tonic-gate# into double-quoted strings
392*0Sstevel@tonic-gate# 20020414 mjd-perl-patch+@plover.com
393*0Sstevel@tonic-gate"I like pie" =~ /(I) (like) (pie)/;
394*0Sstevel@tonic-gateok "@-" eq  "0 0 2 7";
395*0Sstevel@tonic-gateok "@+" eq "10 1 6 10";
396*0Sstevel@tonic-gate
397*0Sstevel@tonic-gate# Tests for the magic get of $\
398*0Sstevel@tonic-gate{
399*0Sstevel@tonic-gate    my $ok = 0;
400*0Sstevel@tonic-gate    # [perl #19330]
401*0Sstevel@tonic-gate    {
402*0Sstevel@tonic-gate	local $\ = undef;
403*0Sstevel@tonic-gate	$\++; $\++;
404*0Sstevel@tonic-gate	$ok = $\ eq 2;
405*0Sstevel@tonic-gate    }
406*0Sstevel@tonic-gate    ok $ok;
407*0Sstevel@tonic-gate    $ok = 0;
408*0Sstevel@tonic-gate    {
409*0Sstevel@tonic-gate	local $\ = "a\0b";
410*0Sstevel@tonic-gate	$ok = "a$\b" eq "aa\0bb";
411*0Sstevel@tonic-gate    }
412*0Sstevel@tonic-gate    ok $ok;
413*0Sstevel@tonic-gate}
414*0Sstevel@tonic-gate
415*0Sstevel@tonic-gate# Test for bug [perl #27839]
416*0Sstevel@tonic-gate{
417*0Sstevel@tonic-gate    my $x;
418*0Sstevel@tonic-gate    sub f {
419*0Sstevel@tonic-gate	"abc" =~ /(.)./;
420*0Sstevel@tonic-gate	$x = "@+";
421*0Sstevel@tonic-gate	return @+;
422*0Sstevel@tonic-gate    };
423*0Sstevel@tonic-gate    my @y = f();
424*0Sstevel@tonic-gate    ok( $x eq "@y", "return a magic array ($x) vs (@y)" );
425*0Sstevel@tonic-gate}
426