#include #include #include #include #include "lily-test.h" LILY_INIT(); void run_test(const char *name, lily_test (*fp)()) { printf("%s... ", name); const char *result = fp(); if (result != 0) { printf("FAILED (%s)\n", result); } else printf("OK\n"); } lily_test check_init() { // should fail to compile if lily_test_data is undefined if (lily_test_data.tests_run != 0) return "tests_run is not equal to zero!"; if (lily_test_data.tests_failed != 0) return "tests_failed is not equal to zero!"; return 0; } int get_message(char **destination, const char *source) { const char *s = source; size_t size = 0; while (*s != '\n') { if (*s == 0) return false; s++; size++; } *destination = malloc((size+1) * sizeof(char)); strncpy(*destination, source, size); (*destination)[size] = 0; return true; } #define assert_msg "message" lily_test wrap_assert(bool statement) { lily_assert(statement, assert_msg); return 0; } lily_test check_assert() { if (wrap_assert(true) != 0) return "true assertion did not return 0!"; const char *result = wrap_assert(false); if (result == 0) return "false assertion returned zero!"; char *message; if (!get_message(&message, result)) return "false assertion contained malformed message!"; if (strcmp(message, assert_msg) != 0) return "false assertion message was not '" assert_msg "'!"; free(message); return 0; } lily_test check_other_asserts() { } int main() { run_test("check LILY_INIT()", check_init); run_test("check basic assertion", check_assert); printf("all tests finished.\n"); return 0; }