Commit 94a5e47d authored by Rakib M. Hasan's avatar Rakib M. Hasan Committed by Commit Bot

Raise an exception when a non glob test expectation pattern is shorter than any test name

If a test expectations non glob pattern is shorter than any test name then the presubmit
check should raise an exception because the test expectation is for a non existing test.
This CL will update CheckTestExpectationsAreForExistingTests so that it raises an exception
when it finds one of these test expectations.

Bug: chromium:978712
Change-Id: Ic80efccca659b7f35a345ebb187fb7dab08c423f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1677510
Commit-Queue: Rakib Hasan <rmhasan@google.com>
Reviewed-by: default avatarKenneth Russell <kbr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#672693}
parent ffc312e4
...@@ -188,6 +188,7 @@ def CheckTestExpectationsAreForExistingTests( ...@@ -188,6 +188,7 @@ def CheckTestExpectationsAreForExistingTests(
_trie = trie.setdefault(test[0], {}) _trie = trie.setdefault(test[0], {})
for l in test[1:]: for l in test[1:]:
_trie = _trie.setdefault(l, {}) _trie = _trie.setdefault(l, {})
_trie.setdefault('$', {})
f = open(expectations_file, 'r') f = open(expectations_file, 'r')
expectations_file = os.path.basename(expectations_file) expectations_file = os.path.basename(expectations_file)
expectations = f.read() expectations = f.read()
...@@ -195,14 +196,18 @@ def CheckTestExpectationsAreForExistingTests( ...@@ -195,14 +196,18 @@ def CheckTestExpectationsAreForExistingTests(
parser = expectations_parser.TaggedTestListParser(expectations) parser = expectations_parser.TaggedTestListParser(expectations)
for exp in parser.expectations: for exp in parser.expectations:
_trie = trie _trie = trie
is_glob = False
for l in exp.test: for l in exp.test:
if l == '*': if l == '*':
is_glob = True
break break
assert l in _trie, ( assert l in _trie, (
"%s:%d: Glob '%s' does not match with any tests in the %s test suite" % "%s:%d: Pattern '%s' does not match with any tests in the %s test suite"
(expectations_file, exp.lineno, exp.test, test_class.Name())) % (expectations_file, exp.lineno, exp.test, test_class.Name()))
_trie = _trie[l] _trie = _trie[l]
assert is_glob or '$' in _trie, (
"%s:%d: Pattern '%s' does not match with any tests in the %s test suite"
% (expectations_file, exp.lineno, exp.test, test_class.Name()))
def CheckTestExpectationGlobsForCollision( def CheckTestExpectationGlobsForCollision(
expectations, file_name, test_class=None): expectations, file_name, test_class=None):
...@@ -625,7 +630,14 @@ class TestGpuTestExpectationsValidators(unittest.TestCase): ...@@ -625,7 +630,14 @@ class TestGpuTestExpectationsValidators(unittest.TestCase):
def testExpectationPatternNotInGeneratedTests(self): def testExpectationPatternNotInGeneratedTests(self):
with self.assertRaises(AssertionError) as context: with self.assertRaises(AssertionError) as context:
_TestCheckTestExpectationsAreForExistingTests('a/b/d [ Failure ]') _TestCheckTestExpectationsAreForExistingTests('a/b/d [ Failure ]')
self.assertIn(("1: Glob 'a/b/d' does not match with any" self.assertIn(("1: Pattern 'a/b/d' does not match with any"
" tests in the GpuIntegrationTest test suite"),
str(context.exception))
def testExpectationPatternIsShorterThanAnyTestName(self):
with self.assertRaises(AssertionError) as context:
_TestCheckTestExpectationsAreForExistingTests('a/b [ Failure ]')
self.assertIn(("1: Pattern 'a/b' does not match with any"
" tests in the GpuIntegrationTest test suite"), " tests in the GpuIntegrationTest test suite"),
str(context.exception)) str(context.exception))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment