Make sure t/10-pure-perl.t runs are identical regardless of invocation
[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   plan skip_all => "Package::Stash ($INC{'Package/Stash.pm'}) loaded before the test even started >.<"
13     if $INC{'Package/Stash.pm'};
14
15   eval { require Variable::Magic }
16     or plan skip_all => "PP tests already executed";
17
18   $ENV{B_HOOKS_ENDOFSCOPE_IMPLEMENTATION} = 'PP';
19   $ENV{PACKAGE_STASH_IMPLEMENTATION} = 'PP';
20 }
21
22 use B::Hooks::EndOfScope 0.12;
23 use Package::Stash;
24
25 ok(
26   ($INC{'B/Hooks/EndOfScope/PP.pm'} && ! $INC{'B/Hooks/EndOfScope/XS.pm'}),
27   'PP BHEOS loaded properly'
28 ) || diag join "\n",
29   map { sprintf '%s => %s', $_, $INC{"B/Hooks/$_"} || 'undef' }
30   qw|EndOfScope.pm EndOfScope/XS.pm EndOfScope/PP.pm|
31 ;
32
33 ok(
34   ($INC{'Package/Stash/PP.pm'} && ! $INC{'Package/Stash/XS.pm'}),
35   'PP Package::Stash loaded properly'
36 ) || diag join "\n",
37   map { sprintf '%s => %s', $_, $INC{"Package/$_"} || 'undef' }
38   qw|Stash.pm Stash/XS.pm Stash/PP.pm|
39 ;
40
41 use Config;
42 use IPC::Open2 qw(open2);
43 use File::Glob 'bsd_glob';
44 use Cwd 'abs_path';
45
46 # for the $^X-es
47 $ENV{PERL5LIB} = join ($Config{path_sep}, @INC);
48 $ENV{PATH} = '';
49
50
51 # rerun the tests under the assumption of pure-perl
52 my $this_file = abs_path(__FILE__);
53
54 for my $fn ( bsd_glob("t/*.t") ) {
55
56   next if abs_path($fn) eq $this_file;
57
58   my @cmd = map { $_ =~ /(.+)/ } ($^X, $fn);
59
60   # this is cheating, and may even hang here and there (testing on windows passed fine)
61   # if it does - will have to fix it somehow (really *REALLY* don't want to pull
62   # in IPC::Cmd just for a fucking test)
63   # the alternative would be to have an ENV check in each test to force a subtest
64   open2(my $out, my $in, @cmd);
65   while (my $ln = <$out>) {
66     print "   $ln";
67   }
68
69   wait;
70   ok (! $?, "Exit $? from: @cmd");
71 }
72
73 done_testing;