diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/kit_test/test.c | 106 | ||||
-rw-r--r-- | source/kit_test/test.h | 12 | ||||
-rw-r--r-- | source/test/unittests/move_back.test.c | 8 |
3 files changed, 88 insertions, 38 deletions
diff --git a/source/kit_test/test.c b/source/kit_test/test.c index 6603d65..7065102 100644 --- a/source/kit_test/test.c +++ b/source/kit_test/test.c @@ -9,14 +9,17 @@ kit_tests_list_t kit_tests_list = { 0 }; -static void report(int i, int line, int ok) { +static void report(int i, int line, long long value, + long long expected) { int const n = kit_tests_list.v[i].assertions++; if (n >= KIT_TEST_ASSERTIONS_LIMIT) return; - kit_tests_list.v[i].line[n] = line; - kit_tests_list.v[i].status[n] = ok; + kit_tests_list.v[i].line[n] = line; + kit_tests_list.v[i].status[n] = value == expected; + kit_tests_list.v[i].value[n] = value; + kit_tests_list.v[i].expected[n] = expected; } static long long ns_to_ms(long long ns) { @@ -250,7 +253,9 @@ int kit_run_tests(int argc, char **argv) { no_color || print_color(light); - if (status != 0) { + if (!quiet && status != 0) { + int have_reports = 0; + for (i = 0; i < kit_tests_list.size && i < KIT_TESTS_SIZE_LIMIT; i++) { if (specific_test != NULL && @@ -263,62 +268,99 @@ int kit_run_tests(int argc, char **argv) { signum < sizeof signames / sizeof *signames && signames[signum] != NULL) { no_color || print_color(light); - quiet || printf("Signal \"%s\" (%d) for \"", - signames[signum], signum); + printf("Signal \"%s\" (%d) for \"", signames[signum], + signum); no_color || print_color(white); - quiet || printf("%s", kit_tests_list.v[i].test_name); + printf("%s", kit_tests_list.v[i].test_name); no_color || print_color(light); - quiet || printf("\" in \""); + printf("\" in \""); no_color || print_color(white); - quiet || - printf("%s", kit_tests_list.v[i].test_file + file_root); + + printf("%s", kit_tests_list.v[i].test_file + file_root); no_color || print_color(light); - quiet || printf("\"!.\n"); + printf("\"!.\n"); } else { no_color || print_color(light); - quiet || printf("Unknown signal (%d) for \"", signum); + printf("Unknown signal (%d) for \"", signum); no_color || print_color(white); - quiet || printf("%s", kit_tests_list.v[i].test_name); + printf("%s", kit_tests_list.v[i].test_name); no_color || print_color(light); - quiet || printf("\" in \""); + printf("\" in \""); no_color || print_color(white); - quiet || - printf("%s", kit_tests_list.v[i].test_file + file_root); + + printf("%s", kit_tests_list.v[i].test_file + file_root); no_color || print_color(light); - quiet || printf("\"!.\n"); + printf("\"!.\n"); } + have_reports = 1; } if (kit_tests_list.v[i].assertions > KIT_TEST_ASSERTIONS_LIMIT) { no_color || print_color(light); - quiet || printf("Too many assertions for \""); + printf("Too many assertions for \""); no_color || print_color(white); - quiet || printf("%s", kit_tests_list.v[i].test_name); + printf("%s", kit_tests_list.v[i].test_name); no_color || print_color(light); - quiet || printf("\" in \""); + printf("\" in \""); no_color || print_color(white); - quiet || - printf("%s", kit_tests_list.v[i].test_file + file_root); + + printf("%s", kit_tests_list.v[i].test_file + file_root); no_color || print_color(light); - quiet || printf("\"!.\n"); - } else + printf("\"!.\n"); + have_reports = 1; + } + } + + have_reports &&printf("\n"); + } + + if (!quiet && status != 0) { + for (i = 0; i < kit_tests_list.size && i < KIT_TESTS_SIZE_LIMIT; + i++) { + if (specific_test != NULL && + strstr(kit_tests_list.v[i].test_name, specific_test) == + NULL) + continue; + + if (kit_tests_list.v[i].assertions <= KIT_TEST_ASSERTIONS_LIMIT) for (j = 0; j < kit_tests_list.v[i].assertions; j++) if (!kit_tests_list.v[i].status[j]) { no_color || print_color(light); - quiet || printf("Assertion on line "); + printf("Assertion on line "); + no_color || print_color(white); + printf("%d", kit_tests_list.v[i].line[j]); + no_color || print_color(light); + printf(" in \""); + no_color || print_color(white); + printf("%s", kit_tests_list.v[i].test_file + file_root); + no_color || print_color(light); + printf("\" failed.\n"); + no_color || print_color(red); + printf(" -> "); + no_color || print_color(light); + printf("Got wrong value"); + no_color || print_color(white); + printf("%10lld", kit_tests_list.v[i].value[j]); + no_color || print_color(light); + printf(" ("); no_color || print_color(white); - quiet || printf("%d", kit_tests_list.v[i].line[j]); + printf("0x%08llx", kit_tests_list.v[i].value[j]); + no_color || print_color(light); + printf(")\n"); + no_color || print_color(green); + printf(" -> "); no_color || print_color(light); - quiet || printf(" in \""); + printf("Expected value "); no_color || print_color(white); - quiet || printf("%s", kit_tests_list.v[i].test_file + - file_root); + printf("%10lld", kit_tests_list.v[i].expected[j]); no_color || print_color(light); - quiet || printf("\" failed.\n"); + printf(" ("); + no_color || print_color(white); + printf("0x%08llx", kit_tests_list.v[i].expected[j]); + no_color || print_color(light); + printf(")\n\n"); } } - - quiet || printf("\n"); } if (kit_tests_list.size > KIT_TESTS_SIZE_LIMIT) { diff --git a/source/kit_test/test.h b/source/kit_test/test.h index 44aae09..8732366 100644 --- a/source/kit_test/test.h +++ b/source/kit_test/test.h @@ -19,7 +19,9 @@ extern "C" { # define KIT_TEST_ASSERTIONS_LIMIT 0x50 #endif -typedef void (*kit_test_report_fn)(int test_index, int line, int ok); +typedef void (*kit_test_report_fn)(int test_index, int line, + long long value, + long long expected); typedef void (*kit_test_run_fn)( int kit_test_index_, kit_test_report_fn kit_test_report_fn_); @@ -30,6 +32,8 @@ typedef struct { int assertions; int line[KIT_TEST_ASSERTIONS_LIMIT]; int status[KIT_TEST_ASSERTIONS_LIMIT]; + long long value[KIT_TEST_ASSERTIONS_LIMIT]; + long long expected[KIT_TEST_ASSERTIONS_LIMIT]; int signal; } kit_test_case_t; @@ -87,13 +91,17 @@ void kit_test_register(char const *name, char const *file, int kit_test_index_, kit_test_report_fn kit_test_report_fn_) #define KIT_REQUIRE(...) \ - kit_test_report_fn_(kit_test_index_, __LINE__, (__VA_ARGS__)) + kit_test_report_fn_(kit_test_index_, __LINE__, (__VA_ARGS__), 1) + +#define KIT_REQUIRE_EQ(...) \ + kit_test_report_fn_(kit_test_index_, __LINE__, __VA_ARGS__) int kit_run_tests(int argc, char **argv); #ifndef KIT_DISABLE_SHORT_NAMES # define TEST KIT_TEST # define REQUIRE KIT_REQUIRE +# define REQUIRE_EQ KIT_REQUIRE_EQ # define test_register kit_test_register # define run_tests kit_run_tests diff --git a/source/test/unittests/move_back.test.c b/source/test/unittests/move_back.test.c index 6799128..399619d 100644 --- a/source/test/unittests/move_back.test.c +++ b/source/test/unittests/move_back.test.c @@ -29,10 +29,10 @@ TEST("move back val") { MOVE_BACK(ref.size, ref, 2, is_equal); - REQUIRE(ref.size == 3); - REQUIRE(v[0] == 1); - REQUIRE(v[1] == 1); - REQUIRE(v[2] == 1); + REQUIRE_EQ(ref.size, 3); + REQUIRE_EQ(v[0], 1); + REQUIRE_EQ(v[1], 1); + REQUIRE_EQ(v[2], 1); } TEST("move back ref val") { |