diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | include/README | 2 | ||||
| -rw-r--r-- | include/kpl.h | 3 | ||||
| -rw-r--r-- | include/kpl_test.h | 15 | ||||
| -rw-r--r-- | source/kpl.c | 2 | ||||
| -rw-r--r-- | test/README | 12 | ||||
| -rw-r--r-- | test/test.c | 47 |
7 files changed, 75 insertions, 8 deletions
@@ -8,7 +8,7 @@ OO := -g -Og FFLAGS := -fno-omit-frame-pointer -fhardened WFLAGS := -Wall -Wextra -Wstack-protector CFLAGS = -std=gnu99 $(FLAGS) -I./include $(OO) $(FFLAGS) $(WFLAGS) -CCOBJ = $(CC) -o $@ $^ $(CFLAGS) +CCOBJ = $(CC) $(CFLAGS) -o $@ $^ SOURCE_OBJECTS := $(patsubst %.c, %.o, $(wildcard ./source/*.c)) TEST_OBJECTS := $(patsubst %.c, %.o, $(wildcard ./test/*.c)) diff --git a/include/README b/include/README index f65c345..b182099 100644 --- a/include/README +++ b/include/README @@ -4,4 +4,6 @@ Headers Complier Flags: +KPL_COLOR_OFF # Turn off colored pretty printing + --- diff --git a/include/kpl.h b/include/kpl.h index 99ddf32..ad76991 100644 --- a/include/kpl.h +++ b/include/kpl.h @@ -1,2 +1,5 @@ #pragma once + +#include "kpl/color.h" +#include "kpl/type.h" diff --git a/include/kpl_test.h b/include/kpl_test.h index 1a61a30..6d19eff 100644 --- a/include/kpl_test.h +++ b/include/kpl_test.h @@ -1,4 +1,19 @@ #pragma once +// KPL testing framework + #include "kpl.h" + +typedef struct _kpl_test kpl_test; + +typedef void kpl_test_function(__attribute__((unused)) kpl_test *_test); + +typedef struct _kpl_test { + int32_t error_line_number; + char *file_name, *test_name, *error_message; + kpl_test_function *test_function; + struct _kpl_test *next_test; +} kpl_test; + +void kpl_test_add(kpl_test *_test); diff --git a/source/kpl.c b/source/kpl.c index 904c14b..7e69777 100644 --- a/source/kpl.c +++ b/source/kpl.c @@ -2,7 +2,7 @@ #include "kpl.h" #ifdef KPL_MAIN -int main(void) { +int32_t main(void) { return 1; } #endif diff --git a/test/README b/test/README index 186c570..43d6110 100644 --- a/test/README +++ b/test/README @@ -50,9 +50,13 @@ All objects need to be built with the same sanitizer and do not run valgrind whe Running: -./kpl_test [OPTIONS] # Run all tests -./kpl_test [OPTIONS] NAME # Run test named NAME -./kpl_test [OPTIONS] NAME1 NAME2 ... # Run selected tests named NAM1 NAME2 ... -./kpl_test -h # Show OPTIONS +./kpl_test # Run all tests +./kpl_test NAME # Run test named NAME +./kpl_test NAME1 NAME2 ... # Run selected tests named NAM1 NAME2 ... +./kpl_test -h # Show help + +--- + +Compiler Flags: --- diff --git a/test/test.c b/test/test.c index f12ee6e..afa8e26 100644 --- a/test/test.c +++ b/test/test.c @@ -1,6 +1,49 @@ #include "kpl_test.h" -int main(void) { - return 2; +static kpl_test *_kpl_test_head = NULL, *_kpl_test_tail = NULL, *_kpl_error_head = NULL, *_kpl_error_tail = NULL; + +void kpl_test_add(kpl_test *_test) { + if (_kpl_test_head) + _kpl_test_tail = _kpl_test_tail->next_test = _test; + else + _kpl_test_head = _kpl_test_tail = _test; +} + +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-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) { + // TODO + return KPL_EXIT_CODE_HELP; +} + +static int32_t kpl_test_run(int32_t argc, char *argv[], const int32_t named_arg_position) { + // TODO RUN + return _kpl_error_tail ? KPL_EXIT_CODE_ERROR : KPL_EXIT_CODE_SUCCESS; +} + +int32_t main(int32_t argc, char *argv[]) { + int32_t arg_position = 1; + while (arg_position < argc) { + if (argv[arg_position][0] != '-' || !argv[arg_position][1] || argv[arg_position][2]) + break; + switch (argv[arg_position][1]) { + case 'h': + return kpl_test_help(argv[0]); + case 'l': + return kpl_test_list(); + default: + return kpl_test_run(argc, argv, arg_position); + } + arg_position++; + } + return kpl_test_run(argc, argv, arg_position); } |
