From 22679c1e0a781f32b493e15992259bffeb884aa1 Mon Sep 17 00:00:00 2001 From: Mosder Date: Mon, 10 Aug 2026 20:11:13 +0200 Subject: feat: added ability to suppress and unsuppress outputs in tester (removed 2>/dev/null from run_tests thanks to that) --- tests/ds/array_tests.c | 6 +++--- tests/mem/alloc_tests.c | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/ds/array_tests.c b/tests/ds/array_tests.c index d674066..a9d4ec7 100644 --- a/tests/ds/array_tests.c +++ b/tests/ds/array_tests.c @@ -90,7 +90,7 @@ Test getting_items() { arr_append(arr, (struct test){0}); test_assert(arr_first(arr) == arr_last(arr), "first and last are different for array of length 1"); - arr_append(arr, (struct test){1}); + arr_append(arr, (struct test){1, 1}); test_assert(arr_first(arr) != arr_last(arr), "first and last are the same for array of length >1"); struct test *next_first = arr_next(arr, NULL); @@ -114,7 +114,7 @@ Test getting_items() { Test deleting_items() { int *arr = NULL; - int *items = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + int items[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; arr_append_n(arr, items, 9); // {1, 2, 3, 4, 5, 6, 7, 8} @@ -160,7 +160,7 @@ Test arr_concat_test() { test_assert(index == 2, "arr_concat returned wrong index"); unsigned long expected[] = {4, 5, 1, 2, 3, 4, 5}; test_assert(arr_len(arr2) == 7, "arr_concat produced array of wrong length"); - test_assert(!memcmp(arr2, items, 7 * sizeof(unsigned long)), "arr_concat produced wrong array"); + test_assert(!memcmp(arr2, expected, 7 * sizeof(unsigned long)), "arr_concat produced wrong array"); } void ds_array_tests(Tester *tester) { diff --git a/tests/mem/alloc_tests.c b/tests/mem/alloc_tests.c index 6eb2e9c..17973c7 100644 --- a/tests/mem/alloc_tests.c +++ b/tests/mem/alloc_tests.c @@ -10,8 +10,11 @@ Test malloc_exit() { Test test_safe_malloc() { void *p = safe_malloc(1024); - test_assert(p != NULL, "Should be able to malloc 1KiB"); + test_assert(p != NULL, "Failed to malloc 1KiB"); + + suppress_output(&stderr); test_assert_exit(malloc_exit, EXIT_FAILURE); + unsuppress_outputs(); } Test realloc_exit() { @@ -22,12 +25,14 @@ Test realloc_exit() { Test test_safe_realloc() { void *p = NULL; p = safe_realloc(p, 1024); - test_assert(p != NULL, "Should be able to realloc NULL to 1KiB"); + test_assert(p != NULL, "Failed to realloc NULL to 1KiB"); p = safe_realloc(p, 4096); - test_assert(p != NULL, "Should be able to realloc 1KiB to 4KiB"); + test_assert(p != NULL, "Failed to realloc 1KiB to 4KiB"); + suppress_output(&stderr); test_assert_exit(realloc_exit, EXIT_FAILURE); + unsuppress_outputs(); } void mem_alloc_tests(Tester *tester) { -- cgit v1.2.3