Define TTEST when ttesting. Also allow multiple assertions per test
This commit is contained in:
parent
1b80c00658
commit
cfa1a15076
@ -27,16 +27,18 @@ extern tt_test tt_tests[];
|
|||||||
#define ASSERT_EQUAL(type, pf, lhs, rhs) do { \
|
#define ASSERT_EQUAL(type, pf, lhs, rhs) do { \
|
||||||
type tt_lhs = (type)(lhs); \
|
type tt_lhs = (type)(lhs); \
|
||||||
type tt_rhs = (type)(rhs); \
|
type tt_rhs = (type)(rhs); \
|
||||||
if(tt_lhs == tt_rhs) return; \
|
if(tt_lhs != tt_rhs) { \
|
||||||
TT_FAIL("Expected <%" pf "> got <%" pf ">", tt_rhs, tt_lhs); \
|
TT_FAIL("Expected <%" pf "> got <%" pf ">", tt_rhs, tt_lhs); \
|
||||||
exit(1); \
|
exit(1); \
|
||||||
|
} \
|
||||||
}while(0);
|
}while(0);
|
||||||
#define ASSERT_NOT_EQUAL(type, pf, lhs, rhs) do { \
|
#define ASSERT_NOT_EQUAL(type, pf, lhs, rhs) do { \
|
||||||
type tt_lhs = (type)(lhs); \
|
type tt_lhs = (type)(lhs); \
|
||||||
type tt_rhs = (type)(rhs); \
|
type tt_rhs = (type)(rhs); \
|
||||||
if(tt_lhs != tt_rhs) return; \
|
if(tt_lhs == tt_rhs) { \
|
||||||
TT_FAIL("Got <%" pf "> but expected anything else", tt_rhs); \
|
TT_FAIL("Got <%" pf "> but expected anything else", tt_rhs); \
|
||||||
exit(1); \
|
exit(1); \
|
||||||
|
} \
|
||||||
}while(0);
|
}while(0);
|
||||||
|
|
||||||
#define ASSERT_STRN(lhs, rhs, n) do { \
|
#define ASSERT_STRN(lhs, rhs, n) do { \
|
||||||
@ -46,10 +48,12 @@ extern tt_test tt_tests[];
|
|||||||
memcpy(tt_lhs, (lhs), tt_n); \
|
memcpy(tt_lhs, (lhs), tt_n); \
|
||||||
memcpy(tt_rhs, (rhs), tt_n); \
|
memcpy(tt_rhs, (rhs), tt_n); \
|
||||||
tt_rhs[tt_n] = tt_lhs[tt_n] = '\0'; \
|
tt_rhs[tt_n] = tt_lhs[tt_n] = '\0'; \
|
||||||
if(!(strncmp(tt_lhs, tt_rhs, tt_n))) {free(tt_lhs); free(tt_rhs); return;} \
|
if(strncmp(tt_lhs, tt_rhs, tt_n)) { \
|
||||||
TT_FAIL("Expected <%s> got <%s>\n", tt_rhs, tt_lhs); \
|
TT_FAIL("Expected <%s> got <%s>\n", tt_rhs, tt_lhs); \
|
||||||
free(tt_lhs); free(tt_rhs); \
|
free(tt_lhs); free(tt_rhs); \
|
||||||
exit(1); \
|
exit(1); \
|
||||||
|
} \
|
||||||
|
free(tt_lhs); free(tt_rhs); \
|
||||||
}while(0);
|
}while(0);
|
||||||
|
|
||||||
#define TEST(name, body) void ttt_##name() { tt_current_test = #name; if(tt_before) tt_before(); body }
|
#define TEST(name, body) void ttt_##name() { tt_current_test = #name; if(tt_before) tt_before(); body }
|
||||||
|
2
ttest
2
ttest
@ -14,7 +14,7 @@ main()
|
|||||||
echo "tt_test tt_tests[] = {${tests}0};" >> $suite.c
|
echo "tt_test tt_tests[] = {${tests}0};" >> $suite.c
|
||||||
|
|
||||||
test_exec=`mktemp`
|
test_exec=`mktemp`
|
||||||
compiler_output=`cc $suite.c -o $test_exec -ggdb -I $dir/include 2>&1`
|
compiler_output=`cc $suite.c -o $test_exec -ggdb -I $dir/include -DTTEST 2>&1`
|
||||||
compiler_status=$?
|
compiler_status=$?
|
||||||
|
|
||||||
echo -e "\x1b[35m$suite\x1b[0m"
|
echo -e "\x1b[35m$suite\x1b[0m"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user