Added support for "Test Hierarchies" // Issue #4135

This commit is contained in:
Ivan Kravets
2022-04-29 20:46:43 +03:00
parent b37a74dfd9
commit 16021d0df7
3 changed files with 25 additions and 8 deletions

View File

@ -45,8 +45,8 @@ Please check `Migration guide from 5.x to 6.0 <https://docs.platformio.org/en/la
* **Unit Testing**
- New `Unit Testing <https://docs.platformio.org/en/latest/advanced/unit-testing/index.html>`_ engine and documentation
- Added support for `Test Hierarchies <https://docs.platformio.org/en/latest/advanced/unit-testing/structure.html>`_ (`issue #4135 <https://github.com/platformio/platformio-core/issues/4135>`_)
- Added a new "test" `build configuration <https://docs.platformio.org/en/latest/projectconf/build_configurations.html>`__
- Added support for test hierarchies (nested test suites) (`issue #4135 <https://github.com/platformio/platformio-core/issues/4135>`_)
- Generate reports in JUnit and JSON formats using the `pio test --output-format <https://docs.platformio.org/en/latest/core/userguide/cmd_test.html#cmdoption-pio-test-output-format>`__ option (`issue #2891 <https://github.com/platformio/platformio-core/issues/2891>`_)
- Provide more information when the native program crashed on a host (errored with a negative return code) (`issue #3429 <https://github.com/platformio/platformio-core/issues/3429>`_)
- Fixed an issue when command line parameters ("--ignore", "--filter") do not override values defined in the |PIOCONF| (`issue #3845 <https://github.com/platformio/platformio-core/issues/3845>`_)

View File

@ -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")],

View File

@ -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 <stdio.h>
@ -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 <stdio.h>
#include <unity.h>