File: IgnoreNonessentialDzilAutogeneratedTests.pm

package info (click to toggle)
libdbix-class-schema-loader-perl 0.07053-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,464 kB
  • sloc: perl: 11,520; sh: 544; makefile: 4
file content (93 lines) | stat: -rw-r--r-- 2,709 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package TAP::Harness::IgnoreNonessentialDzilAutogeneratedTests;

use warnings;
use strict;

use base 'TAP::Harness';
use File::Spec ();
use IPC::Open3 'open3';
use File::Temp ();
use List::Util 'first';

my $frivolous_test_map = {
# Test based on the extremely dep-heavy, *prone to failures* Test::CheckDeps
#
  qr|^t/00-check-deps.t$| => [
    qr|^\Q# this test was generated with Dist::Zilla::Plugin::Test::CheckDeps|m,

    # older non-annotated versions
    qr|use \s+ Test::CheckDeps .*? ^\Qcheck_dependencies('suggests')\E .*? \QBAIL_OUT("Missing dependencies") if !Test::More->builder->is_passing|smx,
  ],

# "does everything compile" tests are useless by definition - this is what the
# rest of the test suite is for
#
  qr|^t/00-compile.t$| => [
    qr|^\Q# this test was generated with Dist::Zilla::Plugin::Test::Compile|m,
  ],

# The report prereq test managed to become fatal as well
#
  qr|^t/00-report-prereqs.t$| => [
    qr|^\Q# This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs|m,
  ],

# Just future-proof the thing, catch anything autogened by dzil for a bit
  qr|^t/00-| => [
    qr|^\Q# This test was generated by Dist::Zilla::|m,
  ]
};

sub aggregate_tests {
  my ($self, $aggregate, @all_tests) = @_;

  my ($run_tests, $skip_tests);

  TESTFILE:
  for (@all_tests) {
    my $fn = File::Spec::Unix->catpath( File::Spec->splitpath( $_ ) );

    if (my $REs = $frivolous_test_map->{
      (first { $fn =~ $_ } keys %$frivolous_test_map ) || ''
    }) {
      my $slurptest = do { local (@ARGV, $/) = $fn; <> };
      $slurptest =~ $_ and push @$skip_tests, $fn and next TESTFILE for @$REs;
    }

    push @$run_tests, $fn;
  }

  if ($skip_tests) {

    for my $tfn (@$skip_tests) {

      (my $tfn_flattened = $tfn) =~ s|/|_|g;

      my $log_file = File::Temp->new(
        DIR => '/tmp',
        TEMPLATE => "AutoGenTest_${tfn_flattened}_XXXXX",
        SUFFIX => '.txt',
      );

      # FIXME I have no idea why the fileno dance is necessary - will investigate later
      # All I know is that if I pass in just $log_file - open3 ignores it >:(
      my $pid = open3(undef, '>&'.fileno($log_file), undef, $^X, qw(-I blib -I arch/lib), $tfn );
      waitpid ($pid, 0);
      my $ex = $?;

      if ($ex) {
        # use qx as opposed to another open3 until I figure out the above
        close $log_file or die "Unable to close $log_file: $!";
        chomp( my $url = `/usr/bin/nopaste -q -s Shadowcat -d $log_file < $log_file` );

        $tfn .= "[would NOT have passed: $ex / $url]";
      }
    }

    print STDERR "=== Skipping nonessential autogenerated tests: @$skip_tests\n";
  }

  return $self->SUPER::aggregate_tests($aggregate, @$run_tests);
}

1;