PlatformIO Community

Test_build_src = true has no effect (anymore)

Hi, I’m a big fan of PlatformIO especially because it worked out of the box, when I tried it the first time.
That was like 8 month ago. I work with ESP32-S2, Arduino framework and I have independent code that I want to test with unity on windows (so I can debug comfortably)

This test I compile for platform = windows_x86 with test_build_src = true (I also tried test_build_src = yes). This is supposed to add all the cpp files in the test directory and complete my test. It used to work but now after a break of 5 month (and probably an update), it doesn’t compile the files int the test folder anymore. And I get a linkage error:

undefined reference to WinMain@16

It is the expected consequence when the test files are omitted by the compiler.

Can anybody tell me, why the compiler is ignoring the test folder?

config file:

[env:Windows_unity_tests]
platform = windows_x86
build_flags =
    ${env.build_flags}
    -I include/utils
    -I include/Extensions
    -std=c++11
test_build_src = true
build_src_filter =
    ${env.src_filter}
    -<main.cpp>
    -<arduino>
lib_deps =
    bblanchon/ArduinoJson@^6.19.4
    arduino-libraries/NTPClient@^3.2.1

Can you post the file structure of your project? (tree <your projectdirectroy>)

Thank you for the answer!
The digest of my tree is below. main.should.cpp contains the test main(). main.cpp contains the regular main but is removed from the compilation via the configuration.

C:\Project
│   .gitignore
│   platformio.ini
│   workspace.code-workspace
│   
├───.pio
	etc...
│
├───.vscode
	etc...
│       
├───include
	etc...
│   ├───driver
│   │       Driver_AdcPin.hpp
│   │       Driver_Spi.hpp
│   │       Driver_TickTime.hpp
│   │       Driver_Time.hpp       
│   ├───EVSE
│   │       ChargingHsm.hpp
│   │       CpModeHsm.hpp
│   │       WifiConnection.hpp
etc...
│   │       
│   └───win
│           WProgram.h
│           
├───lib
etc...
│       
├───src
│   │   main.cpp
│   │   
│   ├───arduino
│   │       Driver_AdcPin_Arduino.cpp
│   │       Driver_Spi_Arduino.cpp
│   │       Driver_TickTime_Arduino.cpp
│   │       Driver_Trace_Arduino.cpp
│   │       
│   ├───EVSE
│   │       CpModeHsm.cpp
│   │       
│   │       
│   └───win
│           Driver_Spi_Win.cpp
│           Driver_Time_win.cpp
│           Driver_Trace_cmd_win.cpp
│           
└───test
        ChargingHsm.should.cpp
        CpModeHsm.should.cpp
        main.should.cpp
       

This folder structure is not valid, PlatformIO requires you to put the code files for each test unit in a new directory starting with test_. This is documented in point 3.

https://docs.platformio.org/en/latest/advanced/unit-testing/structure/best-practices.html

Also see official example