]>
Commit | Line | Data |
---|---|---|
9df43317 PB |
1 | #! /usr/bin/env perl |
2 | # Copyright (C) 2018 Red Hat, Inc. | |
3 | # | |
4 | # Author: Paolo Bonzini <pbonzini@redhat.com> | |
5 | # | |
6 | # This program is free software; you can redistribute it and/or modify | |
7 | # it under the terms of the GNU General Public License as published by | |
8 | # the Free Software Foundation; either version 2, or (at your option) | |
9 | # any later version. | |
10 | # | |
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | |
18 | ||
19 | # ---------------------------------- # | |
20 | # Imports, static data, and setup. # | |
21 | # ---------------------------------- # | |
22 | ||
23 | use warnings FATAL => 'all'; | |
24 | use strict; | |
25 | use Getopt::Long (); | |
26 | use TAP::Parser; | |
27 | ||
28 | my $ME = "tap-merge.pl"; | |
29 | my $VERSION = "2018-11-30"; | |
30 | ||
31 | my $HELP = "$ME: merge multiple TAP inputs from stdin."; | |
32 | ||
33 | use constant DIAG_STRING => "#"; | |
34 | ||
35 | # ----------------- # | |
36 | # Option parsing. # | |
37 | # ----------------- # | |
38 | ||
39 | Getopt::Long::GetOptions | |
40 | ( | |
41 | 'help' => sub { print $HELP; exit 0; }, | |
42 | 'version' => sub { print "$ME $VERSION\n"; exit 0; }, | |
43 | ); | |
44 | ||
45 | # -------------- # | |
46 | # Subroutines. # | |
47 | # -------------- # | |
48 | ||
49 | sub main () | |
50 | { | |
51 | my $iterator = TAP::Parser::Iterator::Stream->new(\*STDIN); | |
52 | my $parser = TAP::Parser->new ({iterator => $iterator }); | |
53 | my $testno = 0; # Number of test results seen so far. | |
54 | my $bailed_out = 0; # Whether a "Bail out!" directive has been seen. | |
55 | ||
2a11ee10 | 56 | STDOUT->autoflush(1); |
9df43317 PB |
57 | while (defined (my $cur = $parser->next)) |
58 | { | |
59 | if ($cur->is_bailout) | |
60 | { | |
61 | $bailed_out = 1; | |
62 | print DIAG_STRING . " " . $cur->as_string . "\n"; | |
63 | next; | |
64 | } | |
65 | elsif ($cur->is_plan) | |
66 | { | |
67 | $bailed_out = 0; | |
68 | next; | |
69 | } | |
70 | elsif ($cur->is_test) | |
71 | { | |
72 | $bailed_out = 0 if $cur->number == 1; | |
73 | $testno++; | |
74 | $cur = TAP::Parser::Result::Test->new({ | |
75 | ok => $cur->ok, | |
76 | test_num => $testno, | |
77 | directive => $cur->directive, | |
78 | explanation => $cur->explanation, | |
79 | description => $cur->description | |
80 | }); | |
81 | } | |
82 | elsif ($cur->is_version) | |
83 | { | |
84 | next if $testno > 0; | |
85 | } | |
86 | print $cur->as_string . "\n" unless $bailed_out; | |
87 | } | |
88 | print "1..$testno\n"; | |
89 | } | |
90 | ||
91 | # ----------- # | |
92 | # Main code. # | |
93 | # ----------- # | |
94 | ||
95 | main; | |
96 | ||
97 | # Local Variables: | |
98 | # perl-indent-level: 2 | |
99 | # perl-continued-statement-offset: 2 | |
100 | # perl-continued-brace-offset: 0 | |
101 | # perl-brace-offset: 0 | |
102 | # perl-brace-imaginary-offset: 0 | |
103 | # perl-label-offset: -2 | |
104 | # cperl-indent-level: 2 | |
105 | # cperl-brace-offset: 0 | |
106 | # cperl-continued-brace-offset: 0 | |
107 | # cperl-label-offset: -2 | |
108 | # cperl-extra-newline-before-brace: t | |
109 | # cperl-merge-trailing-else: nil | |
110 | # cperl-continued-statement-offset: 2 | |
111 | # End: |