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

1 Like

@maxgerhard: I would like to apologize sincerely for starting this post and causing troubles. Can it be deleted? I feel deeply ashamed for doing a basic/foolish mistake and for blaming PlatformIO for it:

I have realized that I forgot to call the Test command in the Advanced section.
I called Build instead and it always gave me the same issue.

As for the test structure: it doesn’t really need the test_* sub folders if there aren’t multiple test suites. But that is only a detail. (If you looking at this post as a solution, look also at the post above from maxgerhard pointing out the existing examples for tests.)

Again, please accept my apologies for not using PlatformIO correctly - problem solved / case closed

1 Like