Debian Codegraph @

debian/tap-todo

raw
1 #!/usr/bin/perl
2
3 use v5.10;
4 use utf8;
5 use strict;
6 use warnings;
7 use re 'taint';
8
9 use TAP::Parser;
10
11 =head1 NAME
12
13 tap-todo - TAP filter to tolerate select failures
14
15 =head1 VERSION
16
17 Version v0.2.3
18
19 =cut
20
21 our $VERSION = version->declare('v0.2.1');
22
23 =head1 SYNOPSIS
24
25 B<prove --lib> | B<tap-todo> "B<is a foo>" "B<does.* do bar::reason: baz.*>"
26
27 =head1 DESCRIPTION
28
29 B<tap-todo> filters the output of TAP tests
30 and flags select (otherwise) failing tests as TODO.
31
32 You feed the original TAP data via STDIN,
33 and apply skip-patterns for failing tests that should be tolerated.
34
35 Each skip-pattern is a regular expression matched against description,
36 optionally followed by "::" and
37 a regular expression for YAML data and other subsequent content.
38
39 tap-todo fails with error code 1
40 if TAP contains failing tests not caught by skip-patterns,
41 and fails with error code 1
42 if TAP contains no tests at all.
43
44 =cut
45
46 # split and compile regular expressions
47 my @skip = map {
48 my ( $desc, $more ) = split /::/;
49 my $desc_re = qr/$desc/ || die;
50 my $more_re = qr/$more/s || die if ($more);
51 { desc => $desc_re, more => $more_re }
52 } @ARGV;
53
54 open my $fh, "<&STDIN";
55 my $parser = TAP::Parser->new( { source => $fh } );
56
57 my ( $more, $seen, $todo );
58 $todo = 0;
59 while ( my $res = $parser->next ) {
60 if ( $res->is_test ) {
61 $more = undef;
62 $seen = 0;
63 unless ( $res->is_ok ) {
64 foreach ( grep { $res->description =~ $$_{desc} } @skip ) {
65 unless ( $more = $$_{more} ) {
66 $todo++;
67 print "# TODO: ";
68 }
69 last;
70 }
71 }
72 }
73 elsif ( $more and $res->as_string =~ $more ) {
74 $todo++ unless ($seen++);
75 print "# TODO: ";
76 }
77 say $res->as_string;
78 }
79 say "# skipped $todo";
80 say "# skip-patterns ", 0 + @ARGV;
81
82 unless ( $parser->tests_run ) {
83 print STDERR "ERROR: no tests run\n";
84 exit(2);
85 }
86
87 my $reallyfailed = $parser->tests_run - $parser->passed - $todo;
88 if ($reallyfailed) {
89 print STDERR "ERROR: $reallyfailed non-TODO tests failed\n";
90 exit(!!$reallyfailed);
91 }
92
93 =head1 AUTHOR
94
95 Jonas Smedegaard C<< <[email protected]> >>
96
97 =head1 COPYRIGHT AND LICENSE
98
99 Copyright © 2020 Jonas Smedegaard
100
101 Copyright © 2020 Purism SPC
102
103 This program is free software:
104 you can redistribute it and/or modify it
105 under the terms of the GNU General Public License
106 as published by the Free Software Foundation,
107 either version 3, or (at your option) any later version.
108
109 This program is distributed in the hope that it will be useful,
110 but WITHOUT ANY WARRANTY;
111 without even the implied warranty
112 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
113 See the GNU Affero General Public License for more details.
114
115 You should have received a copy
116 of the GNU General Public License along with this program.
117 If not, see <https://www.gnu.org/licenses/>.
118
119 =cut