aboutsummaryrefslogtreecommitdiff
path: root/include
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 /include
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 'include')
-rw-r--r--include/moslib/tester.h28
1 files changed, 26 insertions, 2 deletions
diff --git a/include/moslib/tester.h b/include/moslib/tester.h
index 52a9f14..b48a03a 100644
--- a/include/moslib/tester.h
+++ b/include/moslib/tester.h
@@ -30,8 +30,8 @@
// int result1 = 1 + 2;
// int result2 = 3 + 5;
//
-// test_assert(result1 == 3, "1 + 2 should equal 3");
-// test_assert(result2 == 8, "3 + 5 should equal 8");
+// test_assert(result1 == 3, "1 + 2 is not equal 3");
+// test_assert(result2 == 8, "3 + 5 is not equal 8");
// }
//
// You can also test if a function is supposed to call exit.
@@ -46,6 +46,17 @@
// test_assert_exit(helper_test, EXIT_FAILURE);
// }
//
+// If your functions have output and you want to suppress them for the sake of tests,
+// you can do so using suppress_output and unsupress_outputs.
+// Example:
+// Test error_test() {
+// suppress_output(&stdout);
+// suppress_output(&stderr);
+// int code = fun_that_fails_with_output();
+// unsuppress_outputs();
+// test_assert(code == 0, "function didn't fail");
+// }
+//
// ----------------------------------------------------------------------------------------------------
//
// Add tests to test group:
@@ -67,6 +78,8 @@
// ----------------------------------------------------------------------------------------------------
// ===================================== END OF QUICK USAGE GUIDE =====================================
+#include <stdio.h>
+
#ifndef MOSLIB_TESTER_H
#define MOSLIB_TESTER_H
@@ -117,6 +130,17 @@ extern void test_assert(int expression, const char *fail_message);
// expected exit code
#define test_assert_exit(function, code) test_assert_exit_fn((function), (code), #function);
+// Suppress given output
+//
+// Arguments:
+// out
+// pointer to outpout to suppress
+extern void suppress_output(FILE **out);
+
+// Unuppress previously suppressed outputs
+// Will unsupress all of the outputs that were suppressed
+extern void unsuppress_outputs(void);
+
// Add test to a test group
//
// Arguments: