Hello!
I have test case which looks like (really, I'm testing plain C library, but it is object-oriented by design):
TEST_CASE("Implementation of some object") {
some_t *obj = lib_create_obj("arg");
REQUIRE(obj != NULL);
SECTION("Basic sanity check") {
CHECK(lib_api_1(obj) == 42);
CHECK(strcmp("arg", lib_get_obj_name(obj)) == 0);
SECTION("More advanced check") {
other_t retval = lib_api_2(obj, 1, 2, 3);
CHECK(retval == -42);
CHECK(9000 = lib_api_getter_1(obj);
CHECK(lib_api_setter_2(obj, 37) == 1);
SECTION("These checks are meaningful only if previous are Ok") {
CHECK(lib_api_getter_2(obj) == 37);
CHECK(lib_api_3(obj) == 18);
}
}
lib_free_obj(obj);
}
}
Now I need to repeat all checks for objects, created with different arguments to lib_create_obj(). What is idiomatic Catch way to do this? Copy'n'pasting TEST_CASE()s works, sure, but looks ugly. I want to keep nested structure of SECTION()s, which in reality is more complex that in this synthetic example.
--
// Lev Serebryakov