s4-selftest: support 'make testenv SCREEN=1'
[samba.git] / selftest / filter-subunit
1 #!/usr/bin/env python
2 # Filter a subunit stream
3 # Copyright (C) Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GNU GPL, v3 or later
5
6 import optparse
7 import os
8 import sys
9 import signal
10
11 sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../lib/subunit/python"))
12 sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../lib/testtools"))
13
14 import subunithelper
15
16 parser = optparse.OptionParser("filter-subunit [options] < instream > outstream")
17 parser.add_option("--expected-failures", type="string", 
18         help="File containing list of regexes matching tests to consider known "
19              "failures")
20 parser.add_option("--strip-passed-output", action="store_true", 
21     help="Whether to strip output from tests that passed")
22 parser.add_option("--fail-immediately", action="store_true", 
23     help="Whether to stop on the first error", default=False)
24
25 parser.add_option("--prefix", type="string",
26         help="Add prefix to all test names")
27
28 opts, args = parser.parse_args()
29
30 if opts.expected_failures:
31         expected_failures = subunithelper.read_test_regexes(opts.expected_failures)
32 else:
33         expected_failures = {}
34
35 statistics = {
36         'TESTS_UNEXPECTED_OK': 0,
37         'TESTS_EXPECTED_OK': 0,
38         'TESTS_UNEXPECTED_FAIL': 0,
39         'TESTS_EXPECTED_FAIL': 0,
40         'TESTS_ERROR': 0,
41         'TESTS_SKIP': 0,
42 }
43
44 def handle_sigint(sig, stack):
45         sys.exit(0)
46 signal.signal(signal.SIGINT, handle_sigint)
47
48 out = subunithelper.SubunitOps(sys.stdout)
49 msg_ops = subunithelper.FilterOps(out, opts.prefix, expected_failures,
50                                   opts.strip_passed_output,
51                                   fail_immediately=opts.fail_immediately)
52
53 try:
54         sys.exit(subunithelper.parse_results(msg_ops, statistics, sys.stdin))
55 except subunithelper.ImmediateFail:
56         sys.stdout.flush()
57         sys.exit(1)