refactored run_test_with()

This commit is contained in:
jlamothe 2023-11-18 19:28:40 +00:00
parent bd535791d7
commit 2011b75b7e

25
9unit.c
View File

@ -27,20 +27,12 @@
// Internal Types // Internal Types
typedef struct RunTestWith RunTestWith;
typedef struct ContextData ContextData; typedef struct ContextData ContextData;
typedef struct SingleTestContext SingleTestContext; typedef struct SingleTestContext SingleTestContext;
typedef struct TestContextWith TestContextWith; typedef struct TestContextWith TestContextWith;
typedef struct SingleTestContextWith SingleTestContextWith; typedef struct SingleTestContextWith SingleTestContextWith;
typedef struct CheckValue CheckValue; typedef struct CheckValue CheckValue;
struct RunTestWith
{
void *ptr; // state's prevoius ptr value
TestResult (*test)(TestState *, void *); // the test
void *val; // the value being passed in
};
struct ContextData struct ContextData
{ {
const char *old_c; // previous context const char *old_c; // previous context
@ -130,14 +122,7 @@ run_test_with(
void *val // the value being passed in void *val // the value being passed in
) )
{ {
if (!s) return; single_test_context_with(s, 0, test, val);
if (!test) run_test(s, 0);
RunTestWith d;
d.ptr = s->ptr;
d.test = test;
d.val = val;
s->ptr = &d;
run_test(s, run_test_with_test);
} }
void void
@ -332,14 +317,6 @@ report(const char *str)
print("%s", str); print("%s", str);
} }
static TestResult
run_test_with_test(TestState *s)
{
RunTestWith *d = s->ptr;
s->ptr = d->ptr;
return (*d->test)(s, d->val);
}
static void static void
build_new_context(TestState *s, ContextData *cd) build_new_context(TestState *s, ContextData *cd)
{ {