From a7654a60986bb9a0cf1d9e2b8f24d7cd37ed0577 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Mon, 9 May 2022 18:58:43 +0300 Subject: [PATCH] Move Unity code parts to the Unity runner --- platformio/test/runners/base.py | 30 ++---------------------------- platformio/test/runners/unity.py | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/platformio/test/runners/base.py b/platformio/test/runners/base.py index 31df5371..ead621e5 100644 --- a/platformio/test/runners/base.py +++ b/platformio/test/runners/base.py @@ -17,7 +17,7 @@ import click from platformio.exception import ReturnErrorCode from platformio.platform.factory import PlatformFactory from platformio.test.exception import UnitTestSuiteError -from platformio.test.result import TestCase, TestCaseSource, TestStatus +from platformio.test.result import TestCase, TestStatus from platformio.test.runners.readers.program import ProgramTestOutputReader from platformio.test.runners.readers.serial import SerialTestOutputReader @@ -204,31 +204,5 @@ class TestRunnerBase: self._testing_output_buffer = self._testing_output_buffer[nl_pos + 1 :] self.on_testing_line_output(line) - def on_testing_line_output(self, line): + def on_testing_line_output(self, line): # pylint: disable=no-self-use click.echo(line, nl=False) - self.parse_test_case(line) - - def parse_test_case(self, line): - if not self.TESTCASE_PARSE_RE: - raise NotImplementedError() - line = line.strip() - if not line: - return None - match = self.TESTCASE_PARSE_RE.search(line) - if not match: - return None - data = match.groupdict() - source = None - if "source_file" in data: - source = TestCaseSource( - filename=data["source_file"], line=int(data.get("source_line")) - ) - test_case = TestCase( - name=data.get("name").strip(), - status=TestStatus.from_string(data.get("status")), - message=(data.get("message") or "").strip() or None, - stdout=line, - source=source, - ) - self.test_suite.add_case(test_case) - return test_case diff --git a/platformio/test/runners/unity.py b/platformio/test/runners/unity.py index a59b41f1..24950cff 100644 --- a/platformio/test/runners/unity.py +++ b/platformio/test/runners/unity.py @@ -20,6 +20,7 @@ from pathlib import Path import click from platformio.test.exception import UnitTestSuiteError +from platformio.test.result import TestCase, TestCaseSource, TestStatus from platformio.test.runners.base import TestRunnerBase from platformio.util import strip_ansi_codes @@ -28,7 +29,7 @@ class UnityTestRunner(TestRunnerBase): EXTRA_LIB_DEPS = ["throwtheswitch/Unity@^2.5.2"] - # example + # Example: # test/test_foo.cpp:44:test_function_foo:FAIL: Expected 32 Was 33 TESTCASE_PARSE_RE = re.compile( r"(?P[^:]+):(?P\d+):(?P[^:]+):" @@ -262,3 +263,28 @@ void unityOutputComplete(void) { unittest_uart_end(); } if all(s in line for s in ("Tests", "Failures", "Ignored")): self.test_suite.on_finish() + + def parse_test_case(self, line): + if not self.TESTCASE_PARSE_RE: + raise NotImplementedError() + line = line.strip() + if not line: + return None + match = self.TESTCASE_PARSE_RE.search(line) + if not match: + return None + data = match.groupdict() + source = None + if "source_file" in data: + source = TestCaseSource( + filename=data["source_file"], line=int(data.get("source_line")) + ) + test_case = TestCase( + name=data.get("name").strip(), + status=TestStatus.from_string(data.get("status")), + message=(data.get("message") or "").strip() or None, + stdout=line, + source=source, + ) + self.test_suite.add_case(test_case) + return test_case