diff --git a/HISTORY.rst b/HISTORY.rst index 8d526a6c..64971a1f 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -28,6 +28,7 @@ PlatformIO Core 6 * Resolved an issue where the `build_cache_dir `__ setting was not being recognized consistently across multiple environments (`issue #4574 `_) * Fixed an issue where organization details could not be updated using the `pio org update `__ command * Resolved an issue where the incorrect debugging environment was generated for VSCode in "Auto" mode (`issue #4597 `_) +* Resolved an issue where native tests would fail if a custom program name was specified (`issue #4546 `_) 6.1.6 (2023-01-23) ~~~~~~~~~~~~~~~~~~ diff --git a/platformio/test/runners/base.py b/platformio/test/runners/base.py index 78425a76..845a8c37 100644 --- a/platformio/test/runners/base.py +++ b/platformio/test/runners/base.py @@ -18,7 +18,7 @@ from platformio.exception import ReturnErrorCode from platformio.platform.factory import PlatformFactory from platformio.test.exception import UnitTestSuiteError from platformio.test.result import TestCase, TestStatus -from platformio.test.runners.readers.program import ProgramTestOutputReader +from platformio.test.runners.readers.native import NativeTestOutputReader from platformio.test.runners.readers.serial import SerialTestOutputReader CTX_META_TEST_IS_RUNNING = __name__ + ".test_running" @@ -160,7 +160,7 @@ class TestRunnerBase: return None click.secho("Testing...", bold=True) test_port = self.get_test_port() - program_conds = [ + native_conds = [ not self.platform.is_embedded() and (not test_port or "://" not in test_port), self.project_config.get( @@ -168,8 +168,8 @@ class TestRunnerBase: ), ] reader = ( - ProgramTestOutputReader(self) - if any(program_conds) + NativeTestOutputReader(self) + if any(native_conds) else SerialTestOutputReader(self) ) return reader.begin() diff --git a/platformio/test/runners/readers/program.py b/platformio/test/runners/readers/native.py similarity index 91% rename from platformio/test/runners/readers/program.py rename to platformio/test/runners/readers/native.py index d80d170d..981febc3 100644 --- a/platformio/test/runners/readers/program.py +++ b/platformio/test/runners/readers/native.py @@ -24,6 +24,7 @@ from platformio.compat import ( get_filesystem_encoding, get_locale_encoding, ) +from platformio.project.helpers import load_build_metadata from platformio.test.exception import UnitTestError EXITING_TIMEOUT = 5 # seconds @@ -56,7 +57,7 @@ class ProgramProcessProtocol(asyncio.SubprocessProtocol): self._exit_timer.cancel() -class ProgramTestOutputReader: +class NativeTestOutputReader: def __init__(self, test_runner): self.test_runner = test_runner self.aio_loop = ( @@ -78,6 +79,13 @@ class ProgramTestOutputReader: "program.exe" if IS_WINDOWS else "program", ) ] + # if user changed PROGNAME + if not os.path.exists(cmd[0]): + build_data = load_build_metadata( + os.getcwd(), self.test_runner.test_suite.env_name, cache=True + ) + if build_data: + cmd[0] = build_data["prog_path"] if self.test_runner.options.program_args: cmd.extend(self.test_runner.options.program_args) return cmd