PlatformIO Community

PlatformIO test no longer working?

For the GRBL_ESP32 project, I wanted to add unit testing a few months back. So, I dug into the documentation of pio and found pio test. The source and platformio can be found here: GitHub - bdring/Grbl_Esp32 at YamlSettings .Because of compatibility with Arduino IDE and for some other reasons, I made the following config:

[platformio]
src_dir = Grbl_Esp32
lib_dir = libraries
test_dir = Grbl_Esp32/test
...

[env:test]
build_type = debug
test_build_project_src = true

From what I understand from Unit Testing — PlatformIO latest documentation this should just compile the src tree along with the tests (PS: some docs say I should use ‘true’, others say ‘yes’, but the result is the same). And at the time, it just worked great.

Now, it was time to dust it off, because we are working on a major change. And to my surprise, it doesn’t work anymore. After inspection (-v), it turns out that that ‘src’ folder is no longer built, which means it won’t link, and… everything turns red… I just can’t figure out why.

How can I fix this?

What seems to be the problem? You didn’t post any error message. If I download your repo, check it out in the YamlSettings branch and do a pio test -e test --without-uploading --without-testing, I get successful compilation.

Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [==        ]  16.1% (used 52620 bytes from 327680 bytes)
Flash: [======    ]  64.7% (used 1271330 bytes from 1966080 bytes)
.pio\build\test\firmware.elf 

If it were not building stuff in the src/ folder I should be getting a linker error, no?

Oh boy I forgot how the -e test was required, which yields a lot of linker errors.

My bad…

Indeed, only the [env:test] environment has the test_build_project_src = true set and noone other, so pio test will only work in the test environment in your project configuration.

However, I don’t see why this explicit testing environment is needed at all, you can pull it in to the global settings in [env] and thus the debug and release envs should be automatically testable.

However, I don’t see why this explicit testing environment is needed at all, you can pull it in to the global settings in [env] and thus the debug and release envs should be automatically testable.

Nice, thanks a lot, going to use that! While it makes sense, I just never considered that possibility.