I’m running the tests with the command platformio test -e native -f native
. If I comment out the FastLED.h include and all the code referencing it from main.cpp my tests run and pass as the timer.cpp doesn’t reference any arduino/avr libraries. However, even with the #ifndef UNIT_TEST guard in main.cpp, with the FastLED code referenced in main.cpp it tries to compile FastLED and throws a bunch of errors. I understand why it would throw those errors if I was trying to run the native tests referencing arduino/avr libraries. But why is it not excluding the code in my main.cpp file? Am I not structuring the project correctly?
My platformio.ini
[env:uno]
platform = atmelavr
board = uno
framework = arduino
[env:native]
platform = native
test_ignore = arduino
Project Structure
<project_root>/
lib/
time/
src/
time.h
time.cpp
src/
main.cpp
test/
arduino/
test_uno.cpp
native/
test_time.cpp
//main.cpp
#ifndef UNIT_TEST
#include <Arduino.h>
#include <time.h>
#include <FastLED.h>
#include <stdint.h>
uint8_t hours;
uint8_t minutes;
uint8_t seconds;
CRGB leds[19];
#define get_bit(n, k) ((n & (1 << k)) >> k)
void update_leds(CRGB *led_arr, uint32_t value){
// ...snip
}
void setup() {
FastLED.addLeds<WS2812B, 3, GRB>(leds, 19);
time_init(&hours, &minutes, &seconds);
}
void loop() {
tick(&hours, &minutes, &seconds);
uint32_t converted_time = convert_time(hours, minutes, seconds);
update_leds(leds, converted_time);
delay(1000);
}
#endif
//test_time.cpp
#ifdef UNIT_TEST
#include <time.h>
#include <unity.h>
#include <stdio.h>
#include <stdint.h>
// ... snip tests defined here
int main(int argc, char **argv) {
UNITY_BEGIN();
//RUN_TEST here
UNITY_END();
return 0;
}
#endif