diff --git a/include/criterion/redirect.h b/include/criterion/redirect.h index b8a80c5..e88fc89 100644 --- a/include/criterion/redirect.h +++ b/include/criterion/redirect.h @@ -79,6 +79,18 @@ CR_END_C_API # define cr_assert_file_contents_neq_str(...) CR_EXPAND(cr_assert_redir_op_va_(CR_FAIL_ABORT_, cr_file_match_str, !=, __VA_ARGS__)) # define cr_expect_file_contents_neq_str(...) CR_EXPAND(cr_assert_redir_op_va_(CR_FAIL_CONTINUES_, cr_file_match_str, !=, __VA_ARGS__)) +# define cr_assert_stdout_eq_str(...) CR_EXPAND(cr_assert_redir_op_va_(CR_FAIL_ABORT_, cr_file_match_str, ==, cr_get_redirected_stdout(), __VA_ARGS__)) +# define cr_expect_stdout_eq_str(...) CR_EXPAND(cr_assert_redir_op_va_(CR_FAIL_CONTINUES_, cr_file_match_str, ==, cr_get_redirected_stdout(), __VA_ARGS__)) + +# define cr_assert_stdout_neq_str(...) CR_EXPAND(cr_assert_redir_op_va_(CR_FAIL_ABORT_, cr_file_match_str, !=, cr_get_redirected_stdout(), __VA_ARGS__)) +# define cr_expect_stdout_neq_str(...) CR_EXPAND(cr_assert_redir_op_va_(CR_FAIL_CONTINUES_, cr_file_match_str, !=, cr_get_redirected_stdout(), __VA_ARGS__)) + +# define cr_assert_stderr_eq_str(...) CR_EXPAND(cr_assert_redir_op_va_(CR_FAIL_ABORT_, cr_file_match_str, ==, cr_get_redirected_stderr(), __VA_ARGS__)) +# define cr_expect_stderr_eq_str(...) CR_EXPAND(cr_assert_redir_op_va_(CR_FAIL_CONTINUES_, cr_file_match_str, ==, cr_get_redirected_stderr(), __VA_ARGS__)) + +# define cr_assert_stderr_neq_str(...) CR_EXPAND(cr_assert_redir_op_va_(CR_FAIL_ABORT_, cr_file_match_str, !=, cr_get_redirected_stderr(), __VA_ARGS__)) +# define cr_expect_stderr_neq_str(...) CR_EXPAND(cr_assert_redir_op_va_(CR_FAIL_CONTINUES_, cr_file_match_str, !=, cr_get_redirected_stderr(), __VA_ARGS__)) + # ifdef __cplusplus namespace criterion { diff --git a/samples/redirect.c b/samples/redirect.c index f7ee089..9a0db12 100644 --- a/samples/redirect.c +++ b/samples/redirect.c @@ -12,19 +12,15 @@ void redirect_all_std(void) { } Test(redirect, test_outputs, .init = redirect_all_std) { - FILE* f_stdout = cr_get_redirected_stdout(); - fprintf(stdout, "foo"); fflush(stdout); - cr_assert_file_contents_eq_str(f_stdout, "foo"); - - FILE* f_stderr = cr_get_redirected_stderr(); + cr_assert_stdout_eq_str("foo"); fprintf(stderr, "bar"); fflush(stderr); - cr_assert_file_contents_eq_str(f_stderr, "bar"); + cr_assert_stderr_eq_str("bar"); } // Testing general I/O with sample command-line rot13 @@ -52,6 +48,5 @@ Test(redirect, rot13, .init = cr_redirect_stdout) { rot13_io(); - FILE* f_stdout = cr_get_redirected_stdout(); - cr_assert_file_contents_eq_str(f_stdout, "gur dhvpx oebja sbk whzcf bire gur ynml qbt"); + cr_assert_stdout_eq_str("gur dhvpx oebja sbk whzcf bire gur ynml qbt"); } diff --git a/samples/redirect.cc b/samples/redirect.cc index f87dfb8..87a25da 100644 --- a/samples/redirect.cc +++ b/samples/redirect.cc @@ -21,11 +21,8 @@ Test(redirect, test_outputs, .init = redirect_all_std) { std::cout << "foo" << std::flush; std::cerr << "bar" << std::flush; - std::FILE* f_stdout = cr_get_redirected_stdout(); - cr_assert_file_contents_eq_str(f_stdout, "foo"); - - std::FILE* f_stderr = cr_get_redirected_stderr(); - cr_assert_file_contents_eq_str(f_stderr, "bar"); + cr_assert_stdout_eq_str("foo"); + cr_assert_stderr_eq_str("bar"); } // Testing general I/O with sample command-line rot13 @@ -51,6 +48,5 @@ Test(redirect, rot13, .init = cr_redirect_stdout) { rot13_io(); - std::FILE* f_stdout = cr_get_redirected_stdout(); - cr_assert_file_contents_eq_str(f_stdout, "gur dhvpx oebja sbk whzcf bire gur ynml qbt"); + cr_assert_stdout_eq_str("gur dhvpx oebja sbk whzcf bire gur ynml qbt"); }