WIP: re-writing tests

This commit is contained in:
jlamothe 2023-11-20 04:50:42 +00:00
parent 24ed9060ba
commit 8828a8ab17
4 changed files with 92 additions and 57 deletions

View File

@ -28,90 +28,115 @@
// Internal Prototypes // Internal Prototypes
static void tests(TestState *); static TestResult initial_test_count(TestState *, void *);
decl_test(initial_test_count); static TestResult initial_pass_count(TestState *, void *);
decl_test(initial_pass_count); static TestResult initial_fail_count(TestState *, void *);
decl_test(initial_fail_count); static TestResult initial_pend_count(TestState *, void *);
decl_test(initial_pend_count); static TestResult initial_first_log(TestState *, void *);
decl_test(initial_first_log); static TestResult initial_last_log(TestState *, void *);
decl_test(initial_last_log); static TestResult initial_ptr(TestState *, void *);
decl_test(initial_ptr); static TestResult initial_context(TestState *, void *);
decl_test(initial_context); static TestResult initial_full_context(TestState *, void *);
decl_test(initial_full_context); static TestResult initial_depth(TestState *, void *);
decl_test(initial_depth); static TestResult initial_report(TestState *, void *);
decl_test(initial_report);
// Public Functions // Public Functions
void void
test_initial_state(TestState *s) test_initial_state(TestState *s, void *ptr)
{ {
single_test_context(s, "run", initial_test_count); single_test_context(s, "run", initial_test_count, ptr);
single_test_context(s, "passsed", initial_pass_count); single_test_context(s, "passsed", initial_pass_count, ptr);
single_test_context(s, "failed", initial_fail_count); single_test_context(s, "failed", initial_fail_count, ptr);
single_test_context(s, "pending", initial_pend_count); single_test_context(s, "pending", initial_pend_count, ptr);
single_test_context(s, "first_log", initial_first_log); single_test_context(s, "first_log", initial_first_log, ptr);
single_test_context(s, "last_log", initial_last_log); single_test_context(s, "last_log", initial_last_log, ptr);
single_test_context(s, "ptr", initial_ptr); single_test_context(s, "ptr", initial_ptr, ptr);
single_test_context(s, "context", initial_context); single_test_context(s, "context", initial_context, ptr);
single_test_context(s, "full_context", initial_full_context); single_test_context(s, "full_context", initial_full_context, ptr);
single_test_context(s, "depth", initial_depth); single_test_context(s, "depth", initial_depth, ptr);
single_test_context(s, "report()", initial_report); single_test_context(s, "report()", initial_report, ptr);
} }
// Internal Functions // Internal Functions
def_test(initial_test_count, s) static TestResult
initial_test_count(
TestState *s,
void *ptr
)
{ {
TestState *scpy = s->ptr; TestState *scpy = ptr;
if (scpy->run == 0) return test_success; if (scpy->run == 0) return test_success;
append_test_log(s, "initial run was nonzero"); append_test_log(s, "initial run was nonzero");
return test_failure; return test_failure;
} }
def_test(initial_pass_count, s) static TestResult
initial_pass_count(
TestState *s,
void *ptr
)
{ {
TestState *scpy = s->ptr; TestState *scpy = ptr;
print("\tpassed\n");
if (scpy->passed == 0) return test_success; if (scpy->passed == 0) return test_success;
append_test_log(s, "initial passed was nonzero"); append_test_log(s, "initial passed was nonzero");
return test_failure; return test_failure;
} }
def_test(initial_fail_count, s) static TestResult
initial_fail_count(
TestState *s,
void *ptr
)
{ {
TestState *scpy = s->ptr; TestState *scpy = ptr;
if (scpy->failed == 0) return test_success; if (scpy->failed == 0) return test_success;
append_test_log(s, "initial failed was nonzero"); append_test_log(s, "initial failed was nonzero");
return test_failure; return test_failure;
} }
def_test(initial_pend_count, s) static TestResult
initial_pend_count(
TestState *s,
void *ptr
)
{ {
TestState *scpy = s->ptr; TestState *scpy = ptr;
print("\tpending\n");
if (scpy->pending == 0) return test_success; if (scpy->pending == 0) return test_success;
append_test_log(s, "initial pending was nonzero"); append_test_log(s, "initial pending was nonzero");
return test_failure; return test_failure;
} }
def_test(initial_first_log, s) static TestResult
initial_first_log(
TestState *s,
void *ptr
)
{ {
TestState *scpy = s->ptr; TestState *scpy = ptr;
if (scpy->first_log == 0) return test_success; if (scpy->first_log == 0) return test_success;
append_test_log(s, "initial first_log was not null"); append_test_log(s, "initial first_log was not null");
return test_failure; return test_failure;
} }
def_test(initial_last_log, s) static TestResult
initial_last_log(
TestState *s,
void *ptr
)
{ {
TestState *scpy = s->ptr; TestState *scpy = ptr;
if (scpy->last_log == 0) return test_success; if (scpy->last_log == 0) return test_success;
append_test_log(s, "initial last_log was not null"); append_test_log(s, "initial last_log was not null");
return test_failure; return test_failure;
} }
def_test(initial_ptr, s) static TestResult
initial_ptr(
TestState *s,
void *ptr
)
{ {
TestState *scpy = s->ptr; TestState *scpy = s->ptr;
if (scpy->ptr == 0) return test_success; if (scpy->ptr == 0) return test_success;
@ -119,31 +144,47 @@ def_test(initial_ptr, s)
return test_failure; return test_failure;
} }
def_test(initial_context, s) static TestResult
initial_context(
TestState *s,
void *ptr
)
{ {
TestState *scpy = s->ptr; TestState *scpy = ptr;
if (scpy->context == 0) return test_success; if (scpy->context == 0) return test_success;
append_test_log(s, "initial context was not null"); append_test_log(s, "initial context was not null");
return test_failure; return test_failure;
} }
def_test(initial_full_context, s) static TestResult
initial_full_context(
TestState *s,
void *ptr
)
{ {
TestState *scpy = s->ptr; TestState *scpy = ptr;
if (scpy->context == 0) return test_success; if (scpy->context == 0) return test_success;
append_test_log(s, "initial full_context was not null"); append_test_log(s, "initial full_context was not null");
return test_failure; return test_failure;
} }
def_test(initial_depth, s) static TestResult
initial_depth(
TestState *s,
void *ptr
)
{ {
TestState *scpy = s->ptr; TestState *scpy = ptr;
if (scpy->depth == 0) return test_success; if (scpy->depth == 0) return test_success;
append_test_log(s, "initial depth was not zero"); append_test_log(s, "initial depth was not zero");
return test_failure; return test_failure;
} }
def_test(initial_report, s) static TestResult
initial_report(
TestState *s,
void *ptr
)
{ {
TestState *scpy = s->ptr; TestState *scpy = s->ptr;
if (scpy->report != 0) return test_success; if (scpy->report != 0) return test_success;

View File

@ -19,6 +19,6 @@
*/ */
void test_initial_state(TestState *); void test_initial_state(TestState *, void *);
//jl //jl

View File

@ -48,14 +48,13 @@ tests(TestState *s)
{ {
if (!s) exits("ERROR: no TestState"); if (!s) exits("ERROR: no TestState");
// Make a copy of the initial TestState and store it // Make a copy of the initial TestState
TestState scpy; TestState scpy;
memcpy(&scpy, s, sizeof(TestState)); memcpy(&scpy, s, sizeof(TestState));
s->ptr = &scpy;
test_context(s, "initial state", test_initial_state); test_context_with(s, "initial state", test_initial_state, &scpy);
test_run_test(s); test_context(s, "test_run()", test_run_test);
test_append_test_log(s); test_context(s, "append_test_log()", test_append_test_log);
test_context(s, "test_context()", test_test_context); test_context(s, "test_context()", test_test_context);
} }

View File

@ -19,11 +19,6 @@
*/ */
#define STR_BUF_SIZE 256 // buffer size for constructing arbitrary strings
#define decl_test(n) static TestResult n(TestState *)
#define def_test(n, s) static TestResult n(TestState *s)
// initializes a sample TestState value // initializes a sample TestState value
void mk_sample_state(TestState *); void mk_sample_state(TestState *);