Skip to content

Commit c68077b

Browse files
sulixshuahkh
authored andcommitted
kunit: tool: Do not error on tests without test plans
The (K)TAP spec encourages test output to begin with a 'test plan': a count of the number of tests being run of the form: 1..n However, some test suites might not know the number of subtests in advance (for example, KUnit's parameterised tests use a generator function). In this case, it's not possible to print the test plan in advance. kunit_tool already parses test output which doesn't contain a plan, but reports an error. Since we want to use nested subtests with KUnit paramterised tests, remove this error. Signed-off-by: David Gow <[email protected]> Reviewed-by: Daniel Latypov <[email protected]> Reviewed-by: Brendan Higgins <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent ee92ed3 commit c68077b

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

tools/testing/kunit/kunit_parser.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ def parse_test_plan(lines: LineStream, test: Test) -> bool:
340340
"""
341341
Parses test plan line and stores the expected number of subtests in
342342
test object. Reports an error if expected count is 0.
343-
Returns False and reports missing test plan error if fails to parse
344-
test plan.
343+
Returns False and sets expected_count to None if there is no valid test
344+
plan.
345345
346346
Accepted format:
347347
- '1..[number of subtests]'
@@ -356,7 +356,6 @@ def parse_test_plan(lines: LineStream, test: Test) -> bool:
356356
match = TEST_PLAN.match(lines.peek())
357357
if not match:
358358
test.expected_count = None
359-
test.add_error('missing plan line!')
360359
return False
361360
test.log.append(lines.pop())
362361
expected_count = int(match.group(1))

tools/testing/kunit/kunit_tool_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,10 @@ def test_missing_test_plan(self):
191191
result = kunit_parser.parse_run_tests(
192192
kunit_parser.extract_tap_lines(
193193
file.readlines()))
194-
self.assertEqual(2, result.test.counts.errors)
194+
# A missing test plan is not an error.
195+
self.assertEqual(0, result.test.counts.errors)
196+
# All tests should be accounted for.
197+
self.assertEqual(10, result.test.counts.total())
195198
self.assertEqual(
196199
kunit_parser.TestStatus.SUCCESS,
197200
result.status)

0 commit comments

Comments
 (0)