Unit tests with unity

I am trying to run unity tests with Unity and I am getting the error below

> Executing task in folder universal_remote_control: pio test --environment native <

Verbose mode can be enabled via `-v, --verbose` option
Collected 1 items

Processing * in native environment
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Building...
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
*** [.pio/build/native/program] Error 1
=========================================================================================== [FAILED] Took 1.25 seconds ===========================================================================================

Test    Environment    Status    Duration
------  -------------  --------  ------------
*       native         FAILED    00:00:01.249
====================================================================================== 1 failed, 0 succeeded in 00:00:01.249 ======================================================================================
The terminal process "pio 'test', '--environment', 'native'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

I am running the task test on Platformio

The code is (UniversalRemoteControlTest.cpp):

#include <unity.h>
#include <IUniversalRemoteControl.h>

RemoteControl remoteControl;

void setUp(void) {
    remoteControl = RemoteControl();
    remoteControl.addCode(0x123, "up");
}

// void tearDown(void) {
// // clean stuff up here
// }

void test_should_add_code(void) {
    //boolean test = "up".equals(remoteControl.hasCode(0x123));
    TEST_ASSERT_TRUE(true);
} 

int main(int argc, char **argv) {
    /*
    UNITY_BEGIN();
    RUN_TEST(test_should_add_code);
    UNITY_END();
*/
    return 0;
}

I am running on Mac VSCode

platformio.ini:

[env:uno]
platform = atmelavr
board = uno
framework = arduino
lib_deps =
seeed-studio/IRremote@^2.6.1
iondbproject/IonDB@^2.2.0
adafruit/SD@0.0.0-alpha+sha.041f788250
bxparks/AUnit@^1.4.1

[env:native]
platform = native
test_ignore = test_embedded

Project Structure

And which file is that and where is it? What’s the platformio.ini?

Updated on the main question, tks

Isn’t the file just in the wrong place? What happens when you move lib/xxx/test/UniverstalRemoteControlTest.cpp to just test/?

@maxgerhardt, moving the file fixed that error, but dependencies are not working properly.
I dig a bit more.

Any chance I can make the test work from the original location?

Tks

All but the first line must be indented by at least two spaces to be picked up correctly.

Does it help if you also add UniversalRemoteControl in that list?

@maxgerhardt,
there are. It was just pasting here that was wrong. Tks

See the error below.
Both environments fail with different errors

> Executing task in folder universal_remote_control: pio test <

Verbose mode can be enabled via `-v, --verbose` option
Collected 1 items

Processing * in uno environment
------------------------------------------------------------------------------------------------------------------------------------------------------------------
Building...
In file included from .pio/libdeps/uno/IonDB/src/cpp_wrapper/../dictionary/../file/sd_stdio_c_iface.h:53:0,
                 from .pio/libdeps/uno/IonDB/src/cpp_wrapper/../dictionary/ion_master_table.h:55,
                 from .pio/libdeps/uno/IonDB/src/cpp_wrapper/Dictionary.h:44,
                 from .pio/libdeps/uno/IonDB/src/IonDB.h:41,
                 from lib/UniversalRemoteControl/src/IUniversalRemoteControl.h:6,
                 from test/UniversalRemoteControlTest.cpp:2:
.pio/libdeps/uno/IonDB/src/cpp_wrapper/../dictionary/../file/kv_stdio_intercept.h:66:0: warning: "feof" redefined
 #define  feof(x)   sd_feof(x)
 ^
In file included from .pio/libdeps/uno/IonDB/src/key_value/kv_system.h:44:0,
                 from .pio/libdeps/uno/IonDB/src/IonDB.h:40,
                 from lib/UniversalRemoteControl/src/IUniversalRemoteControl.h:6,
                 from test/UniversalRemoteControlTest.cpp:2:
/Users/eduardo/.platformio/packages/toolchain-atmelavr/avr/include/stdio.h:863:0: note: this is the location of the previous definition
 #define feof(s) ((s)->flags & __SEOF)
 ^
