diff options
author | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2018-09-03 23:13:41 +0200 |
---|---|---|
committer | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2018-09-03 23:13:41 +0200 |
commit | 83f6bd88f12ac589e67a7700a5918627fd7f2f47 (patch) | |
tree | 652335ecd26620557eb1a460c3d90a5ad37cb972 | |
parent | b35a7572291a6062a16cc3a9831d4cc641b09442 (diff) | |
download | mtest-83f6bd88f12ac589e67a7700a5918627fd7f2f47.tar.gz mtest-83f6bd88f12ac589e67a7700a5918627fd7f2f47.tar.bz2 mtest-83f6bd88f12ac589e67a7700a5918627fd7f2f47.zip |
add: some statistics at the end of tests
-rw-r--r-- | example/readme.md | 23 | ||||
-rw-r--r-- | mtest.h | 16 | ||||
-rwxr-xr-x | mtest.sh | 16 |
3 files changed, 51 insertions, 4 deletions
diff --git a/example/readme.md b/example/readme.md index 4c3907a..5d294b3 100644 --- a/example/readme.md +++ b/example/readme.md @@ -23,6 +23,10 @@ Description main function, calls test group for add tests, and call directly tests from sub-tests. Also includes single test inside. + * named-tests + looped test, when you can insert own test name (instead of mere function + name) for example with parameters of the test + Run === @@ -32,7 +36,7 @@ included below Output ====== -~~{.sh} +~~~{.sh} $ ./example ok 1 - add_test_valid # assert [add-tests.c:43] add_test_invalid_single_assert, add(3, 2) == 6 @@ -48,5 +52,20 @@ ok 6 - sub_test_valid # assert [sub-tests.c:20] sub_test_invalid, sub(5, 3) == 5 not ok 7 - sub_test_invalid ok 8 - sub_test -1..8 +ok 9 - test add(0, 0) +ok 10 - test add(0, 1) +ok 11 - test add(0, 2) +ok 12 - test add(1, 0) +ok 13 - test add(1, 1) +ok 14 - test add(1, 2) +ok 15 - test add(2, 0) +ok 16 - test add(2, 1) +ok 17 - test add(2, 2) +1..17 +# total tests.......: 17 +# passed tests......: 12 +# failed tests......: 5 +# total checks......: 25 +# passed checks.....: 19 +# failed checks.....: 6 ~~~ @@ -3,7 +3,7 @@ Author: Michał Łyszczek <michal.lyszczek@bofc.pl> ========================================================================== __________________________________________________________ - / mtest version v1.1.2 \ + / mtest version v1.1.3 \ | | | Simple test framework that uses TAP output format | \ http://testanything.org / @@ -59,6 +59,8 @@ int mt_test_status; \ int mt_total_tests = 0; \ int mt_total_failed = 0; \ + int mt_total_checks = 0; \ + int mt_checks_failed = 0; \ static void (*mt_prepare_test)(void); \ static void (*mt_cleanup_test)(void) @@ -75,6 +77,8 @@ extern int mt_test_status; \ extern int mt_total_tests; \ extern int mt_total_failed; \ + extern int mt_total_checks; \ + extern int mt_checks_failed; \ static void (*mt_prepare_test)(void); \ static void (*mt_cleanup_test)(void) @@ -119,11 +123,13 @@ #define mt_assert(e) do { \ + ++mt_total_checks; \ if (!(e)) \ { \ fprintf(stdout, "# assert [%s:%d] %s, %s\n", \ __FILE__, __LINE__, curr_test, #e); \ mt_test_status = -1; \ + ++mt_checks_failed; \ return; \ } } while (0) @@ -135,11 +141,13 @@ #define mt_fail(e) do { \ + ++mt_total_checks; \ if (!(e)) \ { \ fprintf(stdout, "# assert [%s:%d] %s, %s\n", \ __FILE__, __LINE__, curr_test, #e); \ mt_test_status = -1; \ + ++mt_checks_failed; \ } } while (0) @@ -174,4 +182,10 @@ #define mt_return() do { \ fprintf(stdout, "1..%d\n", mt_total_tests); \ + fprintf(stderr, "# total tests.......:%4d\n", mt_total_tests); \ + fprintf(stderr, "# passed tests......:%4d\n", mt_total_tests - mt_total_failed); \ + fprintf(stderr, "# failed tests......:%4d\n", mt_total_failed); \ + fprintf(stderr, "# total checks......:%4d\n", mt_total_checks); \ + fprintf(stderr, "# passed checks.....:%4d\n", mt_total_checks - mt_checks_failed); \ + fprintf(stderr, "# failed checks.....:%4d\n", mt_checks_failed); \ return mt_total_failed > 254 ? 254 : mt_total_failed; } while(0) @@ -5,7 +5,7 @@ # Author: Michał Łyszczek <michal.lyszczek@bofc.pl> # ========================================================================== # __________________________________________________________ -# / mtest version v1.1.2 \ +# / mtest version v1.1.3 \ # | | # | Simple test framework that uses TAP output format | # \ http://testanything.org / @@ -42,6 +42,8 @@ mt_test_status=0 mt_total_tests=0 mt_total_failed=0 +mt_total_checks=0 +mt_checks_failed=0 mt_current_test="none" @@ -120,10 +122,12 @@ mt_run_named() mt_fail() { + ((mt_total_checks++)) if ! eval $1 then echo "# assert $mt_current_test, '$1'" mt_test_status=1 + ((mt_checks_failed++)) fi } @@ -142,6 +146,16 @@ mt_return() { echo "1..$mt_total_tests" + mt_passed_tests=$((mt_total_tests - mt_total_failed)) + mt_passed_checks=$((mt_total_checks - mt_checks_failed)) + + printf "# total tests.......: %4d\n" ${mt_total_tests} + printf "# passed tests......: %4d\n" ${mt_passed_tests} + printf "# failed tests......: %4d\n" ${mt_total_failed} + printf "# total checks......: %4d\n" ${mt_total_checks} + printf "# passed checks.....: %4d\n" ${mt_passed_checks} + printf "# failed checks.....: %4d\n" ${mt_checks_failed} + if [ $mt_total_failed -gt 254 ] then exit 254 |