From ad4abe68e0a0b9feb5f12e986f13f3be6e76c022 Mon Sep 17 00:00:00 2001 From: jlamothe Date: Sun, 19 Nov 2023 04:40:19 +0000 Subject: [PATCH] refactored test_context_with() --- 9unit.c | 39 ++++++++++++++++++++------------------- 9unit.h | 14 +++++++------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/9unit.c b/9unit.c index 7e08482..cce62cd 100644 --- a/9unit.c +++ b/9unit.c @@ -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) { diff --git a/9unit.h b/9unit.h index 96752b7..3cfda13 100644 --- a/9unit.h +++ b/9unit.h @@ -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