selftest: Use external processes for filtering known failures and pretty
[ira/wip.git] / selftest / format-subunit.pl
1 #!/usr/bin/perl
2 # Pretty-format subunit output
3 # Copyright (C) Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GNU GPL, v3 or later
5
6 =pod
7
8 =head1 NAME
9
10 format-subunit [--format=<NAME>] [--immediate] < instream > outstream
11
12 =head1 SYNOPSIS
13
14 Format the output of a subunit stream.
15
16 =head1 OPTIONS
17
18 =over 4
19
20 =item I<--immediate>
21
22 Show errors as soon as they happen rather than at the end of the test run.
23
24 =item I<--format>=FORMAT
25
26 Choose the format to print. Currently supported are plain, html or buildfarm.
27
28 =head1 LICENSE
29
30 GNU General Public License, version 3 or later.
31
32 =head1 AUTHOR
33
34 Jelmer Vernooij <jelmer@samba.org>
35                 
36 =cut
37
38 use Getopt::Long;
39 use strict;
40 use FindBin qw($RealBin $Script);
41 use lib "$RealBin";
42 use Subunit qw(parse_results);
43
44 my $opt_format = "plain";
45 my $opt_help = undef;
46 my $opt_verbose = 0;
47 my $opt_immediate = 0;
48 my $opt_prefix = ".";
49
50 my $result = GetOptions (
51                 'help|h|?' => \$opt_help,
52                 'format=s' => \$opt_format,
53                 'verbose' => \$opt_verbose,
54                 'immediate' => \$opt_immediate,
55                 'prefix:s' => \$opt_prefix,
56             );
57
58 exit(1) if (not $result);
59
60 if (defined($ENV{RUN_FROM_BUILD_FARM}) and 
61         ($ENV{RUN_FROM_BUILD_FARM} eq "yes")) {
62         $opt_format = "buildfarm";
63 }
64
65 my $msg_ops;
66
67 my $statistics = {
68         SUITES_FAIL => 0,
69
70         TESTS_UNEXPECTED_OK => 0,
71         TESTS_EXPECTED_OK => 0,
72         TESTS_UNEXPECTED_FAIL => 0,
73         TESTS_EXPECTED_FAIL => 0,
74         TESTS_ERROR => 0,
75         TESTS_SKIP => 0,
76 };
77
78 if ($opt_format eq "buildfarm") {
79         require output::buildfarm;
80         $msg_ops = new output::buildfarm($statistics);
81 } elsif ($opt_format eq "plain") {
82         require output::plain;
83         $msg_ops = new output::plain("$opt_prefix/summary", $opt_verbose, $opt_immediate, $statistics, undef);
84 } elsif ($opt_format eq "html") {
85         require output::html;
86         mkdir("test-results", 0777);
87         $msg_ops = new output::html("test-results", $statistics);
88 } elsif ($opt_format eq "subunit") {
89         require output::subunit;
90         $msg_ops = new output::subunit();
91 } else {
92         die("Invalid output format '$opt_format'");
93 }
94
95 my $expected_ret = parse_results($msg_ops, $statistics, *STDIN, []);
96
97 $msg_ops->summary();
98
99 exit($expected_ret);