Tougher tests, and test the tests.

This commit is contained in:
Thomas Lovén 2018-02-14 14:51:01 +01:00
parent 2b8fa6047d
commit 498a78cd9f
3 changed files with 53 additions and 5 deletions

View File

@ -5,7 +5,7 @@
#include <string.h> #include <string.h>
#define TT_FAIL(error, ...) dprintf(tt_pipe[1], "\"%s\" Line %d: %s >> " error "\n", tt_current->filename, __LINE__, tt_current->name, __VA_ARGS__); #define TT_FAIL(error, ...) dprintf(tt_pipe[1], "\"%s\" Line %d: %s >> " error "\n", tt_current->filename, __LINE__, tt_current->name, ##__VA_ARGS__);
#define ASSERT_EQUAL(type, pf, lhs, rhs) do { \ #define ASSERT_EQUAL(type, pf, lhs, rhs) do { \
@ -33,7 +33,7 @@
char *tt_rhs = (char *)(rhs); \ char *tt_rhs = (char *)(rhs); \
if(!tt_lhs || !tt_rhs) \ if(!tt_lhs || !tt_rhs) \
{ \ { \
TT_FAIL("Expected string, got null pointer", 0); \ TT_FAIL("Expected string, got null pointer"); \
return 1; \ return 1; \
} \ } \
size_t tt_n = (size_t)(n); \ size_t tt_n = (size_t)(n); \
@ -90,7 +90,7 @@ int tt_verbose = 0;
int tt_silent = 0; int tt_silent = 0;
struct tt_test *tt_tests; struct tt_test *tt_tests;
struct tt_test *tt_current; struct tt_test *tt_current;
int tt_max_name_len = 0; unsigned int tt_max_name_len = 0;
int tt_test_count = 0; int tt_test_count = 0;
void tt_register(char *name, int (*fn)(void), char *filename) void tt_register(char *name, int (*fn)(void), char *filename)

48
toolchain/ttest.tt Normal file
View File

@ -0,0 +1,48 @@
// vim: ft=c
#include <ttest.h>
TEST(two_equal_ints)
{
ASSERT_EQ_INT(1, 1);
}
TEST(FAIL_two_equal_ints)
{
ASSERT_EQ_INT(2, 3);
}
TEST(two_different_ints)
{
ASSERT_NEQ_INT(2, 3);
}
TEST(FAIL_two_different_ints)
{
ASSERT_NEQ_INT(1, 1);
}
TEST(two_equal_chars)
{
ASSERT_EQ_CHR('a', 'a');
}
TEST(FAIL_two_equal_chars)
{
ASSERT_EQ_CHR('b', 'c');
}
TEST(two_different_chars)
{
ASSERT_NEQ_CHR('b', 'c');
}
TEST(FAIL_two_different_chars)
{
ASSERT_NEQ_CHR('a', 'a');
}
TEST(two_equal_strings)
{
ASSERT_EQ_STR("Hello", "Hello", 5);
}
TEST(FAIL_two_equal_strings)
{
ASSERT_EQ_STR("Hello", "World", 5);
}

4
ttest
View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
dirs=src/kernel dirs="toolchain src/kernel"
main() main()
{ {
@ -10,7 +10,7 @@ main()
for suite in $files; do for suite in $files; do
test_exec="${suite}est" test_exec="${suite}est"
compiler_output=`cc -x c $suite -o $test_exec -I $dir/include -I toolchain -DTTEST 2>&1` compiler_output=`cc -x c $suite -o $test_exec -Wall -Wextra -Werror -I $dir/include -I toolchain -DTTEST 2>&1`
compiler_status=$? compiler_status=$?
if [[ "$compiler_status" -eq "0" ]]; then if [[ "$compiler_status" -eq "0" ]]; then