def load(location, requested_paths, excluded_paths, xul_tester, reldir=''): """ Locates all tests by walking the filesystem starting at |location|. Uses xul_tester to evaluate any test conditions in the test header. Failure type and comment for a test case can come from - an external manifest entry for the test case, - an external manifest entry for a containing directory, - most commonly: the header of the test case itself. """ manifestFile = os.path.join(location, 'jstests.list') externalManifestEntries = _parse_external_manifest(manifestFile, '') 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): continue # Skip empty files. fullpath = os.path.join(location, filename) statbuf = os.stat(fullpath) testcase = TestCase(os.path.join(reldir, filename)) _apply_external_manifests(filename, testcase, externalManifestEntries, xul_tester) _parse_test_header(fullpath, testcase, xul_tester) yield testcase
def load(location, requested_paths, excluded_paths, xul_tester, reldir=''): """ Locates all tests by walking the filesystem starting at |location|. Uses xul_tester to evaluate any test conditions in the test header. Failure type and comment for a test case can come from - an external manifest entry for the test case, - an external manifest entry for a containing directory, - most commonly: the header of the test case itself. """ # The list of tests that we are collecting. tests = [] # Any file whose basename matches something in this set is ignored. EXCLUDED = set( ('browser.js', 'shell.js', 'jsref.js', 'template.js', 'user.js', 'sta.js', 'test262-browser.js', 'test262-shell.js', 'test402-browser.js', 'test402-shell.js', 'testBuiltInObject.js', 'testIntl.js', 'js-test-driver-begin.js', 'js-test-driver-end.js')) manifestFile = os.path.join(location, 'jstests.list') externalManifestEntries = _parse_external_manifest(manifestFile, '') for root, basename in _find_all_js_files(location, location): # Skip js files in the root test directory. if not root: continue # Skip files that we know are not tests. if basename in EXCLUDED: continue # Get the full path and relative location of the file. filename = os.path.join(root, basename) fullpath = os.path.join(location, filename) # If any tests are requested by name, skip tests that do not match. if requested_paths \ and not any(req in filename for req in requested_paths): continue # Skip excluded tests. if filename in excluded_paths: continue # Skip empty files. statbuf = os.stat(fullpath) if statbuf.st_size == 0: continue testcase = TestCase(os.path.join(reldir, filename)) _apply_external_manifests(filename, testcase, externalManifestEntries, xul_tester) _parse_test_header(fullpath, testcase, xul_tester) tests.append(testcase) return tests
def load(location, xul_tester, reldir=''): """ Locates all tests by walking the filesystem starting at |location|. Uses xul_tester to evaluate any test conditions in the test header. """ # The list of tests that we are collecting. tests = [] # Any file who's basename matches something in this set is ignored. EXCLUDED = set( ('browser.js', 'shell.js', 'jsref.js', 'template.js', 'user.js', 'js-test-driver-begin.js', 'js-test-driver-end.js')) for root, basename in _find_all_js_files(location, location): # Skip js files in the root test directory. if not root: continue # Skip files that we know are not tests. if basename in EXCLUDED: continue # Get the full path and relative location of the file. filename = os.path.join(root, basename) fullpath = os.path.join(location, filename) # Skip empty files. statbuf = os.stat(fullpath) if statbuf.st_size == 0: continue # Parse the test header and load the test. testcase = TestCase(os.path.join(reldir, filename), enable=True, expect=True, random=False, slow=False, debugMode=False) _parse_test_header(fullpath, testcase, xul_tester) tests.append(testcase) return tests
def parse(filename, xul_tester, reldir=''): ans = [] comment_re = re.compile(r'#.*') dir = os.path.dirname(filename) try: f = open(filename) except IOError: print "warning: include file not found: '%s'" % filename return ans for line in f: sline = comment_re.sub('', line) parts = sline.split() if len(parts) == 0: # line is empty or just a comment, skip pass elif parts[0] == 'include': include_file = parts[1] include_reldir = os.path.join(reldir, os.path.dirname(include_file)) ans += parse(os.path.join(dir, include_file), xul_tester, include_reldir) elif parts[0] == 'url-prefix': # Doesn't apply to shell tests pass else: script = None enable = True expect = True random = False slow = False debugMode = False pos = 0 while pos < len(parts): if parts[pos] == 'fails': expect = False pos += 1 elif parts[pos] == 'skip': expect = enable = False pos += 1 elif parts[pos] == 'random': random = True pos += 1 elif parts[pos].startswith('fails-if'): cond = parts[pos][len('fails-if('):-1] if xul_tester.test(cond): expect = False pos += 1 elif parts[pos].startswith('asserts-if'): # This directive means we may flunk some number of # NS_ASSERTIONs in the browser. For the shell, ignore it. pos += 1 elif parts[pos].startswith('skip-if'): cond = parts[pos][len('skip-if('):-1] if xul_tester.test(cond): expect = enable = False pos += 1 elif parts[pos].startswith('random-if'): cond = parts[pos][len('random-if('):-1] if xul_tester.test(cond): random = True pos += 1 elif parts[pos].startswith('require-or'): cond = parts[pos][len('require-or('):-1] (preconditions, fallback_action) = re.split(",", cond) for precondition in re.split("&&", preconditions): if precondition == 'debugMode': debugMode = True elif precondition == 'true': pass else: if fallback_action == "skip": expect = enable = False elif fallback_action == "fail": expect = False elif fallback_action == "random": random = True else: raise Exception( "Invalid precondition '%s' or fallback action '%s'" % (precondition, fallback_action)) break pos += 1 elif parts[pos] == 'script': script = parts[pos + 1] pos += 2 elif parts[pos] == 'slow': slow = True pos += 1 elif parts[pos] == 'silentfail': # silentfails use tons of memory, and Darwin doesn't support ulimit. if xul_tester.test("xulRuntime.OS == 'Darwin'"): expect = enable = False pos += 1 else: print 'warning: invalid manifest line element "%s"' % parts[ pos] pos += 1 assert script is not None ans.append( TestCase(os.path.join(reldir, script), enable, expect, random, slow, debugMode)) return ans
def parse(filename, xul_tester, reldir = ''): ans = [] comment_re = re.compile(r'#.*') dir = os.path.dirname(filename) try: f = open(filename) except IOError: print "warning: include file not found: '%s'"%filename return ans for line in f: sline = comment_re.sub('', line) parts = sline.split() if parts[0] == 'include': include_file = parts[1] include_reldir = os.path.join(reldir, os.path.dirname(include_file)) ans += parse(os.path.join(dir, include_file), xul_tester, include_reldir) elif parts[0] == 'url-prefix': # Doesn't apply to shell tests pass else: script = None enable = True expect = True random = False pos = 0 while pos < len(parts): if parts[pos] == 'fails': expect = False pos += 1 elif parts[pos] == 'skip': expect = enable = False pos += 1 elif parts[pos] == 'random': random = True pos += 1 elif parts[pos].startswith('fails-if'): cond = parts[pos][len('fails-if('):-1] if xul_tester.test(cond): expect = False pos += 1 elif parts[pos].startswith('asserts-if'): # This directive means we may flunk some number of # NS_ASSERTIONs in the browser. For the shell, ignore it. pos += 1 elif parts[pos].startswith('skip-if'): cond = parts[pos][len('skip-if('):-1] if xul_tester.test(cond): expect = enable = False pos += 1 elif parts[pos].startswith('random-if'): cond = parts[pos][len('random-if('):-1] if xul_tester.test(cond): random = True pos += 1 elif parts[pos] == 'script': script = parts[pos+1] pos += 2 else: print 'warning: invalid manifest line element "%s"'%parts[pos] pos += 1 assert script is not None ans.append(TestCase(os.path.join(reldir, script), enable, expect, random)) return ans