consider calling run_test() with a null function as a pending test

This commit is contained in:
jlamothe 2023-11-12 01:25:55 +00:00
parent 94d6bc8cf9
commit e41263adf0
2 changed files with 39 additions and 2 deletions

10
9unit.c
View File

@ -37,8 +37,16 @@ static void reindex(TestState *);
void
run_test(TestState *s, TestResult (*t)(TestState *))
{
if (!(s && t)) return;
if (!s) return;
s->run++;
// a null test function is a pending test
if (!t)
{
s->pending++;
return;
}
switch ((*t)(s))
{
case test_success:

View File

@ -32,6 +32,7 @@ static void test_pass(TestState *);
static void test_fail(TestState *);
static void test_pend(TestState *);
static void null_state(TestState *);
static void null_test(TestState *);
decl_test(always_passes);
decl_test(always_fails);
decl_test(always_pends);
@ -46,6 +47,7 @@ test_run_test(TestState *s)
test_fail(s);
test_pend(s);
null_state(s);
null_test(s);
}
// Internal Functions
@ -129,13 +131,40 @@ test_pend(TestState *s)
}
static void
null_state(TestState *s)
null_state(TestState *)
{
print("\tnull state\n");
// make sure it doesn't crash
run_test(0, always_passes);
}
static void
null_test(TestState *s)
{
TestState actual, expected;
print("\tnull test\n");
// expected value
memset(&expected, 0, sizeof(TestState));
expected.passed = 1;
expected.failed = 2;
expected.pending = 4;
expected.run = 7;
// actual value
mk_sample_state(&actual);
run_test(&actual, 0);
chk_TestState_eq(
s,
"\t\t",
"ERROR: run_test(): null_test:",
&actual,
&expected
);
}
decl_test(always_passes)
{
return test_success;