Add a TAP test program in C
This commit is contained in:
parent
844bdf6d3c
commit
924acf4748
11
Makefile.am
11
Makefile.am
|
@ -24,11 +24,20 @@ myexecutable_LDADD = libcommon.a
|
||||||
# Tests
|
# Tests
|
||||||
# 'check' comes from 'make check'
|
# 'check' comes from 'make check'
|
||||||
|
|
||||||
check_PROGRAMS = add.ctaptest
|
|
||||||
TESTS = add.ctaptest
|
TESTS = add.ctaptest
|
||||||
|
check_PROGRAMS = add.ctaptest
|
||||||
|
|
||||||
add_ctaptest_SOURCES = tests/add.c src/add.c src/add.h
|
add_ctaptest_SOURCES = tests/add.c src/add.c src/add.h
|
||||||
add_ctaptest_CPPFLAGS = $(AM_CPPFLAGS) # so that tests find the header files
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -80,5 +80,4 @@ fi
|
||||||
|
|
||||||
AC_CONFIG_FILES([Makefile])
|
AC_CONFIG_FILES([Makefile])
|
||||||
AC_REQUIRE_AUX_FILE([tap-driver.sh])
|
AC_REQUIRE_AUX_FILE([tap-driver.sh])
|
||||||
AC_REQUIRE_AUX_FILE([tap-test])
|
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
|
20
tests/add.c
20
tests/add.c
|
@ -6,13 +6,20 @@
|
||||||
|
|
||||||
int tests_run=0;
|
int tests_run=0;
|
||||||
|
|
||||||
char * add_test() {
|
char * test_add_fail() {
|
||||||
mu_assert("add(1,2) must produce 3", add(1,2) == 4);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char * all_tests() {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,11 +27,10 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *result = all_tests();
|
char *result = all_tests();
|
||||||
if (result) {
|
if (result) {
|
||||||
printf("FAILURE\n");
|
printf("# FAILURE\n");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
printf("ALL TESTS PASSED");
|
printf("#ALL TESTS PASSED\n");
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0; /* tap tests report failures via stdout not exit code */
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
|
|
||||||
extern int tests_run;
|
extern int tests_run;
|
||||||
#define mu_assert(message,test) do { if (!(test)) return message; } while (0)
|
#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 */
|
#endif /* MINUNIT_H */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user