Add a test that "eval" does not create additional reference to ouside variables.
[p5sagit/p5-mst-13.2.git] / t / op / sprintf.t
old mode 100755 (executable)
new mode 100644 (file)
index 2b9c7bc..a127143
@@ -49,8 +49,8 @@ while (<DATA>) {
     }
 
     $evalData = eval $data;
-    $data = ref $evalData ? $evalData : [$evalData];
-    push @tests, [$template, $data, $result, $comment];
+    $evalData = ref $evalData ? $evalData : [$evalData];
+    push @tests, [$template, $evalData, $result, $comment, $data];
 }
 
 print '1..', scalar @tests, "\n";
@@ -60,15 +60,17 @@ $SIG{__WARN__} = sub {
        $w = ' INVALID';
     } elsif ($_[0] =~ /^Use of uninitialized value/) {
        $w = ' UNINIT';
+    } elsif ($_[0] =~ /^Missing argument/) {
+       $w = ' MISSING';
     } else {
        warn @_;
     }
 };
 
 for ($i = 1; @tests; $i++) {
-    ($template, $data, $result, $comment) = @{shift @tests};
+    ($template, $evalData, $result, $comment, $data) = @{shift @tests};
     $w = undef;
-    $x = sprintf(">$template<", @$data);
+    $x = sprintf(">$template<", @$evalData);
     substr($x, -1, 0) = $w if $w;
     # $x may have 3 exponent digits, not 2
     my $y = $x;
@@ -306,11 +308,11 @@ __END__
 >%vd<       >"\01\02\03"< >1.2.3<
 >%vd<       >v1.2.3<      >1.2.3<
 >%vd<       >[version::qv("1.2.3")]< >1.2.3<
->%vd<       >[version->new("1.2")]< >1.200<
->%vd<       >[version->new("1.02")]< >1.20<
+>%vd<       >[version->new("1.2")]< >1.2<
+>%vd<       >[version->new("1.02")]< >1.2<
 >%vd<       >[version->new("1.002")]< >1.2<
->%vd<       >[version->new("1048576.5")]< >1048576.500<
->%vd<       >[version->new("50")]< >50.0<
+>%vd<       >[version->new("1048576.5")]< >1048576.5<
+>%vd<       >[version->new("50")]< >50<
 >%v.3d<     >"\01\02\03"< >001.002.003<
 >%0v3d<     >"\01\02\03"< >001.002.003<
 >%v.3d<     >[version::qv("1.2.3")]< >001.002.003<
@@ -618,7 +620,7 @@ __END__
 >%3$d %d %d<   >[12, 34, 56]<  >56 12 34<
 >%2$*3$d %d<   >[12, 34, 3]<   > 34 12<
 >%*3$2$d %d<   >[12, 34, 3]<   >%*3$2$d 12 INVALID<
->%2$d<         >12<    >0 UNINIT<
+>%2$d<         >12<    >0 MISSING<
 >%0$d<         >12<    >%0$d INVALID<
 >%1$$d<                >12<    >%1$$d INVALID<
 >%1$1$d<       >12<    >%1$1$d INVALID<
@@ -685,4 +687,4 @@ __END__
 >%#o<          >0<     >0<
 >%#x<          >0<     >0<
 >%2147483647$v2d<      >''<    ><
->%*2147483647$v2d<     >''<    > UNINIT<
+>%*2147483647$v2d<     >''<    > MISSING<