diff --git a/9unit.c b/9unit.c index 9bc4d12..da658e5 100644 --- a/9unit.c +++ b/9unit.c @@ -25,12 +25,29 @@ void initTestState(TestState *s) { - if(s) + if (!s) return; + s->run = 0; + s->success = 0; + s->failure = 0; + s->postponed = 0; +} + +void +runTest(TestState *s, TestResult (*t)(void)) +{ + if (!(s && t)) return; + s->run++; + switch ((*t)()) { - s->run = 0; - s->success = 0; - s->failure = 0; - s->postponed = 0; + case test_success: + s->success++; + break; + case test_failure: + s->failure++; + break; + case test_postponed: + s->postponed++; + break; } } diff --git a/9unit.h b/9unit.h index 616df9e..500f86a 100644 --- a/9unit.h +++ b/9unit.h @@ -31,9 +31,11 @@ typedef enum TestResult { test_success, test_failure, - test_pending + test_postponed } TestResult; extern void initTestState(TestState *); +extern void runTest(TestState *, TestResult (*)(void)); + //jl