]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - t/17-ctl.t
Update VPIT::TestHelpers to f24eb57f
[perl/modules/Variable-Magic.git] / t / 17-ctl.t
index f781a67902d14eac1a12372c2588f65a110c615e..88345409e64d6c50d6e6fd54ac507f745a3e2089 100644 (file)
@@ -3,7 +3,10 @@
 use strict;
 use warnings;
 
-use Test::More tests => 4 * 8 + 4 * (2 * 4 + 1) + 10 + 1 + 1;
+use Test::More tests => 4 * 8 + 4 * (2 * 6 + 1) + 10 + 1 + 1;
+
+use lib 't/lib';
+use VPIT::TestHelpers 'capture';
 
 use Variable::Magic qw<wizard cast VMG_UVAR>;
 
@@ -152,7 +155,7 @@ for my $t (@scalar_tests) {
     my $x;
     cast $x, $wiz;
    };
-   $check->("$desc at eval BLOCK 1");
+   $check->("$desc at eval BLOCK 1a");
 
    local $@ = $local_out ? 'xxx' : undef;
    eval q{
@@ -160,7 +163,23 @@ for my $t (@scalar_tests) {
     my $x;
     cast $x, $wiz;
    };
-   $check->("$desc at eval STRING 1");
+   $check->("$desc at eval STRING 1a");
+
+   local $@ = $local_out ? 'xxx' : undef;
+   eval {
+    my $x;
+    local $@ = 'yyy' if $local_in;
+    cast $x, $wiz;
+   };
+   $check->("$desc at eval BLOCK 1b");
+
+   local $@ = $local_out ? 'xxx' : undef;
+   eval q{
+    my $x;
+    local $@ = 'yyy' if $local_in;
+    cast $x, $wiz;
+   };
+   $check->("$desc at eval STRING 1b");
 
    local $@ = $local_out ? 'xxx' : undef;
    eval {
@@ -169,7 +188,7 @@ for my $t (@scalar_tests) {
     my $y = \$x;
     &cast($y, $wiz);
    };
-   $check->("$desc at eval BLOCK 2");
+   $check->("$desc at eval BLOCK 2a");
 
    local $@ = $local_out ? 'xxx' : undef;
    eval q{
@@ -178,7 +197,25 @@ for my $t (@scalar_tests) {
     my $y = \$x;
     &cast($y, $wiz);
    };
-   $check->("$desc at eval STRING 2");
+   $check->("$desc at eval STRING 2a");
+
+   local $@ = $local_out ? 'xxx' : undef;
+   eval {
+    my $x;
+    my $y = \$x;
+    local $@ = 'yyy' if $local_in;
+    &cast($y, $wiz);
+   };
+   $check->("$desc at eval BLOCK 2b");
+
+   local $@ = $local_out ? 'xxx' : undef;
+   eval q{
+    my $x;
+    my $y = \$x;
+    local $@ = 'yyy' if $local_in;
+    &cast($y, $wiz);
+   };
+   $check->("$desc at eval STRING 2b");
 
    local $@ = $local_out ? 'xxx' : undef;
    eval {
@@ -308,52 +345,15 @@ eval q{BEGIN {
 like $@, expect('tomato', undef, "\nBEGIN.*"),
                           'die in BEGIN in eval triggers hints hash destructor';
 
-sub run_perl {
- my $code = shift;
-
- my ($SystemRoot, $PATH) = @ENV{qw<SystemRoot PATH>};
- local %ENV;
- $ENV{SystemRoot} = $SystemRoot if $^O eq 'MSWin32' and defined $SystemRoot;
- $ENV{PATH}       = $PATH       if $^O eq 'cygwin'  and defined $PATH;
-
- system { $^X } $^X, '-T', map("-I$_", @INC), '-e', $code;
-}
-
-my $has_capture_tiny = do {
- local $@;
- eval {
-  require Capture::Tiny;
-  Capture::Tiny->VERSION('0.08');
- }
-};
-if ($has_capture_tiny) {
- local $@;
- my $output = eval {
-  Capture::Tiny::capture_merged(sub { run_perl <<'  CODE' });
-print STDOUT "pants\n";
-print STDERR "trousers\n";
-  CODE
- };
- unless (defined $output and $output =~ /pants/ and $output =~ /trousers/) {
-  $has_capture_tiny = 0;
- }
-}
-if ($has_capture_tiny) {
- defined and diag "Using Capture::Tiny $_" for $Capture::Tiny::VERSION;
-}
-
-SKIP:
-{
+SKIP: {
  my $count = 1;
 
- skip 'No working Capture::Tiny is installed'=> $count unless $has_capture_tiny;
-
- my $output = Capture::Tiny::capture_merged(sub { run_perl <<' CODE' });
+ my ($stat, $out, $err) = capture_perl <<' CODE';
 use Variable::Magic qw<wizard cast>; { BEGIN { $^H |= 0x020000; cast %^H, wizard free => sub { die q[cucumber] } } }
  CODE
- skip 'Test code didn\'t run properly' => $count unless defined $output;
- like $output, expect('cucumber', '-e', "\nExecution(?s:.*)"),
-                  'die in free callback at compile time and not in eval string';
+ skip CAPTURE_PERL_FAILED($out) => $count unless defined $stat;
+ like $err, expect('cucumber', '-e', "\nExecution(?s:.*)"),
+            'die in free callback at compile time and not in eval string';
  --$count;
 }
 
@@ -363,14 +363,13 @@ SKIP:
 {
  my $count = 1;
 
- skip 'No nice uvar magic for this perl'     => $count unless VMG_UVAR;
- skip 'No working Capture::Tiny is installed'=> $count unless $has_capture_tiny;
+ skip 'No nice uvar magic for this perl' => $count unless VMG_UVAR;
 
- my $output = Capture::Tiny::capture_merged(sub { run_perl <<' CODE' });
+ my ($stat, $out, $err) = capture_perl <<' CODE';
 use Variable::Magic qw<wizard cast>; BEGIN { cast %derp::, wizard fetch => sub { die q[raddish] } } derp::hlagh()
  CODE
- skip 'Test code didn\'t run properly' => $count unless defined $output;
- like $output, expect('raddish', '-e', "\nExecution(?s:.*)"),
-               'die in free callback at compile time and not in eval string';
+ skip CAPTURE_PERL_FAILED($out) => $count unless defined $stat;
+ like $err, expect('raddish', '-e', "\nExecution(?s:.*)"),
+            'die in free callback at compile time and not in eval string';
  --$count;
 }