Commit | Line | Data |
f207111d |
1 | package TAP::Harness::IgnoreNonessentialDzilAutogeneratedTests; |
2 | |
3 | use warnings; |
4 | use strict; |
5 | |
6 | use base 'TAP::Harness'; |
1e735709 |
7 | use File::Spec (); |
8 | use IPC::Open3 'open3'; |
9 | use File::Temp (); |
a62f6970 |
10 | use List::Util 'first'; |
f207111d |
11 | |
12 | my $frivolous_test_map = { |
13 | # Test based on the extremely dep-heavy, *prone to failures* Test::CheckDeps |
14 | # |
a62f6970 |
15 | qr|^t/00-check-deps.t$| => [ |
f207111d |
16 | qr|^\Q# this test was generated with Dist::Zilla::Plugin::Test::CheckDeps|m, |
17 | |
18 | # older non-annotated versions |
19 | qr|use \s+ Test::CheckDeps .*? ^\Qcheck_dependencies('suggests')\E .*? \QBAIL_OUT("Missing dependencies") if !Test::More->builder->is_passing|smx, |
20 | ], |
21 | |
22 | # "does everything compile" tests are useless by definition - this is what the |
23 | # rest of the test suite is for |
24 | # |
a62f6970 |
25 | qr|^t/00-compile.t$| => [ |
f207111d |
26 | qr|^\Q# this test was generated with Dist::Zilla::Plugin::Test::Compile|m, |
27 | ], |
a62f6970 |
28 | |
29 | # The report prereq test managed to become fatal as well |
30 | # |
31 | qr|^t/00-report-prereqs.t$| => [ |
32 | qr|^\Q# This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs|m, |
33 | ], |
34 | |
35 | # Just future-proof the thing, catch anything autogened by dzil for a bit |
36 | qr|^t/00-| => [ |
37 | qr|^\Q# This test was generated by Dist::Zilla::|m, |
38 | ] |
f207111d |
39 | }; |
40 | |
41 | sub aggregate_tests { |
42 | my ($self, $aggregate, @all_tests) = @_; |
43 | |
44 | my ($run_tests, $skip_tests); |
45 | |
46 | TESTFILE: |
47 | for (@all_tests) { |
48 | my $fn = File::Spec::Unix->catpath( File::Spec->splitpath( $_ ) ); |
49 | |
a62f6970 |
50 | if (my $REs = $frivolous_test_map->{ |
51 | (first { $fn =~ $_ } keys %$frivolous_test_map ) || '' |
52 | }) { |
f207111d |
53 | my $slurptest = do { local (@ARGV, $/) = $fn; <> }; |
54 | $slurptest =~ $_ and push @$skip_tests, $fn and next TESTFILE for @$REs; |
55 | } |
56 | |
57 | push @$run_tests, $fn; |
58 | } |
59 | |
60 | if ($skip_tests) { |
61 | |
1e735709 |
62 | for my $tfn (@$skip_tests) { |
f207111d |
63 | |
1e735709 |
64 | (my $tfn_flattened = $tfn) =~ s|/|_|g; |
65 | |
66 | my $log_file = File::Temp->new( |
67 | DIR => '/tmp', |
68 | TEMPLATE => "AutoGenTest_${tfn_flattened}_XXXXX", |
69 | SUFFIX => '.txt', |
70 | ); |
71 | |
72 | # FIXME I have no idea why the fileno dance is necessary - will investigate later |
73 | # All I know is that if I pass in just $log_file - open3 ignores it >:( |
74 | my $pid = open3(undef, '>&'.fileno($log_file), undef, $^X, qw(-I blib -I arch/lib), $tfn ); |
f207111d |
75 | waitpid ($pid, 0); |
1e735709 |
76 | my $ex = $?; |
77 | |
78 | if ($ex) { |
79 | # use qx as opposed to another open3 until I figure out the above |
80 | close $log_file or die "Unable to close $log_file: $!"; |
81 | chomp( my $url = `/usr/bin/nopaste -q -s Shadowcat -d $log_file < $log_file` ); |
f207111d |
82 | |
1e735709 |
83 | $tfn .= "[would NOT have passed: $ex / $url]"; |
84 | } |
f207111d |
85 | } |
86 | |
87 | print STDERR "=== Skipping nonessential autogenerated tests: @$skip_tests\n"; |
88 | } |
89 | |
90 | return $self->SUPER::aggregate_tests($aggregate, @$run_tests); |
91 | } |
92 | |
93 | 1; |