1bbfd6e7ac0aeba15a35cb18d7b28136e683a3ce
[p5sagit/namespace-clean.git] / t / 10-pure-perl.t
1 use strict;
2 use warnings;
3 use Test::More;
4
5 BEGIN {
6   plan skip_all => "PP tests already executed"
7     if $ENV{NAMESPACE_CLEAN_USE_PP};
8
9   plan skip_all => "B::Hooks::EndOfScope ($INC{'B/Hooks/EndOfScope.pm'}) loaded before the test even started >.<"
10     if $INC{'B/Hooks/EndOfScope.pm'};
11
12   eval { require Variable::Magic }
13     or plan skip_all => "PP tests already executed";
14
15   $ENV{B_HOOKS_ENDOFSCOPE_IMPLEMENTATION} = 'PP';
16 }
17
18 use B::Hooks::EndOfScope 0.12;
19
20 ok(
21   ($INC{'B/Hooks/EndOfScope/PP.pm'} && ! $INC{'B/Hooks/EndOfScope/XS.pm'}),
22   'PP BHEOS loaded properly'
23 ) || diag join "\n",
24   map { sprintf '%s => %s', $_, $INC{"B/Hooks/$_"} || 'undef' }
25   qw|EndOfScope.pm EndOfScope/XS.pm EndOfScope/PP.pm|
26 ;
27
28 use Config;
29 use FindBin qw($Bin);
30 use IPC::Open2 qw(open2);
31 use File::Glob 'bsd_glob';
32
33 # for the $^X-es
34 $ENV{PERL5LIB} = join ($Config{path_sep}, @INC);
35
36
37 # rerun the tests under the assumption of pure-perl
38 my $this_file = quotemeta(__FILE__);
39
40 for my $fn (bsd_glob("$Bin/*.t")) {
41   next if $fn =~ /${this_file}$/;
42
43   my @cmd = ($^X, $fn);
44
45   # this is cheating, and may even hang here and there (testing on windows passed fine)
46   # if it does - will have to fix it somehow (really *REALLY* don't want to pull
47   # in IPC::Cmd just for a fucking test)
48   # the alternative would be to have an ENV check in each test to force a subtest
49   open2(my $out, my $in, @cmd);
50   while (my $ln = <$out>) {
51     print "   $ln";
52   }
53
54   wait;
55   ok (! $?, "Exit $? from: @cmd");
56 }
57
58 done_testing;