On Tue, Apr 16, 2013 at 4:02 AM, David Cantrell <[email protected]> wrote: > 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(); > }
You missed the significant fact that I am passing information into the description in further parameters. That's essential for me, not a nice to have. It allows me to do things like have potentially dubious values appear directly in my test output. (I caught a subtle bug due to seeing that output just last night!) _______________________________________________ Boston-pm mailing list [email protected] http://mail.pm.org/mailman/listinfo/boston-pm

