From 291d25927c970f4e9e2d14a2d79a504cfbcdb528 Mon Sep 17 00:00:00 2001 From: jlamothe Date: Sun, 19 Nov 2023 20:44:14 +0000 Subject: [PATCH] refactored single_test_context_with() --- 9unit.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/9unit.c b/9unit.c index cce62cd..ace5fe5 100644 --- a/9unit.c +++ b/9unit.c @@ -57,9 +57,9 @@ struct TestContextWith void *val; // the value being passed in }; +// data needed by single_test_context_with() struct SingleTestContextWith { - void *ptr; TestResult (*test)(TestState *, void *); void *val; }; @@ -84,7 +84,7 @@ static void display_context(TestState *); static void restore_context(TestState *, ContextData *); static void single_test_context_test(TestState *, void *); static void test_context_with_test(TestState *); -static TestResult single_test_context_with_test(TestState *); +static void single_test_context_with_test(TestState *, void *); static void check_value_test(TestState *, void *); // Public Functions @@ -241,14 +241,15 @@ single_test_context_with( void *val ) { - if (!s) return; - if (!test) single_test_context(s, context, 0); SingleTestContextWith d; - d.ptr = s->ptr; d.test = test; d.val = val; - s->ptr = &d; - single_test_context(s, context, single_test_context_with_test); + test_context_with( + s, + context, + single_test_context_with_test, + &d + ); } void @@ -386,12 +387,11 @@ single_test_context_test(TestState *s, void *test) run_test(s, test); } -static TestResult -single_test_context_with_test(TestState *s) +static void +single_test_context_with_test(TestState *s, void *ptr) { - SingleTestContextWith *d = s->ptr; - s->ptr = d->ptr; - return (*d->test)(s, d->val); + SingleTestContextWith *d = ptr; + run_test_with(s, d->test, d->val); } static void