Created
November 18, 2010 14:56
-
-
Save yaotti/705076 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- nanotap.h 2010-11-18 23:51:59.000000000 +0900 | |
+++ nanotap+color.h 2010-11-18 23:54:57.000000000 +0900 | |
@@ -18,6 +18,7 @@ | |
#endif | |
static int TEST_COUNT = 0; | |
+static int FAIL_COUNT = 0; | |
/** | |
* This simply evaluates any expression ("$got eq $expected" is just a | |
@@ -25,7 +26,8 @@ | |
* failed. A true expression passes, a false one fails. Very simple. | |
*/ | |
NANOTAP_INLINE NANOTAP_DECLARE void ok(int x, const char *msg) { | |
- printf("%s %d - %s\n", (x ? "ok" : "not ok"), ++TEST_COUNT, msg ? msg : ""); | |
+ if (!x) FAIL_COUNT++; | |
+ printf("%s %d - %s\e[0m\n", (x ? "ok" : "\e[31mnot ok"), ++TEST_COUNT, msg ? msg : ""); | |
} | |
/** | |
@@ -54,6 +56,15 @@ | |
*/ | |
NANOTAP_INLINE NANOTAP_DECLARE void done_testing() { | |
printf("1..%d\n", TEST_COUNT); | |
+ if (!FAIL_COUNT) { | |
+ printf("\e[32mAll tests successful.\e[0m\n"); | |
+ printf("Tests: %d\n", TEST_COUNT); | |
+ printf("Result: PASS\n"); | |
+ } else { | |
+ printf("\e[31mFailed %d/%d tests.\e[0m\n", FAIL_COUNT, TEST_COUNT); | |
+ printf("Tests: %d\n", TEST_COUNT); | |
+ printf("Result: FAIL\n"); | |
+ } | |
exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment