From 8981af315c67c424a67b1208610d27f5a79f5ab7 Mon Sep 17 00:00:00 2001 From: yukkop Date: Sat, 12 Apr 2025 15:38:06 +0000 Subject: [PATCH] test: `hectic` C: fix logger test --- package/c/hectic/hectic.c | 2 +- package/c/hectic/make.sh | 4 ++++ package/c/hectic/test/00-logger.c | 8 ++++---- package/c/hectic/test/03-arena.c | 5 ++++- package/c/hectic/test/04-json.c | 3 ++- package/c/hectic/test/05-slice.c | 3 ++- package/c/hectic/test/06-templater.c | 3 ++- 7 files changed, 19 insertions(+), 9 deletions(-) diff --git a/package/c/hectic/hectic.c b/package/c/hectic/hectic.c index 05ea08d..28a3b48 100644 --- a/package/c/hectic/hectic.c +++ b/package/c/hectic/hectic.c @@ -172,7 +172,7 @@ char* raise_message( strftime(timeStr, sizeof(timeStr), "%Y-%m-%d %H:%M:%S", &tm_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, log_level_to_color(level), log_level_to_string(level), diff --git a/package/c/hectic/make.sh b/package/c/hectic/make.sh index bf995c1..8fd1586 100644 --- a/package/c/hectic/make.sh +++ b/package/c/hectic/make.sh @@ -143,6 +143,10 @@ case "$MODE" in env LOG_LEVEL="$LOG_LEVEL" gdb -tui "$exe" fi env LOG_LEVEL="$LOG_LEVEL" "$exe" + + if [ $? -ne 0 ]; then + exit 1 + fi fi done ;; diff --git a/package/c/hectic/test/00-logger.c b/package/c/hectic/test/00-logger.c index 4146845..ced90ca 100644 --- a/package/c/hectic/test/00-logger.c +++ b/package/c/hectic/test/00-logger.c @@ -20,13 +20,13 @@ stderr = orig_stderr; \ fclose(temp); \ char expected_buffer[256]; \ - sprintf(expected_buffer, "%s " LEVEL_STR " " __FILE__ ":%d message\n", time_str, __LINE__); \ - printf("DEBUG: [%s] [%s]\n", result_buffer, expected_buffer); \ + const char* func = __func__; \ + sprintf(expected_buffer, "%s " LEVEL_STR " " __FILE__ ":%s:%d message\n", time_str, func, __LINE__); \ assert(strcmp(result_buffer, expected_buffer) == 0); \ } while(0) 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_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_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; } diff --git a/package/c/hectic/test/03-arena.c b/package/c/hectic/test/03-arena.c index 267657d..a7cb118 100644 --- a/package/c/hectic/test/03-arena.c +++ b/package/c/hectic/test/03-arena.c @@ -91,6 +91,7 @@ void test_arena_overwrite_detection() { } int main() { + printf("%sRunning %s%s%s\n", OPTIONAL_COLOR(COLOR_GREEN), OPTIONAL_COLOR(COLOR_CYAN), __FILE__, OPTIONAL_COLOR(COLOR_RESET)); init_logger(); test_arena_init(); @@ -101,5 +102,7 @@ int main() { test_arena_strdup(); test_arena_repstr(); 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; } diff --git a/package/c/hectic/test/04-json.c b/package/c/hectic/test/04-json.c index b75247e..693ec8a 100644 --- a/package/c/hectic/test/04-json.c +++ b/package/c/hectic/test/04-json.c @@ -124,6 +124,7 @@ static void test_arena_reset_reuse(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(); test_parse_json_object(); @@ -136,6 +137,6 @@ int main(void) { test_nested_json_object(); 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; } diff --git a/package/c/hectic/test/05-slice.c b/package/c/hectic/test/05-slice.c index e3c3d86..ba34a59 100644 --- a/package/c/hectic/test/05-slice.c +++ b/package/c/hectic/test/05-slice.c @@ -83,6 +83,7 @@ void test_slice_string() { } int main() { + printf("%sRunning %s%s%s\n", OPTIONAL_COLOR(COLOR_GREEN), OPTIONAL_COLOR(COLOR_CYAN), __FILE__, OPTIONAL_COLOR(COLOR_RESET)); init_logger(); test_slice_create(); @@ -91,6 +92,6 @@ int main() { test_slice_edge_cases(); 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; } \ No newline at end of file diff --git a/package/c/hectic/test/06-templater.c b/package/c/hectic/test/06-templater.c index ea1c8b8..cb0f512 100755 --- a/package/c/hectic/test/06-templater.c +++ b/package/c/hectic/test/06-templater.c @@ -70,6 +70,7 @@ static void test_template_node_to_debug_str(Arena *arena) { //} int main(void) { + printf("%sRunning %s%s%s\n", OPTIONAL_COLOR(COLOR_GREEN), OPTIONAL_COLOR(COLOR_CYAN), __FILE__, OPTIONAL_COLOR(COLOR_RESET)); init_logger(); Arena arena = arena_init(ARENA_SIZE); @@ -87,6 +88,6 @@ int main(void) { //arena_reset(&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; } \ No newline at end of file