diff --git a/c_projects/x_tfw4c/src/x_tfw4c.c b/c_projects/x_tfw4c/src/x_tfw4c.c new file mode 100644 index 0000000..290ad7e --- /dev/null +++ b/c_projects/x_tfw4c/src/x_tfw4c.c @@ -0,0 +1,83 @@ +#include + +// printf Formating +#define X_RED "\x1B[31m" +#define X_GREEN "\x1B[32m" +#define X_RST "\x1B[0m" + +// TEST FRAMEWORK STRUCT +typedef struct testnode{ + char* name; + int (*op)(void); + struct testnode* next; +}testnode; + +// LL nodes +static testnode* head = NULL; +static testnode* tail = NULL; +static testnode* ptr = NULL; + +// TEST FRAMEWORK MACRO +// create a new node and pass in the name of the test. Then make a new function +// that adds the test to the LL. __attribute__((constructor)) has the function +// run before main +#define TEST(UNIT)\ + static int UNIT(void);\ + static testnode UNIT##node = {#UNIT, UNIT, NULL};\ + __attribute__((constructor)) \ + static void add##UNIT(void){ \ + if (head == NULL){\ + head = &UNIT##node;\ + tail = head;\ + }\ + ptr = tail;\ + tail = &UNIT##node;\ + ptr->next = tail;\ + }\ + static int UNIT(void) + +// DEFINE TESTS +TEST(fail){ + return -1; +} + +TEST(success){ + return 0; +} +// END OF TEST DEFINITIONS + +int main(){ + int total_tests = 0; + int errors = 0; + + ptr = head; + while (ptr != NULL){ + + total_tests++; + + if(!ptr->op()){ + printf("%s[PASS]%s ", X_GREEN, X_RST); + } + else{ + printf("%s[FAIL]%s ", X_RED, X_RST); + errors++; + } + + printf("%s\n", ptr->name); + ptr = ptr->next; + } + + printf("Tests completed with %s%d PASS%s", X_GREEN, total_tests - errors, X_RST); + printf(" and %s%d FAIL%s\n", X_RED, errors, X_RST); + + + + return 0; +} + + +// INSERT HEADERS FOR FUNCS + +// DEFINE TESTS + +// END OF TEST DEFINITIONS