1 package VPIT::TestHelpers;
9 load_or_skip => \&load_or_skip,
10 load_or_skip_all => \&load_or_skip_all,
11 run_perl => \&run_perl,
12 skip_all => \&skip_all,
18 while (my ($name, $code) = each %exports) {
20 *{$pkg.'::'.$name} = $code;
28 if ($INC{'Test/Leaner.pm'}) {
29 $stash = \%Test::Leaner::;
32 $stash = \%Test::More::;
35 my $glob = $stash->{$sub};
36 return $glob ? *$glob{CODE} : undef;
39 sub skip { $test_sub->('skip')->(@_) }
41 sub skip_all { $test_sub->('plan')->(skip_all => $_[0]) }
44 my $diag = $test_sub->('diag');
52 my ($pkg, $ver, $imports) = @_;
54 my $spec = $ver && $ver !~ /^[0._]*$/ ? "$pkg $ver" : $pkg;
58 if (eval "use $spec (); 1") {
59 $ver = do { no strict 'refs'; ${"${pkg}::VERSION"} };
60 $ver = 'undef' unless defined $ver;
63 my @imports = @$imports;
64 my $caller = (caller 1)[0];
66 my $res = eval <<"IMPORTER";
69 BEGIN { \$pkg->import(\@imports) }
72 $err = "Could not import '@imports' from $pkg $ver: $@" unless $res;
75 (my $file = "$pkg.pm") =~ s{::}{/}g;
77 $err = "Could not load $spec";
81 return wantarray ? (0, $err) : 0;
83 diag "Using $pkg $ver";
89 my ($pkg, $ver, $imports, $tests) = @_;
91 die 'You must specify how many tests to skip' unless defined $tests;
93 my ($loaded, $err) = load($pkg, $ver, $imports);
94 skip $err => $tests unless $loaded;
99 sub load_or_skip_all {
100 my ($pkg, $ver, $imports) = @_;
102 my ($loaded, $err) = load($pkg, $ver, $imports);
103 skip_all $err unless $loaded;
111 my ($SystemRoot, $PATH) = @ENV{qw<SystemRoot PATH>};
112 my $ld_name = $Config::Config{ldlibpthname};
113 my $ldlibpth = $ENV{$ld_name};
116 $ENV{SystemRoot} = $SystemRoot if $^O eq 'MSWin32' and defined $SystemRoot;
117 $ENV{PATH} = $PATH if $^O eq 'cygwin' and defined $PATH;
118 $ENV{$ld_name} = $ldlibpth if $^O eq 'android' and defined $ldlibpth;
120 system { $^X } $^X, '-T', map("-I$_", @INC), '-e', $code;
123 package VPIT::TestHelpers::Guard;
126 my ($class, $code) = @_;
128 bless { code => $code }, $class;
131 sub DESTROY { $_[0]->{code}->() }