In file included from /Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/Arduino.h:232:0,
                 from .pio/libdeps/uno/IonDB/src/cpp_wrapper/../dictionary/../file/sd_stdio_c_iface.h:47,
                 from .pio/libdeps/uno/IonDB/src/cpp_wrapper/../dictionary/ion_master_table.h:55,
                 from .pio/libdeps/uno/IonDB/src/cpp_wrapper/Dictionary.h:44,
                 from .pio/libdeps/uno/IonDB/src/IonDB.h:41,
                 from lib/UniversalRemoteControl/src/IUniversalRemoteControl.h:6,
                 from test/UniversalRemoteControlTest.cpp:2:
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:126:83: error: conflicting declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, const char*)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr);
                                                                                   ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:125:27: note: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const String&)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs);
                           ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:127:73: error: conflicting declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, char)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, char c);
                                                                         ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:126:27: note: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const char*)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr);
                           ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:127:73: error: conflicting declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, char)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, char c);
                                                                         ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:125:27: note: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const String&)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs);
                           ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:128:84: error: conflicting declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, unsigned char)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num);
                                                                                    ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:127:27: note: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, char)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, char c);
                           ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:128:84: error: conflicting declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, unsigned char)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num);
                                                                                    ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:126:27: note: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const char*)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr);
                           ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:128:84: error: conflicting declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, unsigned char)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num);
                                                                                    ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:125:27: note: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const String&)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs);
                           ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:129:74: error: conflicting declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, int)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, int num);
                                                                          ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:128:27: note: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, unsigned char)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num);
                           ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:129:74: error: conflicting declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, int)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, int num);
                                                                          ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:127:27: note: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, char)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, char c);
                           ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:129:74: error: conflicting declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, int)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, int num);
                                                                          ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:126:27: note: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const char*)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr);
                           ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:129:74: error: conflicting declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, int)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, int num);
                                                                          ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:125:27: note: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const String&)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs);
                           ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:130:83: error: conflicting declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, unsigned int)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num);
                                                                                   ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:129:27: note: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, int)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, int num);
                           ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:130:83: error: conflicting declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, unsigned int)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num);
                                                                                   ^
/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:128:27: note: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, unsigned char)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num);
                           ^

...
    /Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:135:97: error: conflicting declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, const __FlashStringHelper*)'
      friend StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs);
                                                                                                     ^
    /Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:126:27: note: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const char*)'
      friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr);
                               ^
    /Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:135:97: error: conflicting declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, const __FlashStringHelper*)'
      friend StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs);
                                                                                                     ^
    /Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/WString.h:125:27: note: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const String&)'
      friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs);
                               ^
    In file included from .pio/libdeps/uno/IonDB/src/cpp_wrapper/../dictionary/../file/sd_stdio_c_iface.h:47:0,
                     from .pio/libdeps/uno/IonDB/src/cpp_wrapper/../dictionary/ion_master_table.h:55,
                     from .pio/libdeps/uno/IonDB/src/cpp_wrapper/Dictionary.h:44,
                     from .pio/libdeps/uno/IonDB/src/IonDB.h:41,
                     from lib/UniversalRemoteControl/src/IUniversalRemoteControl.h:6,
                     from test/UniversalRemoteControlTest.cpp:2:
    /Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/Arduino.h:240:33: error: conflicting declaration of C function 'uint16_t makeWord(byte, byte)'
     uint16_t makeWord(byte h, byte l);
                                     ^
    /Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/Arduino.h:239:10: note: previous declaration 'uint16_t makeWord(uint16_t)'
     uint16_t makeWord(uint16_t w);
              ^
    /Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/Arduino.h:251:17: error: conflicting declaration of C function 'long int random(long int)'
     long random(long);
                     ^
    In file included from .pio/libdeps/uno/IonDB/src/key_value/kv_system.h:45:0,
                     from .pio/libdeps/uno/IonDB/src/IonDB.h:40,
                     from lib/UniversalRemoteControl/src/IUniversalRemoteControl.h:6,
                     from test/UniversalRemoteControlTest.cpp:2:
    /Users/eduardo/.platformio/packages/toolchain-atmelavr/avr/include/stdlib.h:590:13: note: previous declaration 'long int random()'
     extern long random(void);
                 ^
    In file included from .pio/libdeps/uno/IonDB/src/cpp_wrapper/../dictionary/../file/sd_stdio_c_iface.h:47:0,
                     from .pio/libdeps/uno/IonDB/src/cpp_wrapper/../dictionary/ion_master_table.h:55,
                     from .pio/libdeps/uno/IonDB/src/cpp_wrapper/Dictionary.h:44,
                     from .pio/libdeps/uno/IonDB/src/IonDB.h:41,
                     from lib/UniversalRemoteControl/src/IUniversalRemoteControl.h:6,
                     from test/UniversalRemoteControlTest.cpp:2:
    /Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/Arduino.h:252:23: error: conflicting declaration of C function 'long int random(long int, long int)'
     long random(long, long);
                           ^
    /Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/Arduino.h:251:6: note: previous declaration 'long int random(long int)'
     long random(long);
          ^
    /Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino/Arduino.h:252:23: error: conflicting declaration of C function 'long int random(long int, long int)'
     long random(long, long);
                           ^
    In file included from .pio/libdeps/uno/IonDB/src/key_value/kv_system.h:45:0,
                     from .pio/libdeps/uno/IonDB/src/IonDB.h:40,
                     from lib/UniversalRemoteControl/src/IUniversalRemoteControl.h:6,
                     from test/UniversalRemoteControlTest.cpp:2:
    /Users/eduardo/.platformio/packages/toolchain-atmelavr/avr/include/stdlib.h:590:13: note: previous declaration 'long int random()'
     extern long random(void);
                 ^
    *** [.pio/build/uno/test/UniversalRemoteControlTest.cpp.o] Error 1
    =================================================================== [FAILED] Took 1.13 seconds ===================================================================

