From 94df2efe2d2221bf0c4d77510142c95283d76f2b Mon Sep 17 00:00:00 2001 From: Alice Frosi Date: Wed, 10 May 2023 15:19:49 +0200 Subject: Clean-up error message and test Refactoring error messages: - standardize error messages and functions - return on error instead of exit - test error when target doesn't exist - include ability to capture stderr and stdout in the tests --- tests/unit/util.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests/unit/util.c') diff --git a/tests/unit/util.c b/tests/unit/util.c index 45171f2..5c36c54 100644 --- a/tests/unit/util.c +++ b/tests/unit/util.c @@ -30,6 +30,8 @@ int pipefd[2]; pid_t pid; char path[PATH_MAX] = "/tmp/test-seitan"; struct gluten gluten; +char stderr_buff[BUFSIZ]; +char stdout_buff[BUFSIZ]; int install_notification_filter(struct args_target *at) { @@ -231,3 +233,19 @@ void teardown() munmap(at, sizeof(struct args_target)); unlink(path); } + +void ck_stderr() +{ + setbuf(stderr, stderr_buff); +} + +void ck_stdout() +{ + setbuf(stdout, stdout_buff); +} + +void ck_error_msg(char *s) +{ + ck_assert_msg(strstr(stderr_buff, s) != NULL, "err=\"%s\" doesn't contain \"%s\" ", + stderr_buff, s); +} -- cgit v1.2.3