aboutsummaryrefslogtreecommitdiff
path: root/test/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/test.c')
-rw-r--r--test/test.c151
1 files changed, 0 insertions, 151 deletions
diff --git a/test/test.c b/test/test.c
deleted file mode 100644
index 04cade6..0000000
--- a/test/test.c
+++ /dev/null
@@ -1,151 +0,0 @@
-
-#include "kpl_test.h"
-
-static kpl_test *_kpl_test_head = NULL, *_kpl_test_tail = NULL, *_kpl_error_head = NULL, *_kpl_error_tail = NULL;
-
-static int32_t _kpl_test_count = 0, _kpl_test_error_count = 0;
-
-void kpl_test_add(kpl_test *_test) {
- _kpl_test_count++;
- if (_kpl_test_head)
- _kpl_test_tail = _kpl_test_tail->next_test = _test;
- else
- _kpl_test_head = _kpl_test_tail = _test;
-}
-
-static void kpl_test_report(kpl_test *_test) {
- printf(KPL_COLOR(BOLD) "%s" KPL_COLOR(RESET) ":" KPL_COLOR(LIGHT_CYAN) "%s" KPL_COLOR(RESET),
- _test->file_name, _test->test_name);
-}
-
-static void kpl_test_report_success(kpl_test *_test) {
- printf(KPL_COLOR2(BOLD, LIGHT_GREEN) "PASSED " KPL_COLOR(RESET));
- kpl_test_report(_test);
- putchar('\n');
-}
-
-static void kpl_test_report_error(kpl_test *_test, bool failed_status) {
- if (failed_status)
- printf(KPL_COLOR2(BOLD, LIGHT_RED) "FAILED " KPL_COLOR(RESET));
- kpl_test_report(_test);
- printf(":" KPL_COLOR(LIGHT_MAGENTA) "%d" KPL_COLOR(RESET) "::"
- KPL_COLOR(LIGHT_RED) "%s\n" KPL_COLOR(RESET), _test->error_line_number, _test->error_message);
-}
-
-static int32_t kpl_test_error_list(void) {
- if (!_kpl_test_error_count) {
- printf(KPL_COLOR2(BOLD, LIGHT_GREEN) "ALL TESTS PASSED\n" KPL_COLOR(RESET));
- return KPL_EXIT_CODE_SUCCESS;
- }
- printf(KPL_COLOR2(BOLD, LIGHT_RED) "FAILED TEST COUNT:" KPL_COLOR(RESET)
- KPL_COLOR(WHITE) " %d\n\n" KPL_COLOR(RESET), _kpl_test_error_count);
- while (_kpl_error_head) {
- kpl_test_report_error(_kpl_error_head, false);
- putchar('\n');
- _kpl_error_head = _kpl_error_head->next_test;
- }
- return KPL_EXIT_CODE_ERROR;
-}
-
-static void kpl_test_run(kpl_test *_test) {
- _test->test_function(_test);
- if (_test->error_line_number == -1) {
- kpl_test_report_success(_test);
- return;
- }
- _kpl_test_error_count++;
- kpl_test_report_error(_test, true);
- if (_kpl_error_head)
- _kpl_error_tail = _kpl_error_tail->next_test = _test;
- else
- _kpl_error_head = _kpl_error_tail = _test;
-}
-
-static kpl_test *kpl_test_next(void) {
- if (!_kpl_test_head)
- return NULL;
- kpl_test *_test = _kpl_test_head;
- _kpl_test_head = _kpl_test_head->next_test;
- _test->next_test = NULL;
- return _test;
-}
-
-static int32_t kpl_test_run_all(void) {
- kpl_test *_test = NULL;
- while ((_test = kpl_test_next()))
- kpl_test_run(_test);
- return kpl_test_error_list();
-}
-
-static int32_t kpl_test_help(const char *argv0) {
- printf("\nUsage: " KPL_COLOR(BOLD) "%s " KPL_COLOR(RESET)
- KPL_COLOR(WHITE) "[OPTIONS] [TEST NAMES]\n\n" KPL_COLOR(RESET), argv0);
- printf("Where " KPL_COLOR(WHITE) "[OPTIONS]" KPL_COLOR(RESET) " are:\n");
- printf(KPL_COLOR(LIGHT_YELLOW) "\t-a " KPL_COLOR(RESET) "Run All Tests\n");
- printf(KPL_COLOR(LIGHT_YELLOW) "\t-h " KPL_COLOR(RESET) "Show Help\n");
- printf(KPL_COLOR(LIGHT_YELLOW) "\t-l " KPL_COLOR(RESET) "List Test Names\n");
- putchar('\n');
- return KPL_EXIT_CODE_HELP;
-}
-
-static int32_t kpl_test_list(void) {
- printf("\nTest Count: " KPL_COLOR(WHITE) "%d\n\n"
- KPL_COLOR(RESET) KPL_COLOR(LIGHT_CYAN), _kpl_test_count);
- while (_kpl_test_head) {
- printf("%s ", _kpl_test_head->test_name);
- _kpl_test_head = _kpl_test_head->next_test;
- }
- printf(KPL_COLOR(RESET) "\n\n");
- return KPL_EXIT_CODE_HELP;
-}
-
-static int32_t kpl_test_run_by_name(const int32_t argc, const char *argv[], const int32_t named_arg_index) {
- if (named_arg_index == argc) {
- printf(KPL_COLOR(LIGHT_RED) "\nNo Tests Specified\n" KPL_COLOR(RESET));
- return kpl_test_help(argv[0]);
- }
- int32_t tests_ran = 0;
- kpl_test *_test = NULL;
- while ((_test = kpl_test_next()))
- for (int32_t test_name_index = named_arg_index; test_name_index < argc; test_name_index++)
- if (strcmp(argv[test_name_index], _test->test_name) == 0) {
- kpl_test_run(_test);
- tests_ran++;
- }
- if (!tests_ran) {
- printf(KPL_COLOR(LIGHT_RED) "\nNo Matching Tests Found, for help run: " KPL_COLOR(RESET)
- KPL_COLOR(BOLD) "%s -h\n\n" KPL_COLOR(RESET), argv[0]);
- return KPL_EXIT_CODE_ERROR;
- }
- return kpl_test_error_list();
-}
-
-int32_t main(const int32_t argc, const char *argv[]) {
- int32_t arg_index = 1;
- while (arg_index < argc) {
- if (argv[arg_index][0] != '-' || !argv[arg_index][1] || argv[arg_index][2])
- break;
- switch (argv[arg_index][1]) {
- case 'a':
- return kpl_test_run_all();
- case 'h':
- return kpl_test_help(argv[0]);
- case 'l':
- return kpl_test_list();
- default:
- return kpl_test_run_by_name(argc, argv, arg_index);
- }
- arg_index++;
- }
- return kpl_test_run_by_name(argc, argv, arg_index);
-}
-
-KPL_TEST(pass_by_default) {
- // Pass by default
- // Uncomment below to f ail
- // KPL_FAIL("Failure message");
-}
-
-KPL_TEST(counting) {
- KPL_ASSERT(_kpl_test_count > 0, "Test counter not incrementing");
-}