Debian Codegraph @

t/formatter.t

raw
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use if $ENV{AUTOMATED_TESTING}, 'Test::DiagINC'; use Test::More;
6 use Test::XML;
7 use File::Slurp qw(slurp);
8 use TAP::Harness;
9 use IO::Scalar;
10 use version;
11
12 ###############################################################################
13 # Figure out how many tests we have to run.
14 #
15 # *MANY* thanks Andy Armstrong et al. for the fabulous set of tests in
16 # Test::Harness. :)
17 my @tests = grep { -f $_ } <t/data/tests/*>;
18 plan tests => scalar(@tests);
19
20 ###############################################################################
21 # Run each of the tests in turn, and compare the output to the expected JUnit
22 # output.
23 foreach my $test (@tests) {
24 # Where is the JUnit output we should be expecting?
25 (my $junit = $test) =~ s{/tests/}{/tests/junit/};
26
27 # Process TAP, and turn it into JUnit
28 my $received = '';
29 my $fh = IO::Scalar->new(\$received);
30 eval {
31 my $harness = TAP::Harness->new( {
32 stdout => $fh,
33 merge => 1,
34 formatter_class => 'TAP::Formatter::JUnit',
35 } );
36 $harness->runtests($test);
37 };
38
39 my $expected = slurp($junit);
40
41 # OVER-RIDE: With Test::Harness prior to v3.43, the "bailout" test would
42 # result in zero/no output. This was fixed in Test::Harness v3.43_0*
43 # development releases, but WE need to watch for and provide accommodations
44 # for newer/older versions.
45 unless (version->parse($TAP::Harness::VERSION) > version->parse(3.43)) {
46 if ($test =~ /bailout/) {
47 $expected = '';
48 }
49 }
50
51 # Skip this test if it is a bailout test, and we have a broken version of
52 # Test::Harness
53 SKIP: {
54 # Should we be skipping "bailout" tests, because of a broken
55 # Test::Harness?
56 #
57 # A handful of Test::Harness releases contained a bug which resulted in
58 # a double-summary being output on BAIL_OUT, and which affect our
59 # expected test output.
60 my $SKIP_BAILOUT = 0;
61 {
62 my $v_harness = version->parse($TAP::Harness::VERSION);
63 my $v_broken_at = version->parse("3.45_01");
64 my $v_fixed_at = version->parse("3.50");
65 $SKIP_BAILOUT = 1 if (
66 ($v_harness >= $v_broken_at)
67 &&
68 ($v_harness < $v_fixed_at)
69 );
70 }
71 skip "Broken Test::Harness installed; skipping BAIL_OUT test", 1 if ($SKIP_BAILOUT && ($test =~ /bailout/));
72
73 # Compare results (bearing in mind that some tests produce zero output, and
74 # thus cannot be parsed as XML)
75 if ($received || $expected) {
76 is_xml $received, $expected, $test
77 or diag "GOT: ", explain($received);
78 }
79 else {
80 is $received, $expected, $test
81 or diag "GOT: ", explain($received);
82 }
83 }
84 }