summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-12-19 20:29:39 -0600
committersanine <sanine.not@pm.me>2022-12-19 20:29:39 -0600
commit182b4002e63f330de6150e160a1ad23b1e6b33b8 (patch)
tree35ffada28aaa26a2700570e560310095b5b5cda4
parent5070426785a69dc0b5bd3bbf1cfe7968329b732c (diff)
add INFO macro
-rw-r--r--lily-test.h18
-rw-r--r--tests/assertions.c34
-rw-r--r--tests/tests.h1
3 files changed, 53 insertions, 0 deletions
diff --git a/lily-test.h b/lily-test.h
index c3f6f8c..c9ae02d 100644
--- a/lily-test.h
+++ b/lily-test.h
@@ -116,6 +116,12 @@ typedef struct lily_test_msg_t {
} lily_test_msg_t;
void lily_msg_destroy(lily_test_msg_t *m);
+void lily_info(const char *location, const char *fmt, ...);
+#define LILY_INFO_(location, ...) \
+ lily_info(location, __VA_ARGS__)
+#define LILY_INFO(...) LILY_INFO_(LILY_LOCATION, __VA_ARGS__)
+#define INFO(...) LILY_INFO(__VA_ARGS__)
+
void lily_check(int x, const char *location, const char *fmt, ...);
#define LILY_CHECK_(str, x, location) \
lily_check(x, location, "%s", str)
@@ -175,6 +181,18 @@ void lily_msg_destroy(lily_test_msg_t *m)
free(m);
}
+
+void lily_info(const char *location, const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ lily_test_msg_t *m = lily_msg_create(location, fmt, args);
+ va_end(args);
+
+ lily_g.TAIL->next = m;
+ lily_g.TAIL = m;
+}
+
void lily_check(int x, const char *location, const char *fmt, ...)
{
if (!x) {
diff --git a/tests/assertions.c b/tests/assertions.c
index 6ad855a..156a484 100644
--- a/tests/assertions.c
+++ b/tests/assertions.c
@@ -2,6 +2,40 @@
#include "tests.h"
+const char * test_INFO()
+{
+ lily_g.HEAD.next = NULL;
+ lily_g.TAIL = &(lily_g.HEAD);
+ lily_g.failed = 0;
+
+ INFO("the number is %d", 10);
+ INFO("the string is '%s'", "hello world");
+
+ if (lily_g.failed)
+ return "INFO caused failure!";
+
+ if (lily_g.HEAD.next == NULL)
+ return "INFO did not append any messages!";
+
+ lily_test_msg_t *m = lily_g.HEAD.next;
+ if (strcmp(m->msg, "the number is 10") != 0)
+ return "the first message is incorrect";
+
+ m = m->next;
+ if (m == NULL)
+ return "there is not a second message!";
+
+ if (strcmp(m->msg, "the string is 'hello world'") != 0)
+ return "the second message is incorrect";
+
+ if (m->next != NULL)
+ return "too many messages";
+
+ lily_msg_destroy(lily_g.HEAD.next);
+ return 0;
+}
+
+
const char * test_CHECK()
{
lily_g.HEAD.next = NULL;
diff --git a/tests/tests.h b/tests/tests.h
index 06c35af..2942fa3 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -12,6 +12,7 @@ int validate_message(const char* received, const char* expected,
X(test_LILY_COUNTER) \
X(test_LILY_COUNTER_DECREMENT) \
X(test_auto_registration) \
+ X(test_INFO) \
X(test_CHECK) \
X(test_REQUIRE) \