PlatformIO Community

Pio test not building project source


#1

Was there a change to the pio test API in 3.5.3? When 3.5.3 released circle CI began failing my tests. Now that I was able to update to 3.5.4 locally the error persists on my local dev machine. It looks like platformio is building the tests but not the actual project and failing to link as a result. Do I have to specify the source location now?


#2

Is no one else experiencing this issue where their src is not building/linking for test (but is including?)


#3

We stopped building source code from src folder to avoid conflicts and wrapping files with ifndef UNITY.

We updated our docs. We recommend organizing code into “lib” components and use them from “src” or “test” source code.

See “green HINT” block in http://docs.platformio.org/en/latest/plus/unit-testing.html#workflow


#4

Thanks for the reply, how does a project that is a library unit test then? If I recall correctly the source for the library must be contained in the src folder for the Arduino IDE to properly handle it.


#5

Indeed, this is a bug in PIO Core and I’m going to fix it in the next hours. If you need to do unit testing on a library, you can add it to build process using lib_extra_dirs. I’ve just cloned your repo and did small modification to platformio.ini:

#
# Project Configuration File
#
# A detailed documentation with the EXAMPLES is located here:
# http://docs.platformio.org/en/latest/projectconf.html
#

# A sign `#` at the beginning of the line indicates a comment
# Comment lines are ignored.

# Simple and base environment
# [env:mybaseenv]
# platform = %INSTALLED_PLATFORM_NAME_HERE%
# framework =
# board =
#
# Automatic targets - enable auto-uploading
# targets = upload

[env:teensy31]
platform = teensy
framework = arduino
board = teensy31

[env:nrf52]
platform = nordicnrf52
framework = arduino
board = nrf52_dk
build_flags = -DNRF52_S132

[env:native]
platform = native
lib_extra_dirs = ..
build_flags = -Wno-c++11-extensions -std=c++11

So, PlatformIO will automatically find this library. See build log:

(develop) ikravets@innomac /V/S/P/G/p/origin> pio test -d /Users/ikravets/Downloads/ant-arduino-master -e native -v
PIO Plus (https://pioplus.com) v1.4.0
Verbose mode can be enabled via `-v, --verbose` option
Collected 2 items

======================================================== [test/TX_AddChannelIdToList] Building... (1/2) ========================================================

Processing native (platform: native)
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
PLATFORM: Native >
SYSTEM:
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 19 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <ANT> 1.1.0
Compiling .pioenvs/native/libc8b/ant-arduino-master/BaseClasses/ANT_BaseAnt.o
Compiling .pioenvs/native/libc8b/ant-arduino-master/BaseClasses/ANT_BaseAntWithCallbacks.o
...

P.S: I’ll ping you here when this fix be pushed to development branch. Need to update our documentation and explain this use case.


#6

Yep that definitely solves the bug. Thanks for that.
I had to use the following parameters otherwise it built outside my repo
lib_extra_dirs = .
Although unity.h is not exposed to the src directory, is this intended? The reason is that I mock some of the arduino framework objects for testing.


#7

Please switch to the latest development version of PIO Core via pio upgrade --dev and check this updated docs http://docs.platformio.org/en/latest/plus/unit-testing.html#shared-code


#8

Updated. Tested it. Something is weird with the LDF. Its pulling in code from other repos. I have a repo with similar headers and cpp files and the LDF appears to be pulling in the files. The repo I’m running tests on is ant-arduino but the LDF appears to be pulling in ant-mbed.

Repo paths: /Users/curtismalainey/Github/<repo name>


52%20PM

Using the following config seems to find the cpp files but I get errors locating headers. It looks like the LDF treats each folder as a different library so this doesn’t work either.

[env:native]
platform = native
lib_extra_dirs = src
build_flags = -Wno-c++11-extensions -std=c++11


#9

I see. Maybe, is better to add new option, such as test_build_project_src = true? Do you have better idea to name this option? having it enabled, will force PlatformIO Core to build source files from src folder too. Then no need to use these lib_deps or lib_extra_dirs.


#10

Yea I think there is no easy around it with scoping paths with lib_extra_dirs. I think that or command line parameter such as pio test --build-src would probably be the best bet


#11

See updated docs http://docs.platformio.org/en/latest/plus/unit-testing.html#shared-code

P.S: Please run pio upgrade --dev.


#12

Success!