Resolved an issue where native tests would fail if a custom program name was specified // Resolve #4546

This commit is contained in:
Ivan Kravets
2023-04-15 13:40:53 +03:00
parent 66fe55668e
commit 0d9ee75b05
3 changed files with 14 additions and 5 deletions

View File

@ -28,6 +28,7 @@ PlatformIO Core 6
* Resolved an issue where the `build_cache_dir <https://docs.platformio.org/en/latest/projectconf/sections/platformio/options/directory/build_cache_dir.html>`__ setting was not being recognized consistently across multiple environments (`issue #4574 <https://github.com/platformio/platformio-core/issues/4574>`_) * Resolved an issue where the `build_cache_dir <https://docs.platformio.org/en/latest/projectconf/sections/platformio/options/directory/build_cache_dir.html>`__ setting was not being recognized consistently across multiple environments (`issue #4574 <https://github.com/platformio/platformio-core/issues/4574>`_)
* Fixed an issue where organization details could not be updated using the `pio org update <https://docs.platformio.org/en/latest/core/userguide/org/cmd_update.html>`__ command * Fixed an issue where organization details could not be updated using the `pio org update <https://docs.platformio.org/en/latest/core/userguide/org/cmd_update.html>`__ command
* Resolved an issue where the incorrect debugging environment was generated for VSCode in "Auto" mode (`issue #4597 <https://github.com/platformio/platformio-core/issues/4597>`_) * Resolved an issue where the incorrect debugging environment was generated for VSCode in "Auto" mode (`issue #4597 <https://github.com/platformio/platformio-core/issues/4597>`_)
* Resolved an issue where native tests would fail if a custom program name was specified (`issue #4546 <https://github.com/platformio/platformio-core/issues/4546>`_)
6.1.6 (2023-01-23) 6.1.6 (2023-01-23)
~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~

View File

@ -18,7 +18,7 @@ from platformio.exception import ReturnErrorCode
from platformio.platform.factory import PlatformFactory from platformio.platform.factory import PlatformFactory
from platformio.test.exception import UnitTestSuiteError from platformio.test.exception import UnitTestSuiteError
from platformio.test.result import TestCase, TestStatus 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 from platformio.test.runners.readers.serial import SerialTestOutputReader
CTX_META_TEST_IS_RUNNING = __name__ + ".test_running" CTX_META_TEST_IS_RUNNING = __name__ + ".test_running"
@ -160,7 +160,7 @@ class TestRunnerBase:
return None return None
click.secho("Testing...", bold=True) click.secho("Testing...", bold=True)
test_port = self.get_test_port() test_port = self.get_test_port()
program_conds = [ native_conds = [
not self.platform.is_embedded() not self.platform.is_embedded()
and (not test_port or "://" not in test_port), and (not test_port or "://" not in test_port),
self.project_config.get( self.project_config.get(
@ -168,8 +168,8 @@ class TestRunnerBase:
), ),
] ]
reader = ( reader = (
ProgramTestOutputReader(self) NativeTestOutputReader(self)
if any(program_conds) if any(native_conds)
else SerialTestOutputReader(self) else SerialTestOutputReader(self)
) )
return reader.begin() return reader.begin()

View File

@ -24,6 +24,7 @@ from platformio.compat import (
get_filesystem_encoding, get_filesystem_encoding,
get_locale_encoding, get_locale_encoding,
) )
from platformio.project.helpers import load_build_metadata
from platformio.test.exception import UnitTestError from platformio.test.exception import UnitTestError
EXITING_TIMEOUT = 5 # seconds EXITING_TIMEOUT = 5 # seconds
@ -56,7 +57,7 @@ class ProgramProcessProtocol(asyncio.SubprocessProtocol):
self._exit_timer.cancel() self._exit_timer.cancel()
class ProgramTestOutputReader: class NativeTestOutputReader:
def __init__(self, test_runner): def __init__(self, test_runner):
self.test_runner = test_runner self.test_runner = test_runner
self.aio_loop = ( self.aio_loop = (
@ -78,6 +79,13 @@ class ProgramTestOutputReader:
"program.exe" if IS_WINDOWS else "program", "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: if self.test_runner.options.program_args:
cmd.extend(self.test_runner.options.program_args) cmd.extend(self.test_runner.options.program_args)
return cmd return cmd