summaryrefslogtreecommitdiff
path: root/source/kit_test
diff options
context:
space:
mode:
authorMitya Selivanov <0x7fffff@guattari.ru>2022-08-06 17:25:22 +0400
committerMitya Selivanov <0x7fffff@guattari.ru>2022-08-06 17:25:22 +0400
commit6c11d4503758079f29ce2b0b0509d2a128ada662 (patch)
treecabe8b223faf8ac42136a0ff10a77622ab0b7cb0 /source/kit_test
parentf112dc4a2dc80d1fe2591a675807cb28f0776d3b (diff)
downloadkit-6c11d4503758079f29ce2b0b0509d2a128ada662.zip
test
Diffstat (limited to 'source/kit_test')
-rw-r--r--source/kit_test/run_tests.c24
-rw-r--r--source/kit_test/test.h42
2 files changed, 36 insertions, 30 deletions
diff --git a/source/kit_test/run_tests.c b/source/kit_test/run_tests.c
index 191982a..19fea96 100644
--- a/source/kit_test/run_tests.c
+++ b/source/kit_test/run_tests.c
@@ -5,7 +5,7 @@
struct kit_tests_list kit_tests_list = { 0 };
-static void report(int i, char const *file, int line, bool ok) {
+static void report(int i, char const *file, int line, _Bool ok) {
int const n = kit_tests_list.tests[i].assertions++;
kit_tests_list.tests[i].file[n] = file;
@@ -23,7 +23,7 @@ static long long sec_to_ms(long long sec) {
enum code_value { white, yellow, red, green };
-static void color_code(bool term_color, int c) {
+static void color_code(_Bool term_color, int c) {
if (term_color) {
if (c == white)
printf("\x1b[37m");
@@ -37,15 +37,15 @@ static void color_code(bool term_color, int c) {
}
int kit_run_tests(int argc, char **argv) {
- int fail_test_count = 0;
- int fail_assertion_count = 0;
- int total_assertion_count = 0;
- int status = 0;
- bool term_color = true;
+ int fail_test_count = 0;
+ int fail_assertion_count = 0;
+ int total_assertion_count = 0;
+ int status = 0;
+ _Bool term_color = 1;
for (int i = 0; i < argc; i++)
if (strcmp("--no-term-color", argv[i]) == 0)
- term_color = false;
+ term_color = 0;
for (int i = 0; i < kit_tests_list.size; i++) {
color_code(term_color, yellow);
@@ -63,17 +63,17 @@ int kit_run_tests(int argc, char **argv) {
printf("\r");
- bool test_status = true;
+ _Bool test_status = 1;
for (int j = 0; j < kit_tests_list.tests[i].assertions; j++)
- if (kit_tests_list.tests[i].status[j] == false) {
+ if (kit_tests_list.tests[i].status[j] == 0) {
fail_assertion_count++;
- test_status = false;
+ test_status = 0;
}
total_assertion_count += kit_tests_list.tests[i].assertions;
- if (test_status == false) {
+ if (test_status == 0) {
color_code(term_color, red);
printf("[ RUN ] %s\n", kit_tests_list.tests[i].test_name);
printf("[ FAILED ] %s - %d ms\n",
diff --git a/source/kit_test/test.h b/source/kit_test/test.h
index 09df7e9..a57f768 100644
--- a/source/kit_test/test.h
+++ b/source/kit_test/test.h
@@ -5,7 +5,6 @@
extern "C" {
#endif
-#include <stdbool.h>
#include <stddef.h>
#include <string.h>
@@ -26,7 +25,7 @@ extern "C" {
#endif
typedef void (*kit_test_report)(int, char const *file, int line,
- bool);
+ _Bool);
typedef void (*kit_test_function)(int, kit_test_report);
struct kit_test_case {
@@ -35,7 +34,7 @@ struct kit_test_case {
int assertions;
char const *file[KIT_TEST_ASSERTIONS_LIMIT];
int line[KIT_TEST_ASSERTIONS_LIMIT];
- bool status[KIT_TEST_ASSERTIONS_LIMIT];
+ _Bool status[KIT_TEST_ASSERTIONS_LIMIT];
};
struct kit_tests_list {
@@ -47,48 +46,55 @@ extern struct kit_tests_list kit_tests_list;
#ifdef _MSC_VER
# pragma section(".CRT$XCU", read)
-# define KIT_TEST_ON_START_2(f, p) \
+# define KIT_TEST_ON_START_2_(f, p) \
static void f(void); \
__declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \
__pragma(comment(linker, "/include:" p #f "_")) static void f( \
void)
# ifdef _WIN64
-# define KIT_TEST_ON_START(f) KIT_TEST_ON_START_2(f, "")
+# define KIT_TEST_ON_START_(f) KIT_TEST_ON_START_2_(f, "")
# else
-# define KIT_TEST_ON_START(f) KIT_TEST_ON_START_2(f, "_")
+# define KIT_TEST_ON_START_(f) KIT_TEST_ON_START_2_(f, "_")
# endif
#else
-# define KIT_TEST_ON_START(f) \
+# define KIT_TEST_ON_START_(f) \
static void f(void) __attribute__((constructor)); \
static void f(void)
#endif
-#define KIT_TEST_CONCAT4(a, b, c, d) a##b##c##d
-#define KIT_TEST_CONCAT3(a, b, c) KIT_TEST_CONCAT4(a, b, _, c)
+#define KIT_TEST_CONCAT4_(a, b, c, d) a##b##c##d
+#define KIT_TEST_CONCAT3_(a, b, c) KIT_TEST_CONCAT4_(a, b, _, c)
-#define TEST(name) \
- static void KIT_TEST_CONCAT3(kit_test_run_, __LINE__, \
- KIT_TEST_FILE)(int, kit_test_report); \
- KIT_TEST_ON_START( \
- KIT_TEST_CONCAT3(kit_test_case_, __LINE__, KIT_TEST_FILE)) { \
+#define KIT_TEST(name) \
+ static void KIT_TEST_CONCAT3_( \
+ kit_test_run_, __LINE__, KIT_TEST_FILE)(int, kit_test_report); \
+ KIT_TEST_ON_START_( \
+ KIT_TEST_CONCAT3_(kit_test_case_, __LINE__, KIT_TEST_FILE)) { \
int n = kit_tests_list.size; \
if (n < KIT_TESTS_SIZE_LIMIT) { \
kit_tests_list.size++; \
- kit_tests_list.tests[n].test_fn = KIT_TEST_CONCAT3( \
+ kit_tests_list.tests[n].test_fn = KIT_TEST_CONCAT3_( \
kit_test_run_, __LINE__, KIT_TEST_FILE); \
strcpy(kit_tests_list.tests[n].test_name, name); \
kit_tests_list.tests[n].assertions = 0; \
} \
} \
- static void KIT_TEST_CONCAT3(kit_test_run_, __LINE__, \
- KIT_TEST_FILE)( \
+ static void KIT_TEST_CONCAT3_(kit_test_run_, __LINE__, \
+ KIT_TEST_FILE)( \
int kit_test_index_, kit_test_report kit_test_report_)
-#define REQUIRE(ok) \
+#define KIT_REQUIRE(ok) \
kit_test_report_(kit_test_index_, __FILE__, __LINE__, (ok))
int kit_run_tests(int argc, char **argv);
+#ifndef KIT_DISABLE_SHORT_NAMES
+# define TEST KIT_TEST
+# define REQUIRE KIT_REQUIRE
+
+# define run_tests kit_run_tests
+#endif
+
#ifdef __cplusplus
}
#endif