aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMosder <xmosder12@gmail.com>2026-08-10 20:11:13 +0200
committerMosder <xmosder12@gmail.com>2026-08-10 20:11:13 +0200
commit22679c1e0a781f32b493e15992259bffeb884aa1 (patch)
tree997d5c8b1bfb11de7f234b15a0ccb52fec831923 /tests
parent28f2d2789054f6dc1929086c5022d0e8dca6a3d5 (diff)
feat: added ability to suppress and unsuppress outputs in tester (removed 2>/dev/null from run_tests thanks to that)
Diffstat (limited to 'tests')
-rw-r--r--tests/ds/array_tests.c6
-rw-r--r--tests/mem/alloc_tests.c11
2 files changed, 11 insertions, 6 deletions
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) {