Processing * in native environment
------------------------------------------------------------------------------------------------------------------------------------------------------------------
Building...
In file included from lib/UniversalRemoteControl/src/UniversalRemoteControl.cpp:1:
lib/UniversalRemoteControl/src/IUniversalRemoteControl.h:6:10: fatal error: 'IonDB.h' file not found
#include <IonDB.h>
         ^~~~~~~~~
1 error generated.
*** [.pio/build/native/lib358/UniversalRemoteControl/UniversalRemoteControl.o] Error 1
In file included from test/UniversalRemoteControlTest.cpp:2:
lib/UniversalRemoteControl/src/IUniversalRemoteControl.h:6:10: fatal error: 'IonDB.h' file not found
#include <IonDB.h>
         ^~~~~~~~~
1 error generated.
*** [.pio/build/native/test/UniversalRemoteControlTest.o] Error 1
=================================================================== [FAILED] Took 0.63 seconds ===================================================================

Test    Environment    Status    Duration
------  -------------  --------  ------------
*       uno            FAILED    00:00:01.127
*       native         FAILED    00:00:00.633
============================================================= 2 failed, 0 succeeded in 00:00:01.760 =============================================================
The terminal process "pio 'test'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

What is interesting is that the build passes: (if fails on Native because it misses Arduino.h, but that kind of makes sense)

Building in release mode
Compiling .pio/build/native/src/main.o
src/main.cpp:1:10: fatal error: 'Arduino.h' file not found
#include <Arduino.h>
         ^~~~~~~~~~~
1 error generated.
*** [.pio/build/native/src/main.o] Error 1
================================================================== [FAILED] Took 0.46 seconds ==================================================================

Environment    Status    Duration
-------------  --------  ------------
uno            SUCCESS   00:00:04.685
native         FAILED    00:00:00.456
============================================================ 1 failed, 1 succeeded in 00:00:05.141 ============================================================
The terminal process "pio 'run'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

I think there’s some issue with C declarations of functions with extern "C" that might happen somwehere. Are the files in lib/ and test/ available for review?

@maxgerhardt,
here: https://github.com/eduardoarantes/universal_remote_control

Another thing I just found out is that the configuration on the c_cpp_properties.json seems incomplete

it has entries for the uno environment but not the native on the “includePath”

/universal_remote_control/.pio/libdeps

I am not sure it’s relevant

