diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 651e778..c757a11 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -327,3 +327,17 @@ foreach(_t IN LISTS _eboot_test_targets) endif() endforeach() +# --- printf format guard --- +# +# A format warning in a unit-test program is an error: test_boot_log once +# printed "11/ tests passed" behind a warning nobody acted on. +# Applies to the unit-test programs in this directory (and the sources they +# compile directly); the libraries, firmware and tests/fuzz are unchanged. +if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") + foreach(_t IN LISTS _eboot_test_targets) + get_target_property(_type ${_t} TYPE) + if(_type STREQUAL "EXECUTABLE") + target_compile_options(${_t} PRIVATE -Werror=format) + endif() + endforeach() +endif() diff --git a/tests/unit/test_boot_log.c b/tests/unit/test_boot_log.c index 0bde90f..c2207b8 100644 --- a/tests/unit/test_boot_log.c +++ b/tests/unit/test_boot_log.c @@ -18,6 +18,7 @@ #include #include +static int tests_run = 0; static int tests_passed = 0; #define ASSERT(condition) \ @@ -32,6 +33,7 @@ static int tests_passed = 0; #define RUN(test) \ do { \ reset_fixture(); \ + tests_run++; \ test(); \ tests_passed++; \ printf("[PASS] %s\n", #test); \ @@ -300,6 +302,6 @@ int main(void) RUN(test_clear_reports_erase_failure); RUN(test_append_does_not_advance_head_when_write_fails); RUN(test_entry_layout_is_stable); - printf("\n%d/%d tests passed\n", tests_passed); + printf("\n%d/%d tests passed\n", tests_passed, tests_run); return 0; }