WHATSNEW: Start release notes for Samba 3.6.15.
[Samba.git] / selftest / filter-subunit
blob5f062d12a29e22d5c8d830d78000b8443faf40be
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
6 import optparse
7 import os
8 import sys
9 import signal
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"))
14 import subunithelper
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 parser.add_option("--prefix", type="string",
25 help="Add prefix to all test names")
26 parser.add_option("--fail-on-empty", default=False,
27 action="store_true", help="Fail if there was no subunit output")
28 parser.add_option("--list", default=False,
29 action="store_true", help="Operate in list mode")
30 opts, args = parser.parse_args()
32 if opts.list:
33 prefix = opts.prefix
34 if not prefix:
35 prefix = ""
36 for l in sys.stdin:
37 sys.stdout.write("%s%s\n" % (prefix, l.rstrip()))
38 sys.exit(0)
40 if opts.expected_failures:
41 expected_failures = subunithelper.read_test_regexes(opts.expected_failures)
42 else:
43 expected_failures = {}
45 statistics = {
46 'TESTS_UNEXPECTED_OK': 0,
47 'TESTS_EXPECTED_OK': 0,
48 'TESTS_UNEXPECTED_FAIL': 0,
49 'TESTS_EXPECTED_FAIL': 0,
50 'TESTS_ERROR': 0,
51 'TESTS_SKIP': 0,
54 def handle_sigint(sig, stack):
55 sys.exit(0)
56 signal.signal(signal.SIGINT, handle_sigint)
58 out = subunithelper.SubunitOps(sys.stdout)
59 msg_ops = subunithelper.FilterOps(out, opts.prefix, expected_failures,
60 opts.strip_passed_output,
61 fail_immediately=opts.fail_immediately)
63 try:
64 ret = subunithelper.parse_results(msg_ops, statistics, sys.stdin)
65 except subunithelper.ImmediateFail:
66 sys.stdout.flush()
67 sys.exit(1)
69 if opts.fail_on_empty and not msg_ops.seen_output:
70 sys.exit(1)
71 else:
72 sys.exit(ret)