/* * 000_smoke — Phase 0 smoke test. * * Asserts: * - libwcc symbols (newarena/amalloc/freearena, fatal/errorf/warnf) * are linkable. * - `ww -V` exits 0 and prints the configured version. */ #include "ww.h" #include #include static void test_arena(void) { Arena *a = newarena(); if (a == NULL) { fprintf(stderr, "smoke: newarena returned NULL\n"); exit(1); } int *p = amalloc(a, sizeof *p); *p = 42; if (*p != 42) { fprintf(stderr, "smoke: arena alloc bad\n"); exit(1); } /* force several growths */ for (int i = 0; i < 10000; i++) { char *s = aprintf(a, "hello-%d", i); if (s == NULL || strncmp(s, "hello-", 6) != 0) { fprintf(stderr, "smoke: aprintf bad\n"); exit(1); } } freearena(a); } static void test_version(void) { if (WW_VERSION == NULL || WW_VERSION[0] == '\0') { fprintf(stderr, "smoke: empty WW_VERSION\n"); exit(1); } } static void test_ww_minus_v(void) { const char *bin = getenv("BIN"); if (bin == NULL) bin = "out/bin"; char cmd[512]; snprintf(cmd, sizeof cmd, "%s/ww -V", bin); FILE *p = popen(cmd, "r"); if (p == NULL) { fprintf(stderr, "smoke: popen %s\n", cmd); exit(1); } char buf[128]; size_t n = fread(buf, 1, sizeof buf - 1, p); buf[n] = '\0'; int rc = pclose(p); if (rc != 0) { fprintf(stderr, "smoke: ww -V exit %d\n", rc); exit(1); } if (strstr(buf, "ww ") != buf) { fprintf(stderr, "smoke: ww -V output not 'ww ...': %s\n", buf); exit(1); } if (strstr(buf, WW_VERSION) == NULL) { fprintf(stderr, "smoke: ww -V missing version %s in: %s\n", WW_VERSION, buf); exit(1); } } int main(void) { test_arena(); test_version(); test_ww_minus_v(); puts("smoke: ok"); return 0; }