edf3f05f87f1af9cd5af352340edc0553ee7e5c3
[p5sagit/namespace-clean.git] / t / 10-pure-perl.t
1 use strict;
2 use warnings;
3 use Test::More;
4
5 plan skip_all => "PP tests already executed"
6   if $ENV{NAMESPACE_CLEAN_USE_PP};
7
8 eval { require B::Hooks::EndOfScope }
9   or plan skip_all => "PP tests already executed";
10
11 # the PP tests will run either wih D::H (mainly on smokers)
12 # or by setting the envvar (for users)
13 my $has_d_h = eval { require Devel::Hide };
14
15 use Config;
16 use FindBin qw($Bin);
17 use IPC::Open2 qw(open2);
18 use File::Glob 'bsd_glob';
19
20 # for the $^X-es
21 $ENV{PERL5LIB} = join ($Config{path_sep}, @INC);
22
23 # rerun the tests under the assumption of pure-perl
24 my $this_file = quotemeta(__FILE__);
25
26 for my $fn (bsd_glob("$Bin/*.t")) {
27   next if $fn =~ /${this_file}$/;
28
29   local $ENV{DEVEL_HIDE_VERBOSE} = 0;
30   local $ENV{NAMESPACE_CLEAN_USE_PP} = 1 unless $has_d_h;
31   my @cmd = (
32     $^X,
33     $has_d_h ? '-MDevel::Hide=B::Hooks::EndOfScope' : (),
34     $fn
35   );
36
37   # this is cheating, and may even hang here and there (testing on windows passed fine)
38   # if it does - will have to fix it somehow (really *REALLY* don't want to pull
39   # in IPC::Cmd just for a fucking test)
40   # the alternative would be to have an ENV check in each test to force a subtest
41   open2(my $out, my $in, @cmd);
42   while (my $ln = <$out>) {
43     print "   $ln";
44   }
45
46   wait;
47   ok (! $?, "Exit $? from: @cmd");
48 }
49
50 done_testing;