restructured library to hide struct initialization
This commit is contained in:
39
9unit.c
39
9unit.c
@@ -19,26 +19,23 @@
|
||||
*/
|
||||
|
||||
#include <u.h>
|
||||
#include <libc.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "9unit.h"
|
||||
|
||||
void
|
||||
initTestState(TestState *s)
|
||||
{
|
||||
if (!s) return;
|
||||
s->run = 0;
|
||||
s->passed = 0;
|
||||
s->failed = 0;
|
||||
s->postponed = 0;
|
||||
}
|
||||
// Internal Prototypes
|
||||
|
||||
static void init_TestState(TestState *s);
|
||||
|
||||
// Public Functions
|
||||
|
||||
void
|
||||
runTest(TestState *s, TestResult (*t)(void))
|
||||
run_test(TestState *s, TestResult (*t)(TestState *))
|
||||
{
|
||||
if (!(s && t)) return;
|
||||
s->run++;
|
||||
switch ((*t)())
|
||||
switch ((*t)(s))
|
||||
{
|
||||
case test_success:
|
||||
s->passed++;
|
||||
@@ -49,15 +46,17 @@ runTest(TestState *s, TestResult (*t)(void))
|
||||
case test_postponed:
|
||||
s->postponed++;
|
||||
break;
|
||||
default:
|
||||
exits("test returned an invalid response");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
runTests(void (*tests)(TestState *))
|
||||
run_tests(void (*tests)(TestState *))
|
||||
{
|
||||
if(!tests) return;
|
||||
TestState s;
|
||||
initTestState(&s);
|
||||
init_TestState(&s);
|
||||
(*tests)(&s);
|
||||
printf("Tests run: %d\n", s.run);
|
||||
printf("Tests passed: %d\n", s.passed);
|
||||
@@ -65,4 +64,18 @@ runTests(void (*tests)(TestState *))
|
||||
printf("Tests postponed: %d\n", s.postponed);
|
||||
}
|
||||
|
||||
// Internal Functions
|
||||
|
||||
static void
|
||||
init_TestState(TestState *s)
|
||||
{
|
||||
if (!s) return;
|
||||
s->run = 0;
|
||||
s->passed = 0;
|
||||
s->failed = 0;
|
||||
s->postponed = 0;
|
||||
s->first_log = 0;
|
||||
s->last_log = 0;
|
||||
}
|
||||
|
||||
//jl
|
||||
|
||||
Reference in New Issue
Block a user