PlatformIO Community

LDF does not find or build src/common modules for unit test

When building unit tests for GoogleTest, LDF finds required modules in lib/ but not in src/. I’ve tried adding paths to test_filter (eg. “…/src/common”) but modules within that folder are still not built.

The unit test code that uses these modules includes their header files and compiles without error, but the modules under src/ and not built and the final link fails because the needed src/ modules are not referenced.


It is expected that no modules in the src/ tree are built for unit test?

Yes, since test_build_src is no by default, no sources in src/ will be compiled. If you need them in unit test, activate that feature while making sure other interfering things (like a possible main function in src/) is not compiled (#ifdef PIO_UNIT_TESTING), or pull the code needed for testing the component in lib.

Yes, of course! Thanks for pointing that out Max. I’ll try setting test_build_src true as a quick fix, but I’d really prefer to move this code into lib as it seems like it really should be there.

Enabling test_build_src worked. Thanks @maxgerhardt !