Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Suite fixture feature #166

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions src/check.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
2 changes: 2 additions & 0 deletions src/check_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ struct Suite
{
const char *name;
List *tclst; /* List of test cases */
List *unch_sflst;
List *unch_tflst;
};

typedef struct Fixture
Expand Down