From: Lukas Krickl Date: Sun, 26 Nov 2023 18:56:27 +0000 (+0100) Subject: WIP: full integration test X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=d50cc0a4bd0c6209e00892406999c0a3f34c5a94;p=ulas%2F.git WIP: full integration test --- diff --git a/src/test.c b/src/test.c index 1fbdfc6..27acf57 100644 --- a/src/test.c +++ b/src/test.c @@ -301,10 +301,35 @@ void test_asminstr(void) { TESTEND("asminstr"); } +#define ULAS_FULLEN 0xFFFF + +#define ASSERT_FULL(expect_len, expect_rc, in_path, ...) \ + { \ + ulaslstout = stdout; \ + struct ulas_config cfg = ulas_cfg_from_env(); \ + char dstbuf[ULAS_FULLEN]; \ + char expect[] = {__VA_ARGS__}; \ + memset(dstbuf, 0, ULAS_FULLEN); \ + ulasout = fmemopen(dstbuf, ULAS_FULLEN, "we"); \ + ulasin = fopen(in_path, "re"); \ + assert(ulas_main(cfg) == expect_rc); \ + fclose(ulasout); \ + for (int i = 0; i < expect_len; i++) { \ + assert(dstbuf[i] == expect[i]); \ + } \ + for (int i = expect_len; i < ULAS_FULLEN; i++) { \ + assert(dstbuf[i] == 0); \ + } \ + ulasin = stdin; \ + ulasout = stdout; \ + } + // tests the entire stack void test_full(void) { TESTBEGIN("testfull"); + ASSERT_FULL(2, 0, "tests/t0.s", 0, 0x76); + TESTEND("testfull"); } @@ -321,9 +346,12 @@ int main(int arc, char **argv) { test_totok(); test_intexpr(); test_asminstr(); - test_full(); ulas_free(); + // this will re-init everything on its own, + // so call after free + test_full(); + return 0; } diff --git a/src/ulas.c b/src/ulas.c index 0b1509e..a07be33 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -1725,8 +1725,6 @@ const struct ulas_instr ULASINSTRS[] = { {NULL}}; -// assembles an instruction, writes bytes into dst -// returns bytes written or -1 on error int ulas_asminstr(char *dst, unsigned long max, const char **line, unsigned long n) { const char *start = *line;