Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[6model/c/t/Test.h] initial TAP emitter for C based tests
  • Loading branch information
mberends committed Jul 9, 2011
1 parent dcfb55a commit 665397f
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions c/t/Test.h
@@ -0,0 +1,45 @@
/* Test.h */

/* Lightweight TAP (Test Anything Protocol) emitter in C macros. */

/* Example usage:
#include <string.h>
#include "../Test.h"
int
main(int argc, char * argv[])
{
char s[7];
plan(1);
ok(1==1, "1 is equal to 1");
is_ii(1+1, 2, "1 plus 1 is equal to 2");
strcpy(s, "foo"); strcat(s, "bar");
is_ss(s, "foobar", "strcpy and strcat");
return 0;
}
*/

#include <stdio.h>

#define plan(count) int testnumber=0; printf("1..%d\n", count)

#define \
ok(flag,desc) \
printf("%sok %d - %s\n", \
flag?"":"not ",++testnumber,desc)

#define \
is_ii(got,expected,desc) \
printf("%sok %d - %s\n", \
got==expected?"":"not ",++testnumber,desc); \
if(got!=expected) \
printf("# got : %d\n# expected : %d\n", got, expected)

#define \
is_ss(got,expected,desc) \
printf("%sok %d - %s\n", \
strcmp(got,expected)?"not ":"",++testnumber,desc)

/* end of Test.h */

0 comments on commit 665397f

Please sign in to comment.