From 842679c32b52d3e63c6f778e59ff4887f981c5c2 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 14 Jul 2022 14:45:31 +0300 Subject: [PATCH] Export a "PIO_UNIT_TESTING" macro to the project source files and dependent libraries in the Unit Testing mode --- HISTORY.rst | 1 + platformio/builder/tools/piolib.py | 4 ++++ platformio/builder/tools/piotest.py | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/HISTORY.rst b/HISTORY.rst index 72d5fa89..e659e93d 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -16,6 +16,7 @@ PlatformIO Core 6 6.1.2 (2022-07-??) ~~~~~~~~~~~~~~~~~~ +* Export a ``PIO_UNIT_TESTING`` macro to the project source files and dependent libraries in the |UNITTESTING| mode * Improved detection of Windows architecture (`issue #4353 `_) * Fixed a regression bug when `libArchive `__ option declared in the `library.json `__ manifest was ignored (`issue #4351 `_) * Fixed an issue when the `pio pkg publish `__ command didn't work with Python 3.6 (`issue #4352 `_) diff --git a/platformio/builder/tools/piolib.py b/platformio/builder/tools/piolib.py index 83e04f69..d375347f 100644 --- a/platformio/builder/tools/piolib.py +++ b/platformio/builder/tools/piolib.py @@ -145,6 +145,10 @@ class LibBuilderBase: self._circular_deps = [] self._processed_search_files = [] + # pass a macro to the projenv + libs + if "test" in env.GetBuildType(): + self.env.Append(CPPDEFINES=["PIO_UNIT_TESTING"]) + # reset source filter, could be overridden with extra script self.env["SRC_FILTER"] = "" diff --git a/platformio/builder/tools/piotest.py b/platformio/builder/tools/piotest.py index 08d475d2..07886efb 100644 --- a/platformio/builder/tools/piotest.py +++ b/platformio/builder/tools/piotest.py @@ -23,7 +23,7 @@ from platformio.test.runners.factory import TestRunnerFactory def ConfigureTestTarget(env): env.Append( - CPPDEFINES=["UNIT_TEST", "PIO_UNIT_TESTING"], + CPPDEFINES=["UNIT_TEST"], # deprecated, use PIO_UNIT_TESTING PIOTEST_SRC_FILTER=[f"+<*.{ext}>" for ext in piotool.SRC_BUILD_EXT], ) env.Prepend(CPPPATH=["$PROJECT_TEST_DIR"])