From 8828a8ab173824cdede4f79ddba1b2c81d1237d2 Mon Sep 17 00:00:00 2001 From: jlamothe Date: Mon, 20 Nov 2023 04:50:42 +0000 Subject: [PATCH] WIP: re-writing tests --- test/initial-state.c | 133 ++++++++++++++++++++++++++++--------------- test/initial-state.h | 2 +- test/tests.c | 9 ++- test/util.h | 5 -- 4 files changed, 92 insertions(+), 57 deletions(-) diff --git a/test/initial-state.c b/test/initial-state.c index 44b3c23..d19f67f 100644 --- a/test/initial-state.c +++ b/test/initial-state.c @@ -28,90 +28,115 @@ // Internal Prototypes -static void tests(TestState *); -decl_test(initial_test_count); -decl_test(initial_pass_count); -decl_test(initial_fail_count); -decl_test(initial_pend_count); -decl_test(initial_first_log); -decl_test(initial_last_log); -decl_test(initial_ptr); -decl_test(initial_context); -decl_test(initial_full_context); -decl_test(initial_depth); -decl_test(initial_report); +static TestResult initial_test_count(TestState *, void *); +static TestResult initial_pass_count(TestState *, void *); +static TestResult initial_fail_count(TestState *, void *); +static TestResult initial_pend_count(TestState *, void *); +static TestResult initial_first_log(TestState *, void *); +static TestResult initial_last_log(TestState *, void *); +static TestResult initial_ptr(TestState *, void *); +static TestResult initial_context(TestState *, void *); +static TestResult initial_full_context(TestState *, void *); +static TestResult initial_depth(TestState *, void *); +static TestResult initial_report(TestState *, void *); // Public Functions 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, "passsed", initial_pass_count); - single_test_context(s, "failed", initial_fail_count); - single_test_context(s, "pending", initial_pend_count); - single_test_context(s, "first_log", initial_first_log); - single_test_context(s, "last_log", initial_last_log); - single_test_context(s, "ptr", initial_ptr); - single_test_context(s, "context", initial_context); - single_test_context(s, "full_context", initial_full_context); - single_test_context(s, "depth", initial_depth); - single_test_context(s, "report()", initial_report); + single_test_context(s, "run", initial_test_count, ptr); + single_test_context(s, "passsed", initial_pass_count, ptr); + single_test_context(s, "failed", initial_fail_count, ptr); + single_test_context(s, "pending", initial_pend_count, ptr); + single_test_context(s, "first_log", initial_first_log, ptr); + single_test_context(s, "last_log", initial_last_log, ptr); + single_test_context(s, "ptr", initial_ptr, ptr); + single_test_context(s, "context", initial_context, ptr); + single_test_context(s, "full_context", initial_full_context, ptr); + single_test_context(s, "depth", initial_depth, ptr); + single_test_context(s, "report()", initial_report, ptr); } // 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; append_test_log(s, "initial run was nonzero"); return test_failure; } -def_test(initial_pass_count, s) +static TestResult +initial_pass_count( + TestState *s, + void *ptr +) { - TestState *scpy = s->ptr; - print("\tpassed\n"); + TestState *scpy = ptr; if (scpy->passed == 0) return test_success; append_test_log(s, "initial passed was nonzero"); 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; append_test_log(s, "initial failed was nonzero"); return test_failure; } -def_test(initial_pend_count, s) +static TestResult +initial_pend_count( + TestState *s, + void *ptr +) { - TestState *scpy = s->ptr; - print("\tpending\n"); + TestState *scpy = ptr; if (scpy->pending == 0) return test_success; append_test_log(s, "initial pending was nonzero"); 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; append_test_log(s, "initial first_log was not null"); 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; append_test_log(s, "initial last_log was not null"); return test_failure; } -def_test(initial_ptr, s) +static TestResult +initial_ptr( + TestState *s, + void *ptr +) { TestState *scpy = s->ptr; if (scpy->ptr == 0) return test_success; @@ -119,31 +144,47 @@ def_test(initial_ptr, s) 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; append_test_log(s, "initial context was not null"); 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; append_test_log(s, "initial full_context was not null"); 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; append_test_log(s, "initial depth was not zero"); return test_failure; } -def_test(initial_report, s) +static TestResult +initial_report( + TestState *s, + void *ptr +) { TestState *scpy = s->ptr; if (scpy->report != 0) return test_success; diff --git a/test/initial-state.h b/test/initial-state.h index eb4d374..d528515 100644 --- a/test/initial-state.h +++ b/test/initial-state.h @@ -19,6 +19,6 @@ */ -void test_initial_state(TestState *); +void test_initial_state(TestState *, void *); //jl diff --git a/test/tests.c b/test/tests.c index 41cf4ef..5ce42c7 100644 --- a/test/tests.c +++ b/test/tests.c @@ -48,14 +48,13 @@ tests(TestState *s) { 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; memcpy(&scpy, s, sizeof(TestState)); - s->ptr = &scpy; - test_context(s, "initial state", test_initial_state); - test_run_test(s); - test_append_test_log(s); + test_context_with(s, "initial state", test_initial_state, &scpy); + test_context(s, "test_run()", test_run_test); + test_context(s, "append_test_log()", test_append_test_log); test_context(s, "test_context()", test_test_context); } diff --git a/test/util.h b/test/util.h index 8ab30e9..b342d5d 100644 --- a/test/util.h +++ b/test/util.h @@ -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 void mk_sample_state(TestState *);