diff options
Diffstat (limited to 'src/std/testing.h')
| -rw-r--r-- | src/std/testing.h | 36 |
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; \ + } |
