aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDanny van Kooten <dannyvankooten@users.noreply.github.com>2020-03-12 12:33:55 +0100
committerDanny van Kooten <dannyvankooten@users.noreply.github.com>2020-03-12 12:33:55 +0100
commit83eee4d23f9da9e72238dd01d43b350ed5bc04f1 (patch)
tree46b92c58b7e37977cd06da09b32dbf626f5b19df /tests
parentcd70ca266bb212d6a32d2dd808c7708bb7be6f1f (diff)
downloadunja-83eee4d23f9da9e72238dd01d43b350ed5bc04f1.tar.gz
unja-83eee4d23f9da9e72238dd01d43b350ed5bc04f1.zip
add some more test helpers
Diffstat (limited to 'tests')
-rw-r--r--tests/test.h9
-rw-r--r--tests/test_hashmap.c8
-rw-r--r--tests/test_template.c10
3 files changed, 22 insertions, 5 deletions
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 <stdarg.h>
#include <string.h>
-#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