Luna/tests/Test.h

45 lines
2.6 KiB
C
Raw Normal View History

2022-10-16 14:00:14 +00:00
#ifndef __TEST_H_
#define __TEST_H_
2022-10-16 13:31:58 +00:00
#include <stdbool.h>
int printf(const char*, ...);
#define DEFINE_TEST(name) bool test_##name()
#define START_TEST(name) printf("testing whether %s works... ", #name)
#define START_TEST_CASE(name) printf("testing %s...\n", #name)
#define TEST_SUCCESS() \
do { \
printf("yes!\n"); \
return true; \
} while (0)
2022-10-16 14:00:14 +00:00
#define TEST_FAIL(expr) \
2022-10-16 13:31:58 +00:00
do { \
2022-10-16 14:00:14 +00:00
printf("no (%s)\n", #expr); \
2022-10-16 13:31:58 +00:00
return false; \
} while (0)
#define TEST_NOT_SURE(expr) \
do { \
printf("not sure (%s)\n", #expr); \
return true; \
} while (0)
2022-10-16 13:31:58 +00:00
#define EXPECT(expr) \
do { \
2022-10-16 14:00:14 +00:00
if (!(expr)) { TEST_FAIL(expr); } \
2022-10-16 13:31:58 +00:00
} while (0)
#define EXPECT_EQ(a, b) EXPECT((a) == (b))
#define EXPECT_NOT_EQ(a, b) EXPECT((a) != (b))
#define EXPECT_NOT_CRASHED() TEST_SUCCESS()
#define RUN_TEST(name) \
do { \
if (!test_##name()) return 1; \
2022-10-16 14:00:14 +00:00
} while (0)
#endif