When a KUnit test (or other KTAP test) is skipped, a "skip reason" can be
provided. kunit.py has never done anything with this, ignoring anything
included in the KTAP output after the 'SKIP' directive.

Since we have it, and it's used, print it in a nice friendly yellow in
parentheses after a skipped test's name.

(And, by parsing it, it can be included in the JUnit results as well.)

Signed-off-by: David Gow <[email protected]>
---

There are a few bits of KTAP that kunit.py has never actually parsed, and
this is one of them. It's also nice to have a good way of quickly seeing
why a test has been skipped, given most tests do provide good reason
strings.

Happy to hear comments about the style: yellow in parentheses looks pretty
good here, but could be a bit confusing if KUnit do

This is the first version of this patch, as it's a new dependency of v3 of
patch 2, the JUnit support, which also includes the skip reason.

--
 tools/testing/kunit/kunit_parser.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/tools/testing/kunit/kunit_parser.py 
b/tools/testing/kunit/kunit_parser.py
index 0e1d2f4985eb..22b8464c6383 100644
--- a/tools/testing/kunit/kunit_parser.py
+++ b/tools/testing/kunit/kunit_parser.py
@@ -44,11 +44,12 @@ class Test:
                self.subtests = []  # type: List[Test]
                self.log = []  # type: List[str]
                self.counts = TestCounts()
+               self.skip_reason = ''
 
        def __str__(self) -> str:
                """Returns string representation of a Test class object."""
                return (f'Test({self.status}, {self.name}, 
{self.expected_count}, '
-                       f'{self.subtests}, {self.log}, {self.counts})')
+                       f'{self.subtests}, {self.log}, {self.counts}, 
{self.skip_reason})')
 
        def __repr__(self) -> str:
                """Returns string representation of a Test class object."""
@@ -352,9 +353,9 @@ def parse_test_plan(lines: LineStream, test: Test) -> bool:
        lines.pop()
        return True
 
-TEST_RESULT = re.compile(r'^\s*(ok|not ok) ([0-9]+) ?(- )?([^#]*)( # .*)?$')
+TEST_RESULT = re.compile(r'^\s*(ok|not ok) ([0-9]+) ?(:?- )?([^#]*)( # .*)?$')
 
-TEST_RESULT_SKIP = re.compile(r'^\s*(ok|not ok) ([0-9]+) ?(- )?(.*) # SKIP 
?(.*)$')
+TEST_RESULT_SKIP = re.compile(r'^\s*(ok|not ok) ([0-9]+) ?(:?- )?(.*) # SKIP 
?(.*)$')
 
 def peek_test_name_match(lines: LineStream, test: Test) -> bool:
        """
@@ -418,7 +419,7 @@ def parse_test_result(lines: LineStream, test: Test,
 
        # Set name of test object
        if skip_match:
-               test.name = skip_match.group(4) or skip_match.group(5)
+               test.name = skip_match.group(4)
        else:
                test.name = match.group(4)
 
@@ -431,6 +432,7 @@ def parse_test_result(lines: LineStream, test: Test,
        status = match.group(1)
        if skip_match:
                test.status = TestStatus.SKIPPED
+               test.skip_reason = skip_match.group(5) or ''
        elif status == 'ok':
                test.status = TestStatus.SUCCESS
        else:
@@ -539,7 +541,7 @@ def format_test_result(test: Test, printer: Printer) -> str:
        if test.status == TestStatus.SUCCESS:
                return printer.green('[PASSED] ') + test.name
        if test.status == TestStatus.SKIPPED:
-               return printer.yellow('[SKIPPED] ') + test.name
+               return printer.yellow('[SKIPPED] ') + test.name + ' (' +  
printer.yellow(test.skip_reason) + ')'
        if test.status == TestStatus.NO_TESTS:
                return printer.yellow('[NO TESTS RUN] ') + test.name
        if test.status == TestStatus.TEST_CRASHED:
-- 
2.54.0


Reply via email to