2010-03-30 14:46:26 +04:00
#!/usr/bin/env python
# Filter a subunit stream
# Copyright (C) Jelmer Vernooij <jelmer@samba.org>
# Published under the GNU GPL, v3 or later
import optparse
2010-03-31 06:51:05 +04:00
import os
2010-03-30 14:46:26 +04:00
import sys
import signal
2010-03-31 06:51:05 +04:00
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../lib/subunit/python"))
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../lib/testtools"))
2010-03-31 06:52:13 +04:00
import subunithelper
2010-03-30 14:46:26 +04:00
parser = optparse.OptionParser("filter-subunit [options] < instream > outstream")
parser.add_option("--expected-failures", type="string",
help="File containing list of regexes matching tests to consider known "
"failures")
parser.add_option("--strip-passed-output", action="store_true",
help="Whether to strip output from tests that passed")
2010-09-27 05:56:50 +04:00
parser.add_option("--fail-immediately", action="store_true",
help="Whether to stop on the first error", default=False)
2010-03-30 14:46:26 +04:00
parser.add_option("--prefix", type="string",
help="Add prefix to all test names")
2010-11-03 18:30:40 +03:00
parser.add_option("--fail-on-empty", default=False,
action="store_true", help="Fail if there was no subunit output")
2010-03-30 14:46:26 +04:00
opts, args = parser.parse_args()
if opts.expected_failures:
2010-04-06 05:55:10 +04:00
expected_failures = subunithelper.read_test_regexes(opts.expected_failures)
2010-03-30 14:46:26 +04:00
else:
2010-04-06 05:55:10 +04:00
expected_failures = {}
2010-03-30 14:46:26 +04:00
statistics = {
'TESTS_UNEXPECTED_OK': 0,
'TESTS_EXPECTED_OK': 0,
'TESTS_UNEXPECTED_FAIL': 0,
'TESTS_EXPECTED_FAIL': 0,
'TESTS_ERROR': 0,
'TESTS_SKIP': 0,
}
def handle_sigint(sig, stack):
sys.exit(0)
signal.signal(signal.SIGINT, handle_sigint)
2010-09-13 23:17:05 +04:00
out = subunithelper.SubunitOps(sys.stdout)
msg_ops = subunithelper.FilterOps(out, opts.prefix, expected_failures,
2010-09-27 05:56:50 +04:00
opts.strip_passed_output,
fail_immediately=opts.fail_immediately)
2010-03-30 14:46:26 +04:00
2010-09-28 09:10:43 +04:00
try:
2010-11-03 18:30:40 +03:00
ret = subunithelper.parse_results(msg_ops, statistics, sys.stdin)
2010-09-28 09:10:43 +04:00
except subunithelper.ImmediateFail:
2010-09-28 09:40:27 +04:00
sys.stdout.flush()
2010-09-28 09:10:43 +04:00
sys.exit(1)
2010-11-03 18:30:40 +03:00
if opts.fail_on_empty and not msg_ops.seen_output:
sys.exit(1)
else:
sys.exit(ret)