I was looking for some informations, because I face the problem that a test gives unexpected results (aka fails ) and I would really like to debug it to find the reason for the failure. During research I found that old discussion and as far I could see, the issue is still open.
Are there any plans to support debugging of tests in a native environment, too?
src\HardwareStepper.h:4:10: fatal error: Arduino.h: No such file or directory
I have references to Arduino.h in my src directory. I’m assuming that is ok? Should I be using an option to exclude the src directory somehow when I’m debugging?
Yes, the tests work using pio test and I’ve got them working in Github Actions too.
Bear in mind I’m not an expert in C++ but I believe all my dependencies are clean and I don’t (directly or indirectly) reference hardware related code from my unit tests.
My first thought is to wonder how the build task I’ve set up knows not to build the src folder. Do I need a special build task?
I saw this thread but I’ve tried looking at articles linked from the solution.
The option that controls whether the src/ directory is built is by default set to no. (docs).
It’s also entirely possible that there is still a bug and the feature test was done without any content in src/. I’ll try and reproduce the issue – if it’s reproducable, that’s gonna be a bug report Issues · platformio/platformio-core · GitHub then.
Ah you just gave me a thought… I had tried removing all code from src directory but I got an error about having nothing in src so I gave up.
I’ve just retried deleting everything in src but I recreated a blank main.cpp with empty setup and loop methods.
This now gets further giving me this:
Building in debug mode
Linking .pio\build\debug\program.exe
C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.1.0/…/…/…/…/x86_64-w64-mingw32/lib/…/lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e): undefined reference to `WinMain’
collect2.exe: error: ld returned 1 exit status
I don’t see the program.exe in that folder so I’m guessing it did not complete the linking process.
Is there anything I can do to help with reproducing or anything I can try next?
Does the test program in test/test_analyzer.cpp contain the main function, e.g. as in example? If it’s still not working as expected , please post the full platformio.ini and source code.
Yes, test/test_analyzer.cpp contains the main function. My repo is public here. This is a branch with the empty src directory with just a main.cpp with empty main, setup and loop methods.
Hi @ivankravets, sorry, no it’s not working as expected.
Expected behavior
Build code in the lib directory and the specific test_xyz.cpp and use the main method in there.
Actual behavior
It builds the code in the src directory and tries to run the main method I’ve defined in there (which I just did for testing purposes).
Hi @ivankravets, @maxgerhardt, many thanks for your help. I’ve worked out what my problem was and have created a cut-down, basic example with this working in this repo.
I had made an assumption that the unit test for the classes in lib would not build the code in the src directory. The issue was that my debug environment in platformio.ini did not include the lib_deps section that I had defined in the other environments (native, nano etc). Once I added this, everything built and I can set a breakpoint in tests defined in debug_test.
Just wanted to add that PlatformIO is incredible - keep up the good work!