diff --git a/Makefile.am b/Makefile.am index f65517f..591fd16 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,17 +1,20 @@ -include $(top_srcdir)/build-aux/glib-tap.mk - AM_CFLAGS = # CFLAGS applicable to all executables (products) +AM_CPPFLAGS = -I$(top_srcdir)/src # so that tests also find header files -# Convenience library so that it can be resued +# Convenience library so that it can be resued # between my_executable and the tests noinst_LIBRARIES = libcommon.a libcommon_a_SOURCES = src/common.h src/common.c # src/common.h appear in SOURCES to that it gets copied to # distribution tgz. -# The main product -bin_PROGRAMS = myexecutable # make all will generate ./my_executable +# The main product +bin_PROGRAMS = myexecutable # make all will generate ./my_executable + +#include .c and .h in SOURCES so that both appear in dist myexecutable_SOURCES = \ + src/add.c \ + src/add.h \ src/main.c myexecutable_CFLAGS = $(AM_CFLAGS) #--std=c11 # CFLAGS applicable to myexecutable_SOURCES myexecutable_LDADD = libcommon.a @@ -21,17 +24,11 @@ myexecutable_LDADD = libcommon.a # Tests # 'check' comes from 'make check' -test_programs = testsuite +check_PROGRAMS = add.ctaptest +TESTS = 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 -testsuite_SOURCES = tests/test.c - -# In this case the testsuite (test.c) requires glib2.0 -# for the g_test_* test harness. glib2.0 requires specific -# CFLAGS and -l options that are retrieved from pkg-config (configure.ac) -# DEPS_CFLAGS and DEPS_LIBS are filled by PKG_CHECK_MODULES (configure.ac) - -testsuite_CPPFLAGS = -I$(top_srcdir)/src -testsuite_CFLAGS = $(AM_CFLAGS) $(GLIB_CFLAGS) # DEPS_* are filled by PKG_CHECK_MODULES -testsuite_LDADD = $(GLIB_LIBS) libcommon.a # in configure.ac diff --git a/configure.ac b/configure.ac index 0d41a4c..a8e415b 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,6 @@ AC_PREREQ([2.69]) AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS]) AC_CONFIG_AUX_DIR([build-aux]) -AM_PATH_GLIB_2_0 AM_INIT_AUTOMAKE([foreign subdir-objects]) # Does not require NEWS, COPYING, AUTHORS, ChangeLog or README # silent make https://autotools.io/automake/silent.html @@ -14,7 +13,7 @@ AM_SILENT_RULES([yes]) # less verbose make output # AM_SILENT_RULES() # use make -s to get silent output AC_CONFIG_SRCDIR([src/main.c]) -AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_HEADERS([config.h]) # use config.h instead of passing -D in the command line AC_CONFIG_MACRO_DIR([build]) AC_LANG([C]) # Use C not C++ @@ -80,7 +79,6 @@ Are you sure that you want to have myfeature disabled? You will lose this and th fi AC_CONFIG_FILES([Makefile]) -GLIB_TESTS AC_REQUIRE_AUX_FILE([tap-driver.sh]) AC_REQUIRE_AUX_FILE([tap-test]) AC_OUTPUT diff --git a/src/add.c b/src/add.c new file mode 100644 index 0000000..f9049d6 --- /dev/null +++ b/src/add.c @@ -0,0 +1,5 @@ +#include "add.h" + +int add(int a, int b) { + return a + b; +} diff --git a/src/add.h b/src/add.h new file mode 100644 index 0000000..085b06e --- /dev/null +++ b/src/add.h @@ -0,0 +1,6 @@ +#ifndef ADD_H +#define ADD_H + +int add(int a,int b); + +#endif /* ADD_H */ diff --git a/tests/add.c b/tests/add.c new file mode 100644 index 0000000..8a774e4 --- /dev/null +++ b/tests/add.c @@ -0,0 +1,30 @@ +#include "minunit.h" +#include "add.h" +#include /* exit() */ +#include /* perror(), printf(), fprintf() */ + + +int tests_run=0; + +char * add_test() { + mu_assert("add(1,2) must produce 3", add(1,2) == 4); + return 0; +} + +char * all_tests() { + mu_run_test(add_test); + return 0; +} + +int main(int argc, char *argv[]) +{ + char *result = all_tests(); + if (result) { + printf("FAILURE\n"); + exit(1); + } + printf("ALL TESTS PASSED"); + + + return 0; +} diff --git a/tests/minunit.h b/tests/minunit.h new file mode 100644 index 0000000..40a61db --- /dev/null +++ b/tests/minunit.h @@ -0,0 +1,8 @@ +#ifndef MINUNIT_H +#define MINUNIT_H + +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) + +#endif /* MINUNIT_H */