From: Vincent Pit Date: Thu, 9 Apr 2015 16:15:25 +0000 (-0300) Subject: Turn run_perl() into a feature X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=274ec39542b4a7f51a3dd39cd3e9e5dd1ee88eb8;p=perl%2Fmodules%2FVPIT-TestHelpers.git Turn run_perl() into a feature --- diff --git a/lib/VPIT/TestHelpers.pm b/lib/VPIT/TestHelpers.pm index 6a3655e..a6ca519 100644 --- a/lib/VPIT/TestHelpers.pm +++ b/lib/VPIT/TestHelpers.pm @@ -19,14 +19,14 @@ sub export_to_pkg { my %default_exports = ( load_or_skip => \&load_or_skip, load_or_skip_all => \&load_or_skip_all, - run_perl => \&run_perl, skip_all => \&skip_all, ); my %features = ( - threads => \&init_threads, - usleep => \&init_usleep, - capture => \&init_capture, + threads => \&init_threads, + usleep => \&init_usleep, + run_perl => \&init_run_perl, + capture => \&init_capture, ); sub import { @@ -165,6 +165,25 @@ sub fresh_perl_env (&) { return $handler->($perl, '-T', map("-I$_", @INC)); } +sub init_run_perl { + my $prefix = shift; + + if (defined $prefix) { + if (length $prefix and $prefix !~ /_$/) { + $prefix .= '_'; + } + } else { + $prefix = ''; + } + + my $p = $prefix; + + return ( + run_perl => \&run_perl, + "${p}RUN_PERL_FAILED" => sub () { 'Could not execute perl subprocess' }, + ); +} + sub run_perl { my $code = shift; diff --git a/t/30-run_perl.t b/t/30-run_perl.t index 077b58e..2238fb7 100644 --- a/t/30-run_perl.t +++ b/t/30-run_perl.t @@ -3,9 +3,9 @@ use strict; use warnings; -use VPIT::TestHelpers; +use VPIT::TestHelpers 'run_perl' => [ 'VTH' ]; -use Test::More tests => 5 + 1; +use Test::More tests => 5 + 2; use Config; use File::Temp; @@ -75,3 +75,8 @@ for my $os (qw) { like $@, qr/^Double quotes in evaluated code are not portable/, 'croak on double quotes'; } + +{ + my $msg = VTH_RUN_PERL_FAILED; + like $msg, qr/^Could not execute/, 'RUN_PERL_FAILED error message'; +}