Even better, include the code that failed to compile in the error.
[gitmo/Class-MOP.git] / Makefile.PL
index 4dbda50..7cfceca 100644 (file)
@@ -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();
@@ -34,15 +34,13 @@ my %prereqs = (
     'File::Spec'               => '0',
     'Carp'                     => '0',
     'Devel::GlobalDestruction' => '0',
+    'Task::Weaken'             => '0',
+    'B'                        => '0',
 );
 
 delete @prereqs{qw(Sub::Name Devel::GlobalDestruction)}
     unless $has_compiler;
 
-if ($has_compiler && is_maintainer()) {
-    create_pp_tests();
-}
-
 write_makefile();
 
 sub write_makefile {
@@ -129,32 +127,10 @@ 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 grep { $_ !~ /^99/ } grep {/^\d.+\.t$/} readdir $dh;
 }
 
 # This is EUMM voodoo
@@ -167,3 +143,27 @@ sub init {
 
     $hash;
 }
+
+package MY;
+
+sub postamble {
+    my @test_files = ::get_pp_tests();
+    my $pp_tests = join q{ }, map { File::Spec->catfile('t', "pp_${_}") } @test_files;
+    my @pp_test_targets = join qq{\n}, map {
+        my $source = File::Spec->catfile('t', ${_});
+        File::Spec->catfile('t', "pp_${_}") . q{: }
+        . qq{$source t/header_pp.inc\n\t}
+        . q{$(NOECHO) $(ABSPERLRUN) "-MExtUtils::Command" -e cat t/header_pp.inc }
+        . $source . q{ > $@} . qq{\n}
+    } @test_files;
+    my $test_dep = $::has_compiler && (::is_maintainer() || $ENV{AUTOMATED_TESTING})
+        ? qq{pure_all :: pp_tests\n} . join qq{\n}, @pp_test_targets
+        : '';
+
+    return <<"EOM"
+pp_tests: ${pp_tests}
+
+${test_dep}
+
+EOM
+}