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