From 498a78cd9f8a11354d49378fdc1fb8ab21374466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Wed, 14 Feb 2018 14:51:01 +0100 Subject: [PATCH] Tougher tests, and test the tests. --- toolchain/ttest.h | 6 +++--- toolchain/ttest.tt | 48 ++++++++++++++++++++++++++++++++++++++++++++++ ttest | 4 ++-- 3 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 toolchain/ttest.tt diff --git a/toolchain/ttest.h b/toolchain/ttest.h index 6d35f23..6e6a9e2 100644 --- a/toolchain/ttest.h +++ b/toolchain/ttest.h @@ -5,7 +5,7 @@ #include -#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 { \ @@ -33,7 +33,7 @@ char *tt_rhs = (char *)(rhs); \ if(!tt_lhs || !tt_rhs) \ { \ - TT_FAIL("Expected string, got null pointer", 0); \ + TT_FAIL("Expected string, got null pointer"); \ return 1; \ } \ size_t tt_n = (size_t)(n); \ @@ -90,7 +90,7 @@ int tt_verbose = 0; int tt_silent = 0; struct tt_test *tt_tests; struct tt_test *tt_current; -int tt_max_name_len = 0; +unsigned int tt_max_name_len = 0; int tt_test_count = 0; void tt_register(char *name, int (*fn)(void), char *filename) diff --git a/toolchain/ttest.tt b/toolchain/ttest.tt new file mode 100644 index 0000000..6aad2e1 --- /dev/null +++ b/toolchain/ttest.tt @@ -0,0 +1,48 @@ +// vim: ft=c +#include + + +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); +} diff --git a/ttest b/ttest index 832e90e..8f0c047 100755 --- a/ttest +++ b/ttest @@ -1,6 +1,6 @@ #!/bin/sh -dirs=src/kernel +dirs="toolchain src/kernel" main() { @@ -10,7 +10,7 @@ main() for suite in $files; do 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=$? if [[ "$compiler_status" -eq "0" ]]; then