From 1ba48229420ac28152f87d27a77d0980d79ff1a9 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 22 Dec 2014 23:26:58 -0700 Subject: spec_tests.py: make --dump-tests sensitive to --pattern, --number. Closes #249 in a slightly different way. --- test/spec_tests.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/spec_tests.py b/test/spec_tests.py index 23f45a0..5a9f278 100755 --- a/test/spec_tests.py +++ b/test/spec_tests.py @@ -112,17 +112,13 @@ def get_tests(specfile): html_lines.append(line) return tests -def do_tests(cmark, tests, pattern, normalize, number): +def do_tests(cmark, tests, pattern_re, normalize, number): result_counts = dict.fromkeys(['pass', 'error', 'fail', 'skip'], 0) if number: test = tests[number - 1] do_test(test, normalize, result_counts) result_counts['skip'] = len(tests) - 1 else: - if pattern: - pattern_re = re.compile(pattern, re.IGNORECASE) - else: - pattern_re = re.compile('.') for test in tests: if re.search(pattern_re, test['section']): do_test(test, normalize, result_counts) @@ -137,12 +133,17 @@ if __name__ == "__main__": exit(0) tests = get_tests(args.spec) + if args.pattern: + pattern_re = re.compile(args.pattern, re.IGNORECASE) + else: + pattern_re = re.compile('.') if args.dump_tests: - print json.dumps(tests, ensure_ascii=False, indent=2) + tests_to_dump = [ test for test in tests if re.search(pattern_re, test['section']) and (not args.number or test['example'] == args.number) ] + print json.dumps(tests_to_dump, ensure_ascii=False, indent=2) exit(0) else: cmark = CMark(prog=args.program, library_dir=args.library_dir) - if do_tests(cmark, tests, args.pattern, args.normalize, args.number): + if do_tests(cmark, tests, pattern_re, args.normalize, args.number): exit(0) else: exit(1) -- cgit v1.2.3