From 6a5cbab93c381d36e679b17cf5d7c126dc2fe5ba Mon Sep 17 00:00:00 2001 From: Michael Kohl Date: Fri, 6 Feb 2026 11:09:35 +0700 Subject: [PATCH] Add test for herb_read_file Document that the function exits when the filename is invalid. --- Makefile | 2 +- test/c/test_io.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6a44f0758..4638055ed 100644 --- a/Makefile +++ b/Makefile @@ -95,7 +95,7 @@ $(static_lib_name): $(objects) src/%.o: src/%.c templates $(cc) -c $(flags) -fPIC $< -o $@ -test/%.o: test/%.c templates +test/%.o: test/%.c templates prism $(cc) -c $(test_cflags) $(test_flags) $(prism_flags) $< -o $@ .PHONY: test diff --git a/test/c/test_io.c b/test/c/test_io.c index b49cab89f..52dc0ee66 100644 --- a/test/c/test_io.c +++ b/test/c/test_io.c @@ -11,6 +11,12 @@ void create_test_file(const char* filename, const char* content) { fclose(fp); } +// Test that reading a non-existent file correctly exits +// Note: Check verifies the exit code via tcase_add_exit_test, so no assertions. +TEST(test_herb_read_file_nonexistent_exits) + herb_read_file("non_existent_file.txt"); +END + // Test reading from a file TEST(test_herb_read_file) const char* filename = "test_herb_read_file.txt"; @@ -31,6 +37,7 @@ TCase* io_tests(void) { TCase* io = tcase_create("IO"); tcase_add_test(io, test_herb_read_file); + tcase_add_exit_test(io, test_herb_read_file_nonexistent_exits, 1); return io; }