s3: krb5: keytab - The done label can be jumped to with context == NULL.
[Samba.git] / selftest / filter-subunit
blob4f95546794a64a07cf78631fe6724757e7d78c20
1 #!/usr/bin/env python
2 # Filter a subunit stream
3 # Copyright (C) 2009-2011 Jelmer Vernooij <jelmer@samba.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # NOTE: This script is a hack, meant as a placeholder until we can migrate
19 # to upstream subunit's filtering tools.
21 import optparse
22 import sys
23 import signal
25 sys.path.insert(0, "bin/python")
26 import samba
27 samba.ensure_external_module("mimeparse", "mimeparse")
28 samba.ensure_external_module("extras", "extras")
29 samba.ensure_external_module("testtools", "testtools")
30 samba.ensure_external_module("subunit", "subunit/python")
32 import subunithelper
34 parser = optparse.OptionParser("filter-subunit [options] < instream > outstream")
35 parser.add_option("--expected-failures", type="string",
36 help="File containing list of regexes matching tests to consider known "
37 "failures")
38 parser.add_option("--flapping", type="string",
39 help="File containing list of flapping tests, of which to ignore results.")
40 parser.add_option("--strip-passed-output", action="store_true",
41 help="Whether to strip output from tests that passed")
42 parser.add_option("--fail-immediately", action="store_true",
43 help="Whether to stop on the first error", default=False)
44 parser.add_option("--prefix", type="string",
45 help="Add prefix to all test names")
46 parser.add_option("--suffix", type="string",
47 help="Add suffix to all test names")
48 parser.add_option("--fail-on-empty", default=False,
49 action="store_true", help="Fail if there was no subunit output")
50 parser.add_option("--list", default=False,
51 action="store_true", help="Operate in list mode")
52 opts, args = parser.parse_args()
54 if opts.list:
55 prefix = opts.prefix
56 suffix = opts.suffix
57 if not prefix:
58 prefix = ""
59 if not suffix:
60 suffix = ""
61 for l in sys.stdin:
62 sys.stdout.write("%s%s%s\n" % (prefix, l.rstrip(), suffix))
63 sys.exit(0)
65 if opts.expected_failures:
66 expected_failures = subunithelper.read_test_regexes(opts.expected_failures)
67 else:
68 expected_failures = {}
71 if opts.flapping:
72 flapping = subunithelper.read_test_regexes(opts.flapping)
73 else:
74 flapping = {}
76 statistics = {
77 'TESTS_UNEXPECTED_OK': 0,
78 'TESTS_EXPECTED_OK': 0,
79 'TESTS_UNEXPECTED_FAIL': 0,
80 'TESTS_EXPECTED_FAIL': 0,
81 'TESTS_ERROR': 0,
82 'TESTS_SKIP': 0,
85 def handle_sigint(sig, stack):
86 sys.exit(0)
87 signal.signal(signal.SIGINT, handle_sigint)
89 out = subunithelper.SubunitOps(sys.stdout)
90 msg_ops = subunithelper.FilterOps(out, opts.prefix, opts.suffix, expected_failures,
91 opts.strip_passed_output,
92 fail_immediately=opts.fail_immediately,
93 flapping=flapping)
95 try:
96 ret = subunithelper.parse_results(msg_ops, statistics, sys.stdin)
97 except subunithelper.ImmediateFail:
98 sys.stdout.flush()
99 sys.exit(1)
101 if opts.fail_on_empty and not msg_ops.seen_output:
102 sys.exit(1)
103 else:
104 sys.exit(ret)