diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/assertions.c | 31 | ||||
-rw-r--r-- | tests/helpers.c | 2 | ||||
-rw-r--r-- | tests/main.c | 2 | ||||
-rw-r--r-- | tests/run_test.c | 2 | ||||
-rw-r--r-- | tests/tests.h | 7 |
5 files changed, 42 insertions, 2 deletions
diff --git a/tests/assertions.c b/tests/assertions.c new file mode 100644 index 0000000..0c443b5 --- /dev/null +++ b/tests/assertions.c @@ -0,0 +1,31 @@ +#include <stdio.h> +#include <string.h> + +#include "lily-test.h" +#include "tests.h" + +// basic assertion +lily_test wrap_assert_msg(int statement, const char *message) +{ + // if you move the location of this line, BE SURE TO UPDATE THE + // TEST BELOW so that it expects the correct line! + lily_assert_msg(statement, message); + return LILY_SUCCESS; +} + +const char* basic_assertion() +{ + lily_test result = wrap_assert_msg(1, "should succeed"); + if (result.error != 0) + return "assert_msg() incorrectly returned non-zero error on true statement!"; + + result = wrap_assert_msg(0, "should fail"); + if (result.error == 0) + return "assert_msg() incorrectly returned zero error on false statement!"; + if (strcmp(result.message, "should fail") != 0) + return "assert_msg() returned with incorrect message!"; + if (strcmp(result.location, "tests/assertions.c:12") != 0) + return "assert_msg() returned with incorrect location!"; + + return 0; +} diff --git a/tests/helpers.c b/tests/helpers.c index 42a0724..cdf72b4 100644 --- a/tests/helpers.c +++ b/tests/helpers.c @@ -8,7 +8,7 @@ void run_test(const char *name, const char* (*test)()) printf("%s... ", name); const char *result = test(); if (result != 0) { - printf("FAILED (%s)\n", result); + printf("FAILED: %s\n", result); } else printf("OK\n"); diff --git a/tests/main.c b/tests/main.c index a3de945..ccc7310 100644 --- a/tests/main.c +++ b/tests/main.c @@ -8,6 +8,8 @@ int main() { + run_test("check basic assert_msg()", basic_assertion); + printf("all tests finished.\n"); return 0; } diff --git a/tests/run_test.c b/tests/run_test.c new file mode 100644 index 0000000..3dd0c4b --- /dev/null +++ b/tests/run_test.c @@ -0,0 +1,2 @@ +#include "lily-test.h" + diff --git a/tests/tests.h b/tests/tests.h index cbe0f02..7b3dc48 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -1,7 +1,12 @@ #ifndef LILY_META_TESTS_H #define LILY_META_TESTS_H -void run_test(const char *name, const char* (*fp)()); +void run_test(const char *name, const char* (*test)()); int validate_message(const char* received, const char* expected, const char* FILE, unsigned int LINE); + +// test cases +const char* basic_assertion(); + + #endif |