X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/43f490c377cb05d1ac6e7d2c27a06ae940e2c047..a077a9a931a4b81abf0f549d7f463ae75075149a:/utils/t/exc-test.c diff --git a/utils/t/exc-test.c b/utils/t/exc-test.c index 89701bf..69fa8cd 100644 --- a/utils/t/exc-test.c +++ b/utils/t/exc-test.c @@ -1,44 +1,65 @@ #include + #include "exc.h" +#include "macros.h" +#include "report.h" +#include "tvec.h" +#include "tvec-adhoc.h" +#include "tvec-types.h" + +static struct tvec_state tvstate; +static int step; -void func(void) +#define TESTGROUP(name) \ + TVEC_TESTGROUP_TAG(grp, &tvstate, name) \ + MC_BEFORE(init, { step = 0; }) +#define TEST TVEC_TEST_TAG(test, &tvstate) +#define STEP(s) do { \ + tvec_claim(&tvstate, s == step, __FILE__, __LINE__, \ + "found %d /= expected %d", s, step); \ + step++; \ + } while (0) +#define MISSTEP do { \ + tvec_claim(&tvstate, 0, __FILE__, __LINE__, \ + "shouldn't have reached here"); \ + step++; \ + } while (0) + +static void func(void) { - printf("cabbage\n"); - TRY { - printf("dibble\n"); - THROW(EXC_FAIL, "excession"); - printf("can't see me\n"); - } CATCH switch (exc_type) { - case 1: - printf("exc type 1 (not possible)\n"); - break; - case EXC_FAIL: - printf("exc type 2 (%s)\n", exc_s); - break; - default: - RETHROW; + TRY { STEP(2); THROW(EXC_FAIL, "excession"); MISSTEP; } + CATCH switch (exc_type) { + case EXC_FAIL: TVEC_CLAIMEQ_TEXTZ(&tvstate, exc_s, "excession"); break; + default: MISSTEP; break; } END_TRY; - printf("fennel\n"); - THROW(EXC_ERRNO, 53); + TRY { STEP(3); THROW(EXC_ERRNO, 53); } + CATCH switch (exc_type) { + case EXC_ERRNO: RETHROW; + default: MISSTEP; break; + } END_TRY; + MISSTEP; } -int main(void) +int main(int argc, char *argv[]) { - printf("apple\n"); - TRY { - printf("banana\n"); - func(); - printf("can't see me\n"); - } CATCH switch (exc_type) { - default: - printf("%lu exception (val = %i)\n", exc_type, exc_i); - break; - } END_TRY; - printf("hello! __exc_list = "); - if (__exc_list) printf("%p", (void *)__exc_list); - else printf("(nil)"); - putchar('\n'); + int argpos; + + tvec_parseargs(argc, argv, &tvstate, &argpos, &tvec_adhocconfig); + if (argpos < argc) die(2, "no input files expected"); + + TESTGROUP("flow") { + STEP(0); + TRY { STEP(1); func(); MISSTEP; } + CATCH switch (exc_type) { + case EXC_ERRNO: STEP(4); TVEC_CLAIMEQ_INT(&tvstate, exc_i, 53); break; + default: MISSTEP; + } END_TRY; + STEP(5); + } + + TESTGROUP("final") + TVEC_CLAIMEQ_PTR(&tvstate, __exc_list, 0); - return (0); + return (tvec_end(&tvstate)); }