On 15/04/2013 19:35, Ben Tilly wrote:
I'm writing some C++ at the moment that fits into the first group
(performance-critical code). For unit testing I've been emitting TAP
protocol and testing it with prove, but are there better approaches?
I get a test file with a lot of code that looks like this:
printf(
"%s %d: Some useful description and maybe a number %d\n",
(expected_value == test_value) ? "ok" : "not ok", ++tests,
some_useful_debugging_info
);
How about abusing the pre-processor to build a strangely
familiar-looking mini-language for testing:
#define OK(result, text) printf("%s %d %s\n", (result ? "ok" : "not
ok"), test_number++, text); if(!(result)) { all_gone_buggerup = 1; }
#define DONE_TESTING() printf("%s\n", all_gone_buggerup ? "FAILED" :
"PASSED"); if(all_gone_buggerup) { return 1; } else { return 0; }
obviously you also need to declare and initialise test_number and
all_gone_buggerup too.
You can then write:
int main(void) {
int test_number = 0;
int all_gone_buggerup = 0;
OK(1 == 1, "it works!");
OK(2 == 1, "oh no it doesn't");
DONE_TESTING();
}
--
David Cantrell | A machine for turning tea into grumpiness
What profiteth a man, if he win a flame war, yet lose his cool?
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm