diff options
| author | Mosder <git@mosder.eu> | 2026-10-13 17:44:16 +0200 |
|---|---|---|
| committer | Mosder <git@mosder.eu> | 2026-10-13 17:44:16 +0200 |
| commit | 7698b0c7774f89b8329e898b534329f7a945cbd0 (patch) | |
| tree | 56d378f868118909eeba19ab118fdf3553f54ba6 /include | |
| parent | 2b01cab2df7273dad7f95c4349929a28331338c2 (diff) | |
refactor: changed API in tester, so the output related functions use FILE * streams insted of file descriptors
Diffstat (limited to 'include')
| -rw-r--r-- | include/moslib/tester.h | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/include/moslib/tester.h b/include/moslib/tester.h index 838341a..d2443c5 100644 --- a/include/moslib/tester.h +++ b/include/moslib/tester.h @@ -47,21 +47,21 @@ // // You can also test if a function writes correct output. // You need to create a helper test and pass it into test_assert_out in main test. -// Pass the helper test, output stream's fd, and expected output to it. +// Pass the helper test, output stream, and expected output to it. // Example: // TEST_HELPER(helper_test) { // printf("output"); // } // TEST(main_test) { -// test_assert_out(helper_test, STDOUT_FILENO, "output"); +// test_assert_out(helper_test, stdout, "output"); // } // // 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_FILENO); -// suppress_output(STDERR_FILENO); +// suppress_output(stdout); +// suppress_output(stderr); // int code = fun_that_fails_with_output(); // unsuppress_outputs(); // test_assert(code == 0, "function didn't fail"); @@ -91,6 +91,8 @@ #ifndef MOSLIB_TESTER_H #define MOSLIB_TESTER_H +#include <stdio.h> + #ifndef MOS_FORCE_PREFIXES #define TEST MOS_TEST @@ -166,20 +168,20 @@ extern void mos_test_assert(int expression, const char *fail_message); // function // function that is supposed to write output // -// fd -// file descriptor of stream to write the output to +// stream +// stream to write the output to // // output // expected output of the function -#define mos_test_assert_out(function, fd, output) \ - mos_test_assert_out_fn(function, fd, output, #function, #fd) +#define mos_test_assert_out(function, stream, output) \ + mos_test_assert_out_fn(function, stream, output, #function, #stream) // Suppress given output // // Arguments: -// fd -// file descriptor of output to suppress -#define mos_suppress_output(fd) mos_suppress_output_fn(fd) +// stream +// file stream to suppress +#define mos_suppress_output(stream) mos_suppress_output_fn(stream) // Unuppress previously suppressed outputs // Will unsupress all of the outputs that were suppressed @@ -216,9 +218,13 @@ extern void mos_free_tester(MosTester *tester); extern MosTestGroup *mos_add_test_group_fn(MosTester *tester, const char *group_name); extern void mos_test_assert_exit_fn(MosTestFn function, int code, const char *name); extern void mos_test_assert_out_fn( - MosTestFn function, int fd, const char *output, const char *fn_name, const char *fd_name + MosTestFn function, + FILE *stream, + const char *output, + const char *fn_name, + const char *stream_name ); -extern void mos_suppress_output_fn(int fd); +extern void mos_suppress_output_fn(FILE *stream); extern void mos_add_test_fn(MosTestGroup *group, MosTestFn test, const char *name); #endif // MOSLIB_TESTER_H |
