diff --git a/Makefile.am b/Makefile.am index 591fd16..1b0049b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -24,11 +24,20 @@ myexecutable_LDADD = libcommon.a # Tests # 'check' comes from 'make check' -check_PROGRAMS = add.ctaptest TESTS = add.ctaptest +check_PROGRAMS = add.ctaptest add_ctaptest_SOURCES = tests/add.c src/add.c src/add.h add_ctaptest_CPPFLAGS = $(AM_CPPFLAGS) # so that tests find the header files +# See http://www.gnu.org/software/automake/manual/html_node/Use-TAP-with-the-Automake-test-harness.html +# TESTS ending in .ctaptest should produce TAP output +# 1..2 +# ok 1 - message +# not ok 2 - message +TEST_EXTENSIONS = .ctaptest +CTAPTEST_LOG_DRIVER = env AM_TAP_HAWK='$(AWK)' $(SHELL) $(top_srcdir)/build-aux/tap-driver.sh + + diff --git a/configure.ac b/configure.ac index a8e415b..e1a81c8 100644 --- a/configure.ac +++ b/configure.ac @@ -80,5 +80,4 @@ fi AC_CONFIG_FILES([Makefile]) AC_REQUIRE_AUX_FILE([tap-driver.sh]) -AC_REQUIRE_AUX_FILE([tap-test]) AC_OUTPUT diff --git a/tests/add.c b/tests/add.c index 8a774e4..c8c5b63 100644 --- a/tests/add.c +++ b/tests/add.c @@ -6,13 +6,20 @@ int tests_run=0; -char * add_test() { - mu_assert("add(1,2) must produce 3", add(1,2) == 4); +char * test_add_fail() { + mu_assert("add(1,2) must produce 4", add(1,2) == 4); + return 0; +} + +char * test_add_sucess() { + mu_assert("add(1,2) must produce 3", add(1,2) == 3); return 0; } char * all_tests() { - mu_run_test(add_test); + printf("1..2\n"); + mu_run_test("test_add_fail", test_add_fail); + mu_run_test("test_add_sucess", test_add_sucess); return 0; } @@ -20,11 +27,10 @@ int main(int argc, char *argv[]) { char *result = all_tests(); if (result) { - printf("FAILURE\n"); - exit(1); + printf("# FAILURE\n"); } - printf("ALL TESTS PASSED"); + printf("#ALL TESTS PASSED\n"); - return 0; + return 0; /* tap tests report failures via stdout not exit code */ } diff --git a/tests/minunit.h b/tests/minunit.h index 40a61db..9294a16 100644 --- a/tests/minunit.h +++ b/tests/minunit.h @@ -3,6 +3,6 @@ extern int tests_run; #define mu_assert(message,test) do { if (!(test)) return message; } while (0) -#define mu_run_test(test) do { char *result = test(); tests_run++; if (result) return result; } while (0) +#define mu_run_test(test_name, test) do { printf("# starting test %s\n", test_name); char *result = test(); tests_run++; if (result) {printf("not "); } printf("ok %d - %s\n", tests_run, test_name);} while (0) #endif /* MINUNIT_H */