help="exclude skips", dest="skip")
parser.add_option("--no-success", action="store_true",
help="exclude successes", default=True, dest="success")
-parser.add_option("-m", "--match", type=str,
- help="regexp to include (case-sensitive by default)")
-parser.add_option("--anti-match", type=str,
- help="regexp to exclude (case-sensitive by default)")
+parser.add_option("-m", "--with", type=str,
+ help="regexp to include (case-sensitive by default)",
+ action="append", dest="with_regexps")
+parser.add_option("--without", type=str,
+ help="regexp to exclude (case-sensitive by default)",
+ action="append", dest="without_regexps")
(options, args) = parser.parse_args()
-def make_re_matcher(needle_re_string):
- needle_re = re.compile(needle_re_string, re.MULTILINE)
- return lambda test, err: (
- needle_re.search(str(test)) or
- ((err is not None) and needle_re.search(str(err))))
-if options.match:
- match_predicate = make_re_matcher(options.match)
-else:
- match_predicate = lambda test, err: True
+def _compile_re_from_list(l):
+ return re.compile("|".join(l), re.MULTILINE)
-if options.anti_match:
- anti_match_predicate = make_re_matcher(options.anti_match)
-else:
- anti_match_predicate = lambda test, err: False
-filter_predicate = lambda test, err: (
- match_predicate(test, err) and not anti_match_predicate(test, err))
+def check_regexps(test, err):
+ """Check if this test and error match the regexp filters."""
+ test_str = str(test)
+ err_str = err and str(err) # may be None
+ if options.with_regexps:
+ with_re = _compile_re_from_list(options.with_regexps)
+ if not (with_re.search(test_str)
+ or with_re.search(err_str)):
+ return False
+ if options.without_regexps:
+ without_re = _compile_re_from_list(options.without_regexps)
+ if (without_re.search(test_str) or without_re.search(err_str)):
+ return False
+ return True
+
result = TestProtocolClient(sys.stdout)
result = TestResultFilter(result, filter_error=options.error,
filter_failure=options.failure, filter_success=options.success,
filter_skip=options.skip,
- filter_predicate=filter_predicate)
+ filter_predicate=check_regexps)
if options.no_passthrough:
passthrough_stream = DiscardStream()
else: