Added redirection assertion shortcuts for std{out,err}
This commit is contained in:
parent
0e2203df43
commit
779fbca56e
3 changed files with 18 additions and 15 deletions
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue