Page 1 of 1

Unit Testing includepath

Posted: Wed Mar 20, 2019 5:12 pm
by Bushfries
If I have a project structure that looks like:

Code: Select all

-project
	+main
	-components
		-testable
			-test
				test.c
Where in this project would the unit test app look for header files for the project? Currently I have all .c and .h files in project/main and would like to avoid making duplicates, if possible.

From the documentation and things I've read it seems like you have to make duplicate files for unity to be able to access them. Is there any way to avoid this and just use the project files I already have in project/main/?

Re: Unit Testing includepath

Posted: Thu Mar 21, 2019 1:41 am
by ESP_igrr
You can specify include directories exported by the main component by setting COMPONENT_ADD_INCLUDEDIRS variable to the list of directories to include. By default, COMPONENT_ADD_INCLUDEDIRS is set to "include", so if you put the header files into "include" subdirectory of the component, they will be visible to other components.
If you want to keep the header files in the root of the "main" component, you can set
COMPONENT_ADD_INCLUDEDIRS := .

(See https://docs.espressif.com/projects/esp ... -variables for more details)

Re: Unit Testing includepath

Posted: Fri Mar 22, 2019 5:36 pm
by Bushfries
Using a modified version of the unit test example with the file structure looking like this:
Image

I get the following error:

Code: Select all

/Users/user/esp/esp-idf/tools/unit-test-app/build/hub_test/libhub_test.a(test_mean.o):(.literal.test_func_16+0x0): undefined reference to `testable_mean'
/Users/user/esp/esp-idf/tools/unit-test-app/build/hub_test/libhub_test.a(test_mean.o): In function `test_func_16':
/Users/user/projects/unit_test/components/hub/test/test_mean.c:19: undefined reference to `testable_mean'
/Users/user/esp/esp-idf/tools/unit-test-app/build/hub_test/libhub_test.a(test_mean.o): In function `test_func_22':
/Users/user/projects/unit_test/components/hub/test/test_mean.c:25: undefined reference to `testable_mean'
/Users/user/esp/esp-idf/tools/unit-test-app/build/hub_test/libhub_test.a(test_mean.o): In function `test_func_32':
/Users/user/projects/unit_test/components/hub/test/test_mean.c:35: undefined reference to `testable_mean'
collect2: error: ld returned 1 exit status
test_mean.c is including the file like this:

Code: Select all

#include "../../../main/testable.h"
and CMakeLists.txt has the following information:

Code: Select all

set(COMPONENT_SRCDIRS "../../main")
set(COMPONENT_ADD_INCLUDEDIRS "../../main")

register_component()
Is there anything else I should be doing differently?

Re: Unit Testing includepath

Posted: Sun Mar 24, 2019 4:35 am
by ESP_igrr
Just a thought, have you added mean.c to the CMakeLists of main component? Do you see main.c being compiled?

Re: Unit Testing includepath

Posted: Mon Mar 25, 2019 5:05 pm
by Bushfries
I've realized what the problem is. When I do

Code: Select all

EXTRA_COMPONENT_DIRS="component"
it overwrites the default IDF_PATH components directory.

How would I go about adding multiple components via EXTRA_COMPONENT_DIRS? would it just be by using += rather than =?