Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ jobs:
- name: Build mock binary (Makefile.mac)
run: make -f test/Makefile.mac

- name: Run unit tests (assertion-based)
run: |
make -f test/Makefile.unit
./test_unit

- name: Run celestial math tests
run: |
make -f test/Makefile.celestial
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ test_oled
test_celestial
test_neopixel
test_ring
test_unit
weather_display_mac

# Test output
Expand Down
34 changes: 34 additions & 0 deletions test/Makefile.unit
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Assertion-based unit tests for pure-logic subsystems.
# No hardware drivers, no real HTTP calls.
#
# From the project root:
# make -f test/Makefile.unit # build
# make -f test/Makefile.unit run # build + run
# make -f test/Makefile.unit clean

CXX = g++
CXXFLAGS = -std=c++17 -D_DEFAULT_SOURCE -Iinclude -Wall -Wextra -g

# Only the pure-logic source files — no LCD, OLED, SPI, I2C, ring, or main.
# test/stubs/weather_stub.cpp replaces src/weather.cpp so that
# weather_cache.cpp can be compiled without a libcurl dependency.
# An empty API key makes the stub return an invalid report immediately,
# which is how we drive the cache failure state machine in tests.
SRCS = \
src/weather_alerts.cpp \
src/weather_cache.cpp \
test/stubs/weather_stub.cpp \
src/display_rotation.cpp \
src/config.cpp

TARGET = test_unit

$(TARGET): test/test_unit.cpp $(SRCS)
$(CXX) $(CXXFLAGS) -o $(TARGET) test/test_unit.cpp $(SRCS)

run: $(TARGET)
./$(TARGET)

.PHONY: run clean
clean:
rm -f $(TARGET)
17 changes: 17 additions & 0 deletions test/stubs/weather_stub.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Replaces src/weather.cpp in the unit test build.
// No libcurl dependency — returns an invalid report for any call.
// The empty-key path is what test_weather_cache.cpp uses to drive failures.
#include "weather.h"
#include "log.h"

WeatherReport getWeatherReport(const std::string& apiKey,
const std::string& city,
std::string* /*rawResponse*/) {
WeatherReport report;
if (apiKey.empty()) {
LOG_ERROR("getWeatherReport: empty API key");
return report;
}
LOG_ERROR("getWeatherReport: no HTTP in unit-test build (key=" << city << ")");
return report;
}
Loading
Loading