ATF_TC_BODY(build_cxx_o, tc) { init_and_run_h_tc(&ATF_TC_NAME(h_build_cxx_o_ok), &ATF_TC_PACK_NAME(h_build_cxx_o_ok), "stdout", "stderr"); ATF_CHECK(grep_file("stdout", "-o test.o")); ATF_CHECK(grep_file("stdout", "-c test.cpp")); init_and_run_h_tc(&ATF_TC_NAME(h_build_cxx_o_fail), &ATF_TC_PACK_NAME(h_build_cxx_o_fail), "stdout", "stderr"); ATF_CHECK(grep_file("stdout", "-o test.o")); ATF_CHECK(grep_file("stdout", "-c test.cpp")); ATF_CHECK(grep_file("stderr", "test.cpp")); ATF_CHECK(grep_file("stderr", "UNDEFINED_SYMBOL")); }
ATF_TC_BODY(build_c_o, tc) { init_and_run_h_tc(&ATF_TC_NAME(h_build_c_o_ok), &ATF_TC_PACK_NAME(h_build_c_o_ok), "stdout", "stderr"); ATF_CHECK(atf_utils_grep_file("-o test.o", "stdout")); ATF_CHECK(atf_utils_grep_file("-c test.c", "stdout")); init_and_run_h_tc(&ATF_TC_NAME(h_build_c_o_fail), &ATF_TC_PACK_NAME(h_build_c_o_fail), "stdout", "stderr"); ATF_CHECK(atf_utils_grep_file("-o test.o", "stdout")); ATF_CHECK(atf_utils_grep_file("-c test.c", "stdout")); ATF_CHECK(atf_utils_grep_file("test.c", "stderr")); ATF_CHECK(atf_utils_grep_file("UNDEFINED_SYMBOL", "stderr")); }
ATF_TC_BODY(build_cpp, tc) { init_and_run_h_tc(&ATF_TC_NAME(h_build_cpp_ok), &ATF_TC_PACK_NAME(h_build_cpp_ok), "stdout", "stderr"); ATF_CHECK(grep_file("stdout", "-o.*test.p")); ATF_CHECK(grep_file("stdout", "test.c")); ATF_CHECK(grep_file("test.p", "foo bar")); init_and_run_h_tc(&ATF_TC_NAME(h_build_cpp_fail), &ATF_TC_PACK_NAME(h_build_cpp_fail), "stdout", "stderr"); ATF_CHECK(grep_file("stdout", "-o test.p")); ATF_CHECK(grep_file("stdout", "test.c")); ATF_CHECK(grep_file("stderr", "test.c")); ATF_CHECK(grep_file("stderr", "non-existent.h")); }
static void do_require_eq_tests(const struct require_eq_test *tests) { const struct require_eq_test *t; for (t = &tests[0]; t->head != NULL; t++) { printf("Checking with %s, %s and expecting %s\n", t->v1, t->v2, t->ok ? "true" : "false"); init_and_run_h_tc("h_require", t->head, t->body); ATF_REQUIRE(exists("before")); if (t->ok) { ATF_REQUIRE(atf_utils_grep_file("^passed", "result")); ATF_REQUIRE(exists("after")); } else { ATF_REQUIRE(atf_utils_grep_file("^failed: .*macros_test.c" ":[0-9]+: %s$", "result", t->msg)); ATF_REQUIRE(!exists("after")); } ATF_REQUIRE(unlink("before") != -1); if (t->ok) ATF_REQUIRE(unlink("after") != -1); } }
static void do_check_eq_tests(const struct check_eq_test *tests) { const struct check_eq_test *t; for (t = &tests[0]; t->head != NULL; t++) { printf("Checking with %s, %s and expecting %s\n", t->v1, t->v2, t->ok ? "true" : "false"); init_and_run_h_tc("h_check", t->head, t->body); ATF_CHECK(exists("before")); ATF_CHECK(exists("after")); if (t->ok) { ATF_REQUIRE(grep_file("result", "^passed")); } else { ATF_REQUIRE(grep_file("result", "^failed")); ATF_CHECK(grep_file("error", "Check failed: .*" "macros_test.c:[0-9]+: %s$", t->msg)); } ATF_CHECK(unlink("before") != -1); ATF_CHECK(unlink("after") != -1); } }
ATF_TC_BODY(require, tc) { struct test { void (*head)(atf_tc_t *); void (*body)(const atf_tc_t *); bool value; const char *msg; bool ok; } *t, tests[] = { { H_REQUIRE_HEAD_NAME(0), H_REQUIRE_BODY_NAME(0), 0, "0 not met", false }, { H_REQUIRE_HEAD_NAME(1), H_REQUIRE_BODY_NAME(1), 1, "1 not met", true }, { H_REQUIRE_MSG_HEAD_NAME(0), H_REQUIRE_MSG_BODY_NAME(0), 0, "expected a false value", false }, { H_REQUIRE_MSG_HEAD_NAME(1), H_REQUIRE_MSG_BODY_NAME(1), 1, "expected a true value", true }, { NULL, NULL, false, NULL, false } }; for (t = &tests[0]; t->head != NULL; t++) { printf("Checking with a %d value\n", t->value); init_and_run_h_tc("h_require", t->head, t->body); ATF_REQUIRE(exists("before")); if (t->ok) { ATF_REQUIRE(atf_utils_grep_file("^passed", "result")); ATF_REQUIRE(exists("after")); } else { ATF_REQUIRE(atf_utils_grep_file( "^failed: .*macros_test.c:[0-9]+: %s$", "result", t->msg)); ATF_REQUIRE(!exists("after")); } ATF_REQUIRE(unlink("before") != -1); if (t->ok) ATF_REQUIRE(unlink("after") != -1); } }
ATF_TC_BODY(require_errno, tc) { struct test { void (*head)(atf_tc_t *); void (*body)(const atf_tc_t *); bool ok; const char *exp_regex; } *t, tests[] = { { H_REQUIRE_ERRNO_HEAD_NAME(no_error), H_REQUIRE_ERRNO_BODY_NAME(no_error), false, "Expected true value in errno_ok_stub\\(\\) == -1" }, { H_REQUIRE_ERRNO_HEAD_NAME(errno_ok), H_REQUIRE_ERRNO_BODY_NAME(errno_ok), true, NULL }, { H_REQUIRE_ERRNO_HEAD_NAME(errno_fail), H_REQUIRE_ERRNO_BODY_NAME(errno_fail), false, "Expected errno 3, got 4, in errno_fail_stub\\(4\\) == -1" }, { NULL, NULL, false, NULL } }; for (t = &tests[0]; t->head != NULL; t++) { init_and_run_h_tc("h_require_errno", t->head, t->body); ATF_REQUIRE(exists("before")); if (t->ok) { ATF_REQUIRE(atf_utils_grep_file("^passed", "result")); ATF_REQUIRE(exists("after")); } else { ATF_REQUIRE(atf_utils_grep_file( "^failed: .*macros_test.c:[0-9]+: %s$", "result", t->exp_regex)); ATF_REQUIRE(!exists("after")); } ATF_REQUIRE(unlink("before") != -1); if (t->ok) ATF_REQUIRE(unlink("after") != -1); } }
ATF_TC_BODY(msg_embedded_fmt, tc) { struct test { void (*head)(atf_tc_t *); void (*body)(const atf_tc_t *); bool fatal; const char *msg; } *t, tests[] = { { H_CHECK_HEAD_NAME(msg), H_CHECK_BODY_NAME(msg), false, "aux_bool\\(\"%d\"\\) not met" }, { H_REQUIRE_HEAD_NAME(msg), H_REQUIRE_BODY_NAME(msg), true, "aux_bool\\(\"%d\"\\) not met" }, { H_CHECK_STREQ_HEAD_NAME(msg), H_CHECK_STREQ_BODY_NAME(msg), false, "aux_str\\(\"%d\"\\) != \"\" \\(foo != \\)" }, { H_REQUIRE_STREQ_HEAD_NAME(msg), H_REQUIRE_STREQ_BODY_NAME(msg), true, "aux_str\\(\"%d\"\\) != \"\" \\(foo != \\)" }, { NULL, NULL, false, NULL } }; for (t = &tests[0]; t->head != NULL; t++) { printf("Checking with an expected '%s' message\n", t->msg); init_and_run_h_tc("h_check", t->head, t->body); if (t->fatal) { bool matched = grep_file("result", "^failed: .*macros_test.c:[0-9]+: " "%s$", t->msg); ATF_CHECK_MSG(matched, "couldn't find error string in result"); } else { bool matched = grep_file("error", "Check failed: .*" "macros_test.c:[0-9]+: %s$", t->msg); ATF_CHECK_MSG(matched, "couldn't find error string in output"); } } }