From 667224817c0a5612d471c8cc579e159050ad61a1 Mon Sep 17 00:00:00 2001 From: Johannes Löthberg Date: Mon, 19 Jan 2015 22:12:33 +0100 Subject: twbctf: Update to newest version Note: The twbctf version used in sds is a slightly modified version and not pure upstream, to let us have the tests in test.c --- test/twbctf.c | 46 +++++++++++++++++++++++++++++++++------------- test/twbctf.h | 2 ++ 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/test/twbctf.c b/test/twbctf.c index af95c10..3b3ae4b 100644 --- a/test/twbctf.c +++ b/test/twbctf.c @@ -20,6 +20,7 @@ // Libraries // #include +#include #include #include @@ -29,22 +30,41 @@ // Forward Declarations // #define TEST_COUNT ((sizeof test_list)/(sizeof (struct test))) -// Run Suite // -signed -main (void) { - int print_width = 0; +uint8_t +longest_desc(const struct test *list) { + uint8_t longest = 0; for (size_t i = 0; i < TEST_COUNT; i++) { - int length = (int)strlen(test_list[i].desc); - if (length > print_width) { - print_width = length; + uint8_t len = (uint8_t)strlen(list[i].desc); + if (longest < len) { + longest = len; } } + return longest; +} - for (size_t i = 0; i < TEST_COUNT; i++) { - printf("Testing %-*s\t\t[ PEND ]\r", print_width, test_list[i].desc); - char * result = (test_list[i].func() ? "\x1b[32mPASS" : "\x1b[31mFAIL"); - printf("Testing %-*s\t\t[ %s \x1b[0m]\n", print_width, test_list[i].desc, result); - } +// Run Suite // +signed +main(signed argc, char * argv []) { + + uint8_t print_width = longest_desc(test_list); - return 0; + const size_t tc = TEST_COUNT; + bool results [tc]; + bool shortened = (argc > 1 && *(short * )argv[1] == 0x732d); + for ( size_t i = 0; i < tc; i ++ ) { + if ( shortened ) { + results[i] = test_list[i].func(); + //printf(results[i] ? "\x1b[32m." : "\x1b[31mF"); + putchar(results[i] ? '.' : '!'); + } else { + printf("Testing %-*s\t\t[ PEND ]\r", print_width, test_list[i].desc); + char * r = test_list[i].func() ? "\x1b[32mPASS" : "\x1b[31mFAIL"; + printf("Testing %-*s\t\t[ %s \x1b[0m]\n", print_width, test_list[i].desc, r); + } + } if ( shortened ) { + printf("\x1b[0m\n\nFailed Tests:\n"); + for ( size_t i = 0; i < tc; i ++ ) { + !results[i] ? printf(" %s\n", test_list[i].desc) : printf(""); + } + } return 0; } diff --git a/test/twbctf.h b/test/twbctf.h index c0789cc..3f6656e 100644 --- a/test/twbctf.h +++ b/test/twbctf.h @@ -11,4 +11,6 @@ struct test { test_p func; }; +uint8_t longest_desc(const struct test *list); + #endif -- cgit v1.2.3-70-g09d2