From e92962ff1ede3651597afe641da0b1aa3ca48c3a Mon Sep 17 00:00:00 2001 From: Steve Fink Date: Tue, 31 Jan 2017 17:16:04 -0800 Subject: [PATCH] Bug 1335592 - Implement jstests.py --include and --exclude options for including and excluding files or directories, r=fitzgen MozReview-Commit-ID: FQ3fVFU4yf9 --HG-- extra : rebase_source : 1f1399f14fa500ff57375c9623f53afbea32adce --- js/src/tests/jstests.py | 9 +++++++-- js/src/tests/lib/manifest.py | 29 +++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/js/src/tests/jstests.py b/js/src/tests/jstests.py index 6cd92a5e014b..a00c88a6915c 100755 --- a/js/src/tests/jstests.py +++ b/js/src/tests/jstests.py @@ -105,6 +105,10 @@ def parse_args(): help='Get tests from the given file.') input_og.add_option('-x', '--exclude-file', action='append', help='Exclude tests from the given file.') + input_og.add_option('--include', action='append', dest='requested_paths', default=[], + help='Include the given test file or directory.') + input_og.add_option('--exclude', action='append', dest='excluded_paths', default=[], + help='Exclude the given test file or directory.') input_og.add_option('-d', '--exclude-random', dest='random', action='store_false', help='Exclude tests marked as "random."') @@ -160,7 +164,7 @@ def parse_args(): # Acquire the JS shell given on the command line. options.js_shell = None - requested_paths = set() + requested_paths = set(options.requested_paths) if len(args) > 0: options.js_shell = abspath(args[0]) requested_paths |= set(args[1:]) @@ -209,9 +213,10 @@ def parse_args(): requested_paths |= set( [line.strip() for line in open(test_file).readlines()]) + excluded_paths = set(options.excluded_paths) + # If files with lists of tests to exclude were specified, add them to the # excluded tests set. - excluded_paths = set() if options.exclude_file: for filename in options.exclude_file: try: diff --git a/js/src/tests/lib/manifest.py b/js/src/tests/lib/manifest.py index 7079a186f6da..43d2504f3df0 100644 --- a/js/src/tests/lib/manifest.py +++ b/js/src/tests/lib/manifest.py @@ -328,7 +328,7 @@ def _apply_external_manifests(filename, testcase, entries, xul_tester): _parse_one(testcase, xul_tester) def _is_test_file(path_from_root, basename, filename, requested_paths, - excluded_paths): + excluded_files, excluded_dirs): # Any file whose basename matches something in this set is ignored. EXCLUDED = set(('browser.js', 'shell.js', 'template.js', 'user.js', 'sta.js', @@ -351,17 +351,36 @@ def _is_test_file(path_from_root, basename, filename, requested_paths, return False # Skip excluded tests. - if filename in excluded_paths: + if filename in excluded_files: return False + for dir in excluded_dirs: + if filename.startswith(dir + '/'): + return False return True +def _split_files_and_dirs(location, paths): + """Split up a set of paths into files and directories""" + files, dirs = set(), set() + for path in paths: + fullpath = os.path.join(location, path) + if path.endswith('/'): + dirs.add(path[0:-1]) + elif os.path.isdir(fullpath): + dirs.add(path) + elif os.path.exists(fullpath) + files.add(path) + + return files, dirs + + def count_tests(location, requested_paths, excluded_paths): count = 0 + excluded_files, excluded_dirs = _split_files_and_dirs(location, excluded_paths) for root, basename in _find_all_js_files(location, location): filename = os.path.join(root, basename) - if _is_test_file(root, basename, filename, requested_paths, excluded_paths): + if _is_test_file(root, basename, filename, requested_paths, excluded_files, excluded_dirs): count += 1 return count @@ -378,10 +397,12 @@ def load_reftests(location, requested_paths, excluded_paths, xul_tester, reldir= manifestFile = os.path.join(location, 'jstests.list') externalManifestEntries = _parse_external_manifest(manifestFile, '') + excluded_files, excluded_dirs = _split_files_and_dirs(location, excluded_paths) + for root, basename in _find_all_js_files(location, location): # Get the full path and relative location of the file. filename = os.path.join(root, basename) - if not _is_test_file(root, basename, filename, requested_paths, excluded_paths): + if not _is_test_file(root, basename, filename, requested_paths, excluded_files, excluded_dirs): continue # Skip empty files.