//
// !!! WARNING !!! AUTO-GENERATED FILE!
// PLEASE DO NOT MODIFY IT AND USE “platformio.ini”:
// Redirecting...
//
{
“configurations”: [
{
“name”: “PlatformIO”,
“includePath”: [
“/Users/eduardo/Documents/arduino/Projetos/remote_control/universal_remote_control/include”,
“/Users/eduardo/Documents/arduino/Projetos/remote_control/universal_remote_control/src”,
“/Users/eduardo/Documents/arduino/Projetos/remote_control/universal_remote_control/.pio/libdeps/uno/AUnit/src”,
“/Users/eduardo/Documents/arduino/Projetos/remote_control/universal_remote_control/.pio/libdeps/uno/IonDB/src”,
“/Users/eduardo/Documents/arduino/Projetos/remote_control/universal_remote_control/.pio/libdeps/uno/SD”,
“/Users/eduardo/.platformio/packages/framework-arduino-avr/libraries/SPI/src”,
“/Users/eduardo/Documents/arduino/Projetos/remote_control/universal_remote_control/.pio/libdeps/uno/IRremote/src”,
“/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino”,
“/Users/eduardo/.platformio/packages/framework-arduino-avr/variants/standard”,
“/Users/eduardo/Documents/arduino/Projetos/remote_control/universal_remote_control/lib/UniversalRemoteControl/src”,
“/Users/eduardo/.platformio/packages/framework-arduino-avr/libraries/EEPROM/src”,
“/Users/eduardo/.platformio/packages/framework-arduino-avr/libraries/HID/src”,
“/Users/eduardo/.platformio/packages/framework-arduino-avr/libraries/SoftwareSerial/src”,
“/Users/eduardo/.platformio/packages/framework-arduino-avr/libraries/Wire/src”,
“/Users/eduardo/.platformio/packages/tool-unity”,
“”
],
“browse”: {
“limitSymbolsToIncludedHeaders”: true,
“path”: [
“/Users/eduardo/Documents/arduino/Projetos/remote_control/universal_remote_control/include”,
“/Users/eduardo/Documents/arduino/Projetos/remote_control/universal_remote_control/src”,
“/Users/eduardo/Documents/arduino/Projetos/remote_control/universal_remote_control/.pio/libdeps/uno/AUnit/src”,
“/Users/eduardo/Documents/arduino/Projetos/remote_control/universal_remote_control/.pio/libdeps/uno/IonDB/src”,
“/Users/eduardo/Documents/arduino/Projetos/remote_control/universal_remote_control/.pio/libdeps/uno/SD”,
“/Users/eduardo/.platformio/packages/framework-arduino-avr/libraries/SPI/src”,
“/Users/eduardo/Documents/arduino/Projetos/remote_control/universal_remote_control/.pio/libdeps/uno/IRremote/src”,
“/Users/eduardo/.platformio/packages/framework-arduino-avr/cores/arduino”,
“/Users/eduardo/.platformio/packages/framework-arduino-avr/variants/standard”,
“/Users/eduardo/Documents/arduino/Projetos/remote_control/universal_remote_control/lib/UniversalRemoteControl/src”,
“/Users/eduardo/.platformio/packages/framework-arduino-avr/libraries/EEPROM/src”,
“/Users/eduardo/.platformio/packages/framework-arduino-avr/libraries/HID/src”,
“/Users/eduardo/.platformio/packages/framework-arduino-avr/libraries/SoftwareSerial/src”,
“/Users/eduardo/.platformio/packages/framework-arduino-avr/libraries/Wire/src”,
“/Users/eduardo/.platformio/packages/tool-unity”,
“”
]
},
“defines”: [
“PLATFORMIO=50004”,
“ARDUINO_AVR_UNO”,
“F_CPU=16000000L”,
“ARDUINO_ARCH_AVR”,
“ARDUINO=10808”,
AVR_ATmega328P”,
“”
],
“cStandard”: “c11”,
“cppStandard”: “c++11”,
“compilerPath”: “/Users/eduardo/.platformio/packages/toolchain-atmelavr/bin/avr-gcc”,
“compilerArgs”: [
“-mmcu=atmega328p”,
“”
]
}
],
“version”: 4
}

@maxgerhardt,

I tried to create a project from scratch using CLI and it still doesn’t work