aboutsummaryrefslogtreecommitdiff
path: root/src/std/testing.h
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-04-08 13:14:27 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-04-08 13:15:01 +0200
commitcf534d762754860ed5b714974f99acd282d48b3b (patch)
treebf22341cedfb50ee7bcd4e15f85add2329783f31 /src/std/testing.h
parent630fcb1846aed16b9ab62bcf700f668883f4521f (diff)
Restructure into src/{std,json}/
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'src/std/testing.h')
-rw-r--r--src/std/testing.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/std/testing.h b/src/std/testing.h
new file mode 100644
index 0000000..388c778
--- /dev/null
+++ b/src/std/testing.h
@@ -0,0 +1,36 @@
+#pragma once
+#include <stdio.h>
+#include <string.h>
+
+#include "memory.h"
+
+typedef struct {
+ size size;
+ byte *content;
+} MemoryFile;
+MemoryFile load_file(Arena *a, const char *filename);
+
+#define t_assert_equal(a, b) \
+ if (!(a == b)) { \
+ fprintf(stderr, \
+ "Assertion failed: %d (%s) != %d (%s) at %s:%d in %s()\n", \
+ (i32)a, #a, (i32)b, #b, __FILE__, __LINE__, __func__); \
+ return 1; \
+ }
+
+#define t_assert_fequal(a, b) \
+ if ((a - b) > 1e-6 || (b - a) > 1e-6) { \
+ fprintf(stderr, \
+ "Assertion failed: %f (%s) != %f (%s) at %s:%d in %s()\n", a, \
+ #a, b, #b, __FILE__, __LINE__, __func__); \
+ return 1; \
+ }
+
+#define t_assert_strequal(a, b) \
+ if ((a.len != b.len) || (a.len && memcmp(a.data, b.data, a.len))) { \
+ fprintf(stderr, \
+ "Assertion failed: %.*s (%s) != %.*s (%s) at %s:%d in %s()\n", \
+ (i32)a.len, a.data, #a, (i32)b.len, b.data, #b, __FILE__, \
+ __LINE__, __func__); \
+ return 1; \
+ }