diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-01-01 09:19:05 -0500 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-01-01 09:19:05 -0500 |
commit | d3edca1670ffc448570745bcc060e8dcce7966c3 (patch) | |
tree | b6a040e6151bbafd7574b0cb84929407a3f52087 | |
parent | 77847f9e83d86931578d1d0ecdf68dd7eebc2a5f (diff) |
initial test types and output
-rw-r--r-- | test.c | 68 | ||||
-rw-r--r-- | test.h | 15 |
2 files changed, 83 insertions, 0 deletions
@@ -0,0 +1,68 @@ +#include <stdio.h> +#include <stdarg.h> + +typedef enum { + DEFAULT = 39, + RED = 31, + GREEN = 32, + YELLOW = 33, + BLUE = 34, + MAGENTA = 35 +} Color; + +static void set_output_color(Color c) +{ + printf("\033[%dm", c); +} + +static void print_result(int success, const char *format, ...) +{ + va_list ap; + Color color = GREEN; + char indicator = '+'; + + if (!success) { + color = RED; + indicator = '!'; + } + + set_output_color(color); + printf("%c ", indicator); + + va_start(ap, format); + vprintf(format, ap); + va_end(ap); + + printf("\n"); + set_output_color(DEFAULT); +} + +void testing_header(const char *header) +{ + printf("Testing header "); + set_output_color(MAGENTA); + printf("<%s>", header); + set_output_color(DEFAULT); + printf("\n"); +} + +void testing_comment(const char *comment) +{ + printf("- %s\n", comment); +} + +void test_int_equals_imp(const char *expression, int result, int expected) +{ + print_result(result == expected, "%s == %d", expression, expected); +} + +void test_void_imp(const char *expression) +{ + printf("? %s\n", expression); +} + +void test_bool_imp(const char *expression, int result, int expected) +{ + int success = (result && expected) || (!result && !expected); + print_result(success, "%s%s", expected ? "" : "!", expression); +} @@ -0,0 +1,15 @@ +void testing_header(const char *); +void testing_comment(const char*); + +void test_int_equals_imp(const char*, int, int); +#define test_int_equals(expression, expected) test_int_equals_imp(#expression, expression, expected) + +void test_void_imp(const char*); +#define test_void(expression) test_void_imp(#expression); (void)expression + +void test_bool_imp(const char *, int, int); +#define test_false(expression) test_bool_imp(#expression, expression, 0) +#define test_true(expression) test_bool_imp(#expression, expression, 1) + +void test_assert(void); +void test_ctype(void); |