On Tue, Dec 07, 2004 at 03:18:17PM +1100, Andrew Savige wrote: > Good idea Schwern. > These test suites inevitably degenerate into macro crack-pipe > smoking sessions. Lacking 'eval', it is always going to be very > hard work to even get close to Perl's Test::More functionality > and ease-of-use in C. > > I don't have a filthy enough mind to make your: > cmp_ok(foo, 'int', '==', bar); > macro work (mainly because '==' is not a valid C identifier). > But I can make this one work: > cmp_ok(foo, int, eq, bar); > pretty easily:
Whoa. > #include <stdio.h> > void cmp_ok_inteq(int s, int t) { > printf("in cmp_ok_inteq: %d %d\n", s, t); > } > void cmp_ok_streq(const char* s, const char* t) { > printf("in cmp_ok_streq: '%s' '%s'\n", s, t); > } > #define cmp_ok(s, y, o, t) cmp_ok_##y##o(s, t) > int main() { > int ifoo = 42; > int ibar = 43; > static const char* sfoo = "foo"; > static const char* sbar = "bar"; > cmp_ok(ifoo, int, eq, ibar); > cmp_ok(sfoo, str, eq, sbar); > return 0; > } -- Michael G Schwern [EMAIL PROTECTED] http://www.pobox.com/~schwern/ Kids - don't try this at--oh, hell, go ahead, give it a whirl...