Integrate mainline
[p5sagit/p5-mst-13.2.git] / t / op / magic.t
index c39ad64..436e253 100755 (executable)
@@ -8,6 +8,7 @@ BEGIN {
 }
 
 use warnings;
+use Config;
 
 my $test = 1;
 sub ok {
@@ -35,7 +36,7 @@ sub skip {
     return 1;
 }
 
-print "1..43\n";
+print "1..46\n";
 
 $Is_MSWin32 = $^O eq 'MSWin32';
 $Is_NetWare = $^O eq 'NetWare';
@@ -46,16 +47,17 @@ $Is_Cygwin  = $^O eq 'cygwin';
 $Is_MacOS   = $^O eq 'MacOS';
 $Is_MPE     = $^O eq 'mpeix';          
 
-$PERL = ($Is_NetWare ? 'perl'   :
-        $Is_MacOS   ? $^X      :
-        $Is_MSWin32 ? '.\perl' :
+$PERL = ($Is_NetWare            ? 'perl'   :
+        ($Is_MacOS || $Is_VMS) ? $^X      :
+        $Is_MSWin32            ? '.\perl' :
         './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
-if ($Is_MSWin32)  { ok `set FOO` =~ /^(FOO=)?hi there$/; }
+if ($Is_MSWin32)  { ok `set FOO` =~ /^(?:FOO=)?hi there$/; }
 elsif ($Is_MacOS) { ok "1 # skipped", 1; }
+elsif ($Is_VMS)   { ok `write sys\$output f\$trnlnm("FOO")` eq "hi there\n"; }
 else              { ok `echo \$FOO` eq "hi there\n"; }
 
 unlink 'ajslkdfpqjsjfk';
@@ -68,9 +70,14 @@ if ($Is_MSWin32 || $Is_NetWare || $Is_Dos || $Is_MPE || $Is_MacOS) {
     skip('SIGINT not safe on this platform') for 1..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.
-    system './perl', '-e', <<'END';
+  # 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.
+
+    open( CMDPIPE, "| $PERL");
+
+    print CMDPIPE <<'END';
 
     $| = 1;            # command buffering
 
@@ -88,6 +95,9 @@ else {
     }
 
 END
+
+    close CMDPIPE;
+
     $test += 2;
 }
 
@@ -124,22 +134,29 @@ ok((keys %h)[0] eq "foo\034bar", (keys %h)[0]);
 }
 
 # $?, $@, $$
-system qq[$PERL -e "exit(0)"];
-ok $? == 0, $?;
-system qq[$PERL -e "exit(1)"];
-ok $? != 0, $?;
+if ($Is_MacOS) {
+    skip('$? + system are broken on MacPerl') for 1..2;
+}
+else {
+    system qq[$PERL "-I../lib" -e "use vmsish qw(hushed); exit(0)"];
+    ok $? == 0, $?;
+    system qq[$PERL "-I../lib" -e "use vmsish qw(hushed); exit(1)"];
+    ok $? != 0, $?;
+}
 
 eval { die "foo\n" };
 ok $@ eq "foo\n", $@;
 
 ok $$ > 0, $$;
+eval { $$++ };
+ok $@ =~ /^Modification of a read-only value attempted/;
 
 # $^X and $0
 {
     if ($^O eq 'qnx') {
        chomp($wd = `/usr/bin/fullpath -t`);
     }
-    elsif($Is_Cygwin) {
+    elsif($Is_Cygwin || $Config{'d_procselfexe'}) {
        # Cygwin turns the symlink into the real file
        chomp($wd = `pwd`);
        $wd =~ s#/t$##;
@@ -153,7 +170,7 @@ ok $$ > 0, $$;
     else {
        $wd = '.';
     }
-    my $perl = $Is_MacOS ? $^X : "$wd/perl";
+    my $perl = ($Is_MacOS || $Is_VMS) ? $^X : "$wd/perl";
     my $headmaybe = '';
     my $tailmaybe = '';
     $script = "$wd/show-shebang";
@@ -181,8 +198,8 @@ EOT
     elsif ($Is_MacOS) {
       $script = ":show-shebang";
     }
-    elsif ($Is_MacOS) {
-      $script = ":show-shebang";
+    elsif ($Is_VMS) {
+      $script = "[]show-shebang";
     }
     if ($^O eq 'os390' or $^O eq 'posix-bc' or $^O eq 'vmesa') {  # no shebang
        $headmaybe = <<EOH ;
@@ -199,7 +216,7 @@ print "\$^X is $^X, \$0 is $0\n";
 EOF
     ok close(SCRIPT), $!;
     ok chmod(0755, $script), $!;
-    $_ = $Is_MacOS ? `$perl $script` : `$script`;
+    $_ = ($Is_MacOS || $Is_VMS) ? `$perl $script` : `$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
@@ -218,7 +235,7 @@ ok $^O;
 ok $^T > 850000000, $^T;
 
 if ($Is_VMS || $Is_Dos || $Is_MacOS) {
-    skip("cannot test on $^O") for 1..2;
+    skip("%ENV manipulations fail or aren't safe on $^O") for 1..2;
 }
 else {
        $PATH = $ENV{PATH};
@@ -234,14 +251,16 @@ else {
        $0 = "bar";
 # cmd.exe will echo 'variable=value' but 4nt will echo just the value
 # -- Nikola Knezevic
-       ok ($Is_MSWin32 ? (`set __NoNeSuCh` =~ /^(__NoNeSuCh=)?foo$/)
+       ok ($Is_MSWin32 ? (`set __NoNeSuCh` =~ /^(?:__NoNeSuCh=)?foo$/)
                            : (`echo \$__NoNeSuCh` eq "foo\n") );
 }
 
 {
-    local $SIG{'__WARN__'} = sub { print "# @_\nnot " };
+    my $ok = 1;
+    my $warn = '';
+    local $SIG{'__WARN__'} = sub { $ok = 0; $warn = join '', @_; };
     $! = undef;
-    ok 1;
+    ok($ok, $warn, $Is_VMS ? "'\$!=undef' does throw a warning" : '');
 }
 
 # test case-insignificance of %ENV (these tests must be enabled only
@@ -287,3 +306,11 @@ ok $^S == 0;
 ok ${^TAINT} == 0;
 eval { ${^TAINT} = 1 };
 ok ${^TAINT} == 0;
+
+# 5.6.1 had a bug: @+ and @- were not properly interpolated
+# into double-quoted strings
+# 20020414 mjd-perl-patch+@plover.com
+"I like pie" =~ /(I) (like) (pie)/;
+ok "@-" eq  "0 0 2 7";
+ok "@+" eq "10 1 6 10";
+