test: hectic C: fix logger test

This commit is contained in:
2025-04-12 15:38:06 +00:00
parent 1f25c4fcad
commit 8981af315c
7 changed files with 19 additions and 9 deletions

View File

@@ -172,7 +172,7 @@ char* raise_message(
strftime(timeStr, sizeof(timeStr), "%Y-%m-%d %H:%M:%S", &tm_info); strftime(timeStr, sizeof(timeStr), "%Y-%m-%d %H:%M:%S", &tm_info);
// Print timestamp, log level with color, location info // Print timestamp, log level with color, location info
fprintf(stderr, "%s %s%s%s [%s:%s:%s%d%s] ", fprintf(stderr, "%s %s%s%s %s:%s:%s%d%s ",
timeStr, timeStr,
log_level_to_color(level), log_level_to_color(level),
log_level_to_string(level), log_level_to_string(level),

View File

@@ -143,6 +143,10 @@ case "$MODE" in
env LOG_LEVEL="$LOG_LEVEL" gdb -tui "$exe" env LOG_LEVEL="$LOG_LEVEL" gdb -tui "$exe"
fi fi
env LOG_LEVEL="$LOG_LEVEL" "$exe" env LOG_LEVEL="$LOG_LEVEL" "$exe"
if [ $? -ne 0 ]; then
exit 1
fi
fi fi
done done
;; ;;

View File

@@ -20,13 +20,13 @@
stderr = orig_stderr; \ stderr = orig_stderr; \
fclose(temp); \ fclose(temp); \
char expected_buffer[256]; \ char expected_buffer[256]; \
sprintf(expected_buffer, "%s " LEVEL_STR " " __FILE__ ":%d message\n", time_str, __LINE__); \ const char* func = __func__; \
printf("DEBUG: [%s] [%s]\n", result_buffer, expected_buffer); \ sprintf(expected_buffer, "%s " LEVEL_STR " " __FILE__ ":%s:%d message\n", time_str, func, __LINE__); \
assert(strcmp(result_buffer, expected_buffer) == 0); \ assert(strcmp(result_buffer, expected_buffer) == 0); \
} while(0) } while(0)
int main(void) { int main(void) {
printf("Running %s\n", __FILE__); printf("%sRunning %s%s%s\n", OPTIONAL_COLOR(COLOR_GREEN), OPTIONAL_COLOR(COLOR_CYAN), __FILE__, OPTIONAL_COLOR(COLOR_RESET));
TEST_RAISE_GENERIC(raise_debug, LOG_LEVEL_DEBUG, "DEBUG"); TEST_RAISE_GENERIC(raise_debug, LOG_LEVEL_DEBUG, "DEBUG");
TEST_RAISE_GENERIC(raise_log, LOG_LEVEL_LOG, "LOG"); TEST_RAISE_GENERIC(raise_log, LOG_LEVEL_LOG, "LOG");
@@ -35,6 +35,6 @@ int main(void) {
TEST_RAISE_GENERIC(raise_warn, LOG_LEVEL_WARN, "WARN"); TEST_RAISE_GENERIC(raise_warn, LOG_LEVEL_WARN, "WARN");
TEST_RAISE_GENERIC(raise_exception, LOG_LEVEL_EXCEPTION, "EXCEPTION"); TEST_RAISE_GENERIC(raise_exception, LOG_LEVEL_EXCEPTION, "EXCEPTION");
printf("%s%s all tests passed.%s\n", OPTIONAL_COLOR(COLOR_GREEN), __FILE__, OPTIONAL_COLOR(COLOR_RESET)); printf("%sall tests passed.%s%s%s\n", OPTIONAL_COLOR(COLOR_GREEN), OPTIONAL_COLOR(COLOR_CYAN), __FILE__, OPTIONAL_COLOR(COLOR_RESET));
return 0; return 0;
} }

View File

@@ -91,6 +91,7 @@ void test_arena_overwrite_detection() {
} }
int main() { int main() {
printf("%sRunning %s%s%s\n", OPTIONAL_COLOR(COLOR_GREEN), OPTIONAL_COLOR(COLOR_CYAN), __FILE__, OPTIONAL_COLOR(COLOR_RESET));
init_logger(); init_logger();
test_arena_init(); test_arena_init();
@@ -101,5 +102,7 @@ int main() {
test_arena_strdup(); test_arena_strdup();
test_arena_repstr(); test_arena_repstr();
test_arena_overwrite_detection(); test_arena_overwrite_detection();
printf("%s%s all tests passed.%s\n", OPTIONAL_COLOR(COLOR_GREEN), __FILE__, OPTIONAL_COLOR(COLOR_RESET));
printf("%sall tests passed.%s%s%s\n", OPTIONAL_COLOR(COLOR_GREEN), OPTIONAL_COLOR(COLOR_CYAN), __FILE__, OPTIONAL_COLOR(COLOR_RESET));
return 0;
} }

View File

@@ -124,6 +124,7 @@ static void test_arena_reset_reuse(void) {
} }
int main(void) { int main(void) {
printf("%sRunning %s%s%s\n", OPTIONAL_COLOR(COLOR_GREEN), OPTIONAL_COLOR(COLOR_CYAN), __FILE__, OPTIONAL_COLOR(COLOR_RESET));
init_logger(); init_logger();
test_parse_json_object(); test_parse_json_object();
@@ -136,6 +137,6 @@ int main(void) {
test_nested_json_object(); test_nested_json_object();
test_arena_reset_reuse(); test_arena_reset_reuse();
printf("%s%s all tests passed.%s\n", OPTIONAL_COLOR(COLOR_GREEN), __FILE__, OPTIONAL_COLOR(COLOR_RESET)); printf("%sall tests passed.%s%s%s\n", OPTIONAL_COLOR(COLOR_GREEN), OPTIONAL_COLOR(COLOR_CYAN), __FILE__, OPTIONAL_COLOR(COLOR_RESET));
return 0; return 0;
} }

View File

@@ -83,6 +83,7 @@ void test_slice_string() {
} }
int main() { int main() {
printf("%sRunning %s%s%s\n", OPTIONAL_COLOR(COLOR_GREEN), OPTIONAL_COLOR(COLOR_CYAN), __FILE__, OPTIONAL_COLOR(COLOR_RESET));
init_logger(); init_logger();
test_slice_create(); test_slice_create();
@@ -91,6 +92,6 @@ int main() {
test_slice_edge_cases(); test_slice_edge_cases();
test_slice_string(); test_slice_string();
printf("%s%s all tests passed.%s\n", OPTIONAL_COLOR(COLOR_GREEN), __FILE__, OPTIONAL_COLOR(COLOR_RESET)); printf("%sall tests passed.%s%s%s\n", OPTIONAL_COLOR(COLOR_GREEN), OPTIONAL_COLOR(COLOR_CYAN), __FILE__, OPTIONAL_COLOR(COLOR_RESET));
return 0; return 0;
} }

View File

@@ -70,6 +70,7 @@ static void test_template_node_to_debug_str(Arena *arena) {
//} //}
int main(void) { int main(void) {
printf("%sRunning %s%s%s\n", OPTIONAL_COLOR(COLOR_GREEN), OPTIONAL_COLOR(COLOR_CYAN), __FILE__, OPTIONAL_COLOR(COLOR_RESET));
init_logger(); init_logger();
Arena arena = arena_init(ARENA_SIZE); Arena arena = arena_init(ARENA_SIZE);
@@ -87,6 +88,6 @@ int main(void) {
//arena_reset(&arena); //arena_reset(&arena);
arena_free(&arena); arena_free(&arena);
printf("%s%s all tests passed.%s\n", OPTIONAL_COLOR(COLOR_GREEN), __FILE__, OPTIONAL_COLOR(COLOR_RESET)); printf("%sall tests passed.%s%s%s\n", OPTIONAL_COLOR(COLOR_GREEN), OPTIONAL_COLOR(COLOR_CYAN), __FILE__, OPTIONAL_COLOR(COLOR_RESET));
return 0; return 0;
} }