diff --git a/src/check.c b/src/check.c index 9f9b251c..b2c31cf6 100644 --- a/src/check.c +++ b/src/check.c @@ -68,6 +68,8 @@ Suite *suite_create(const char *name) else s->name = name; s->tclst = check_list_create(); + s->unch_sflst = check_list_create(); + s->unch_tflst = check_list_create(); return s; } @@ -102,6 +104,8 @@ static void suite_free(Suite * s) tcase_free((TCase *)check_list_val(l)); } check_list_free(s->tclst); + check_list_apply(s->unch_sflst, free); + check_list_apply(s->unch_tflst, free); free(s); } @@ -276,6 +280,22 @@ static Fixture *fixture_create(SFun fun, int ischecked) return f; } +void suite_add_unchecked_fixture(Suite * s, SFun setup, SFun teardown) +{ + if(setup) + { + check_list_add_end(s->unch_sflst, + fixture_create(setup, 0)); + } + + /* Add teardowns at front so they are run in reverse order. */ + if(teardown) + { + check_list_add_front(s->unch_tflst, + fixture_create(teardown, 0)); + } +} + void tcase_add_unchecked_fixture(TCase * tc, SFun setup, SFun teardown) { tcase_add_fixture(tc, setup, teardown, 0); diff --git a/src/check.h.in b/src/check.h.in index d5467279..f87d9171 100644 --- a/src/check.h.in +++ b/src/check.h.in @@ -308,6 +308,22 @@ CK_DLL_EXP void CK_EXPORT _tcase_add_test(TCase * tc, const TTest * ttest, int _signal, int allowed_exit_value, int start, int end); +/** + * Add unchecked fixture setup/teardown functions to a suite + * + * TODO: Detailed documentation + * TODO: Update `@since` + * + * @param s suite to add unchecked fixture setup/teardown to + * @param setup function to add to be executed before the suite; + * if NULL no setup function is added + * @param teardown function to add to be executed after the suite; + * if NULL no teardown function is added + * @since 0.12.0 + */ +CK_DLL_EXP void CK_EXPORT suite_add_unchecked_fixture(Suite * s, SFun setup, + SFun teardown); + /** * Add unchecked fixture setup/teardown functions to a test case * diff --git a/src/check_impl.h b/src/check_impl.h index f4e8c590..baa7f143 100644 --- a/src/check_impl.h +++ b/src/check_impl.h @@ -47,6 +47,8 @@ struct Suite { const char *name; List *tclst; /* List of test cases */ + List *unch_sflst; + List *unch_tflst; }; typedef struct Fixture