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(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"); } } }