re-implemented test using new convenience functions
This commit is contained in:
107
test/run-test.c
107
test/run-test.c
@@ -31,23 +31,22 @@
|
||||
static void test_pass(TestState *);
|
||||
static void test_fail(TestState *);
|
||||
static void test_pend(TestState *);
|
||||
decl_test(null_state);
|
||||
static TestResult null_state(TestState *);
|
||||
static void null_test(TestState *);
|
||||
decl_test(always_passes);
|
||||
decl_test(always_fails);
|
||||
decl_test(always_pends);
|
||||
static TestResult always_passes(TestState *);
|
||||
static TestResult always_fails(TestState *);
|
||||
static TestResult always_pends(TestState *);
|
||||
|
||||
// Public Functions
|
||||
|
||||
void
|
||||
test_run_test(TestState *s)
|
||||
{
|
||||
print("run_test()\n");
|
||||
test_pass(s);
|
||||
test_fail(s);
|
||||
test_pend(s);
|
||||
run_test(s, null_state);
|
||||
null_test(s);
|
||||
test_context(s, "passing", test_pass);
|
||||
test_context(s, "failing", test_fail);
|
||||
test_context(s, "pending", test_pend);
|
||||
single_test_context(s, "null state", null_state);
|
||||
test_context(s, "null test", null_test);
|
||||
}
|
||||
|
||||
// Internal Functions
|
||||
@@ -55,78 +54,58 @@ test_run_test(TestState *s)
|
||||
static void
|
||||
test_pass(TestState *s)
|
||||
{
|
||||
TestState expected, actual;
|
||||
print("\tpassing\n");
|
||||
TestState actual, expected;
|
||||
|
||||
// actual result
|
||||
mk_sample_state(&actual);
|
||||
run_test(&actual, always_passes);
|
||||
|
||||
// expected result
|
||||
mk_sample_state(&expected);
|
||||
expected.passed = 2;
|
||||
expected.run = 7;
|
||||
|
||||
// actual result
|
||||
mk_sample_state(&actual);
|
||||
run_test(&actual, always_passes);
|
||||
|
||||
chk_TestState_eq(
|
||||
s,
|
||||
"\t\t",
|
||||
"ERROR: run_test(): passing:",
|
||||
&actual,
|
||||
&expected
|
||||
);
|
||||
chk_TestState_eq(s, 0, &actual, &expected);
|
||||
}
|
||||
|
||||
static void
|
||||
test_fail(TestState *s)
|
||||
{
|
||||
TestState expected, actual;
|
||||
print("\tfailing\n");
|
||||
TestState actual, expected;
|
||||
|
||||
// actual result
|
||||
mk_sample_state(&actual);
|
||||
run_test(&actual, always_fails);
|
||||
|
||||
// expected result
|
||||
mk_sample_state(&expected);
|
||||
expected.failed = 3;
|
||||
expected.run = 7;
|
||||
|
||||
// actual result
|
||||
mk_sample_state(&actual);
|
||||
run_test(&actual, always_fails);
|
||||
|
||||
chk_TestState_eq(
|
||||
s,
|
||||
"\t\t",
|
||||
"ERROR: run_test(): failing:",
|
||||
&expected,
|
||||
&actual
|
||||
);
|
||||
chk_TestState_eq(s, 0, &actual, &expected);
|
||||
}
|
||||
|
||||
static void
|
||||
test_pend(TestState *s)
|
||||
{
|
||||
TestState expected, actual;
|
||||
print("\tpending\n");
|
||||
TestState actual, expected;
|
||||
|
||||
// actual result
|
||||
mk_sample_state(&actual);
|
||||
run_test(&actual, always_pends);
|
||||
|
||||
// expected result
|
||||
mk_sample_state(&expected);
|
||||
expected.pending = 4;
|
||||
expected.run = 7;
|
||||
|
||||
// actual result
|
||||
mk_sample_state(&actual);
|
||||
run_test(&actual, always_pends);
|
||||
|
||||
chk_TestState_eq(
|
||||
s,
|
||||
"\t\t",
|
||||
"ERROR: run_test(): pending:",
|
||||
&expected,
|
||||
&actual
|
||||
);
|
||||
chk_TestState_eq(s, 0, &actual, &expected);
|
||||
}
|
||||
|
||||
decl_test(null_state)
|
||||
static TestResult
|
||||
null_state(TestState *)
|
||||
{
|
||||
print("\tnull state\n");
|
||||
// make sure it doesn't crash
|
||||
run_test(0, always_passes);
|
||||
return test_success;
|
||||
}
|
||||
@@ -135,37 +114,33 @@ static void
|
||||
null_test(TestState *s)
|
||||
{
|
||||
TestState actual, expected;
|
||||
print("\tnull test\n");
|
||||
|
||||
// actual value
|
||||
mk_sample_state(&actual);
|
||||
run_test(&actual, 0);
|
||||
|
||||
// expected value
|
||||
mk_sample_state(&expected);
|
||||
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
|
||||
);
|
||||
chk_TestState_eq(s, 0, &actual, &expected);
|
||||
}
|
||||
|
||||
decl_test(always_passes)
|
||||
static TestResult
|
||||
always_passes(TestState *)
|
||||
{
|
||||
return test_success;
|
||||
}
|
||||
|
||||
decl_test(always_fails)
|
||||
static TestResult
|
||||
always_fails(TestState *)
|
||||
{
|
||||
return test_failure;
|
||||
}
|
||||
|
||||
decl_test(always_pends)
|
||||
static TestResult
|
||||
always_pends(TestState *)
|
||||
{
|
||||
return test_pending;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user