From 83eee4d23f9da9e72238dd01d43b350ed5bc04f1 Mon Sep 17 00:00:00 2001 From: Danny van Kooten Date: Thu, 12 Mar 2020 12:33:55 +0100 Subject: add some more test helpers --- tests/test.h | 9 ++++++--- tests/test_hashmap.c | 8 ++++++-- tests/test_template.c | 10 ++++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 tests/test_template.c (limited to 'tests') diff --git a/tests/test.h b/tests/test.h index 19868f8..05c35b9 100644 --- a/tests/test.h +++ b/tests/test.h @@ -3,12 +3,15 @@ #include #include -#define assert(assertion, format, ...) _assert(assertion, __FILE__, __LINE__, format, ##__VA_ARGS__) -#define TESTNAME(v) strcpy(current_test, v); +#define START_TESTS int main() { +#define END_TESTS } +#define TEST(name) strcpy(current_test, #name); +/* used to store the running test name */ char current_test[256] = {'\0'}; -void _assert(int assertion, const char filename[64], const int line, char *format, ...) +#define assert(assertion, format, ...) _assert(assertion, __FILE__, __LINE__, format, ##__VA_ARGS__) +static void _assert(int assertion, const char filename[64], const int line, char *format, ...) { if (assertion) { diff --git a/tests/test_hashmap.c b/tests/test_hashmap.c index cf6f7a2..68b8d0c 100644 --- a/tests/test_hashmap.c +++ b/tests/test_hashmap.c @@ -1,7 +1,9 @@ #include "test.h" #include "hashmap.h" -int main() { +START_TESTS + +TEST(hashmap) { struct hashmap *hm = hashmap_new(); assert(hashmap_get(hm, "foo") == NULL, "expected NULL"); @@ -11,4 +13,6 @@ int main() { assert(strcmp(value, "bar") == 0, "expected %s, got %s", "bar", value); hashmap_free(hm); -} \ No newline at end of file +} + +END_TESTS \ No newline at end of file diff --git a/tests/test_template.c b/tests/test_template.c new file mode 100644 index 0000000..62ac77c --- /dev/null +++ b/tests/test_template.c @@ -0,0 +1,10 @@ +#include "test.h" +#include "template.h" + +START_TESTS + +TEST(text_only) { + +} + +END_TESTS \ No newline at end of file -- cgit v1.2.3