refactored test_context_with()

This commit is contained in:
jlamothe 2023-11-19 04:40:19 +00:00
parent 1c4fb1e87d
commit ad4abe68e0
2 changed files with 27 additions and 26 deletions

39
9unit.c
View File

@ -49,11 +49,12 @@ struct ContextData
char *new_fc; // new full context
};
// data needed by test_context_with()
struct TestContextWith
{
void *ptr; // state's original ptr value
void *val; // the value being passed in
void (*test)(TestState *, void *); // the test function
void *val; // the value being passed in
};
struct SingleTestContextWith
@ -205,16 +206,6 @@ test_context(
else (*test)(s);
}
void
single_test_context(
TestState *s,
const char *context,
TestResult (*test)(TestState *)
)
{
test_context_with(s, context, single_test_context_test, test);
}
void
test_context_with(
TestState *s,
@ -223,15 +214,25 @@ test_context_with(
void *val
)
{
if (!(s && test)) return;
if (!s) return;
TestContextWith d;
d.ptr = s->ptr;
d.val = val;
d.test = test;
d.val = val;
s->ptr = &d;
test_context(s, context, test_context_with_test);
}
void
single_test_context(
TestState *s,
const char *context,
TestResult (*test)(TestState *)
)
{
test_context_with(s, context, single_test_context_test, test);
}
void
single_test_context_with(
TestState *s,
@ -371,12 +372,6 @@ run_test_with_test(TestState *s)
return (*d->test)(s, d->val);
}
static void
single_test_context_test(TestState *s, void *test)
{
run_test(s, test);
}
static void
test_context_with_test(TestState *s)
{
@ -385,6 +380,12 @@ test_context_with_test(TestState *s)
(*d->test)(s, d->val);
}
static void
single_test_context_test(TestState *s, void *test)
{
run_test(s, test);
}
static TestResult
single_test_context_with_test(TestState *s)
{

14
9unit.h
View File

@ -94,13 +94,6 @@ extern void test_context(
void (*)(TestState *) // the actual test
);
// Runs a single test with a context label
extern void single_test_context(
TestState *, // the current state
const char *, // a description of the context
TestResult (*)(TestState *) // the actual test
);
// Runs a test with a context and an additional input
extern void test_context_with(
TestState *, // the current state
@ -109,6 +102,13 @@ extern void test_context_with(
void * // the value being passed in
);
// Runs a single test with a context label
extern void single_test_context(
TestState *, // the current state
const char *, // a description of the context
TestResult (*)(TestState *) // the actual test
);
// Runs a single test with a context and input
extern void single_test_context_with(
TestState *, // the state