diff --git a/HISTORY.rst b/HISTORY.rst index 30960775..c20b419a 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -45,8 +45,8 @@ Please check `Migration guide from 5.x to 6.0 `_ engine and documentation + - Added support for `Test Hierarchies `_ (`issue #4135 `_) - Added a new "test" `build configuration `__ - - Added support for test hierarchies (nested test suites) (`issue #4135 `_) - Generate reports in JUnit and JSON formats using the `pio test --output-format `__ option (`issue #2891 `_) - Provide more information when the native program crashed on a host (errored with a negative return code) (`issue #3429 `_) - Fixed an issue when command line parameters ("--ignore", "--filter") do not override values defined in the |PIOCONF| (`issue #3845 `_) diff --git a/platformio/builder/tools/piotest.py b/platformio/builder/tools/piotest.py index b9c2444a..0ebe7637 100644 --- a/platformio/builder/tools/piotest.py +++ b/platformio/builder/tools/piotest.py @@ -16,6 +16,7 @@ from __future__ import absolute_import import os +from platformio.builder.tools import platformio as piotool from platformio.test.result import TestSuite from platformio.test.runners.factory import TestRunnerFactory @@ -23,10 +24,24 @@ from platformio.test.runners.factory import TestRunnerFactory def ConfigureTestTarget(env): env.Append( CPPDEFINES=["UNIT_TEST", "PIO_UNIT_TESTING"], - PIOTEST_SRC_FILTER=["+<*.cpp>", "+<*.c>"], + PIOTEST_SRC_FILTER=[f"+<*.{ext}>" for ext in piotool.SRC_BUILD_EXT], ) if "PIOTEST_RUNNING_NAME" in env: + test_name = env["PIOTEST_RUNNING_NAME"] + while True: + test_name = os.path.dirname(test_name) # parent dir + # skip nested tests (user's side issue?) + if not test_name or os.path.basename(test_name).startswith("test_"): + break + env.Append( + PIOTEST_SRC_FILTER=[ + f"+<{test_name}{os.path.sep}*.{ext}>" + for ext in piotool.SRC_BUILD_EXT + ], + CPPPATH=[os.path.join("$PROJECT_TEST_DIR", test_name)], + ) + env.Append( PIOTEST_SRC_FILTER=[f"+<$PIOTEST_RUNNING_NAME{os.path.sep}>"], CPPPATH=[os.path.join("$PROJECT_TEST_DIR", "$PIOTEST_RUNNING_NAME")], diff --git a/tests/commands/test_test.py b/tests/commands/test_test.py index d8780fae..a68a20fe 100644 --- a/tests/commands/test_test.py +++ b/tests/commands/test_test.py @@ -235,16 +235,18 @@ int main() { assert all(f in result.output for f in ("setUp called", "tearDown called")) -def test_unity_custom_config(clirunner, validate_cliresult, tmpdir): - project_dir = tmpdir.mkdir("project") - project_dir.join("platformio.ini").write( +def test_unity_custom_config(clirunner, validate_cliresult, tmp_path: Path): + project_dir = tmp_path / "project" + project_dir.mkdir() + (project_dir / "platformio.ini").write_text( """ [env:native] platform = native """ ) - test_dir = project_dir.mkdir("test") - test_dir.join("unity_config.h").write( + test_dir = project_dir / "test" / "native" / "test_component" + test_dir.mkdir(parents=True) + (test_dir.parent / "unity_config.h").write_text( """ #include @@ -254,7 +256,7 @@ platform = native #define UNITY_OUTPUT_FLUSH() fflush(stdout) """ ) - test_dir.join("test_main.c").write( + (test_dir / "test_main.c").write_text( """ #include #include