From: Florian Ragwitz Date: Wed, 7 Jan 2009 06:59:23 +0000 (+0000) Subject: Turn generation of pure perl tests into a makefile target. X-Git-Tag: 0.76~21 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6e97d9ad838f92e8b8b962a8cb026f8b6e0f9ce3;p=gitmo%2FClass-MOP.git Turn generation of pure perl tests into a makefile target. --- diff --git a/Makefile.PL b/Makefile.PL index 004ea1c..8a5d375 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -18,7 +18,7 @@ for (@ARGV) { /^--xs/ and $force_xs = 1; } -my $has_compiler = $force_xs; +our $has_compiler = $force_xs; unless ( defined $force_xs ) { $has_compiler = check_for_compiler() or no_cc(); @@ -41,10 +41,6 @@ my %prereqs = ( delete @prereqs{qw(Sub::Name Devel::GlobalDestruction)} unless $has_compiler; -if ($has_compiler && is_maintainer()) { - create_pp_tests(); -} - write_makefile(); sub write_makefile { @@ -131,32 +127,12 @@ sub is_maintainer { return 1; } -sub create_pp_tests { +sub get_pp_tests { opendir my $dh, 't' or die "Cannot read t: $!"; - foreach my $file ( grep {/^\d.+\.t$/} readdir $dh ) { - next if $file =~ /^99/; - - my $real_file = File::Spec->catfile( 't', $file ); - - open my $fh, '<', $real_file - or die "Cannot read $real_file: $!"; - - my $shbang = <$fh>; - my $test = do { local $/; <$fh> }; - - close $fh; - - $test = "$shbang\nBEGIN { \$ENV{CLASS_MOP_NO_XS} = 1 }\n\n$test"; - - my $new_file = File::Spec->catfile( 't', "pp_$file" ); - open my $new_fh, '>', $new_file - or die "Cannot write to $new_file: $!"; - - print $new_fh $test; - - close $new_fh; - } + return map { + File::Spec->catfile('t', "pp_${_}") + } grep { $_ !~ /^99/ } grep {/^\d.+\.t$/} readdir $dh; } # This is EUMM voodoo @@ -169,3 +145,21 @@ sub init { $hash; } + +package MY; + +sub postamble { + my $pp_tests = join q{ }, ::get_pp_tests(); + my $test_dep = $::has_compiler && ::is_maintainer() + ? 'pure_all :: pp_tests' + : ''; + + return <<"EOM" +pp_tests: ${pp_tests} + +${test_dep} + +t/pp_%: t/% t/header_pp.inc +\t\$(NOECHO) \$(ABSPERLRUN) "-MExtUtils::Command" -e cat t/header_pp.inc \$< >> \$@ +EOM +} diff --git a/t/header_pp.inc b/t/header_pp.inc new file mode 100644 index 0000000..3f6d438 --- /dev/null +++ b/t/header_pp.inc @@ -0,0 +1,2 @@ +BEGIN { $ENV{CLASS_MOP_NO_XS} = 1 } +