Change glib test framework to minunit
This commit is contained in:
parent
7acc23761a
commit
844bdf6d3c
23
Makefile.am
23
Makefile.am
|
@ -1,6 +1,5 @@
|
||||||
include $(top_srcdir)/build-aux/glib-tap.mk
|
|
||||||
|
|
||||||
AM_CFLAGS = # CFLAGS applicable to all executables (products)
|
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
|
# between my_executable and the tests
|
||||||
|
@ -11,7 +10,11 @@ libcommon_a_SOURCES = src/common.h src/common.c
|
||||||
|
|
||||||
# The main product
|
# The main product
|
||||||
bin_PROGRAMS = myexecutable # make all will generate ./my_executable
|
bin_PROGRAMS = myexecutable # make all will generate ./my_executable
|
||||||
|
|
||||||
|
#include .c and .h in SOURCES so that both appear in dist
|
||||||
myexecutable_SOURCES = \
|
myexecutable_SOURCES = \
|
||||||
|
src/add.c \
|
||||||
|
src/add.h \
|
||||||
src/main.c
|
src/main.c
|
||||||
myexecutable_CFLAGS = $(AM_CFLAGS) #--std=c11 # CFLAGS applicable to myexecutable_SOURCES
|
myexecutable_CFLAGS = $(AM_CFLAGS) #--std=c11 # CFLAGS applicable to myexecutable_SOURCES
|
||||||
myexecutable_LDADD = libcommon.a
|
myexecutable_LDADD = libcommon.a
|
||||||
|
@ -21,17 +24,11 @@ myexecutable_LDADD = libcommon.a
|
||||||
# Tests
|
# Tests
|
||||||
# 'check' comes from 'make check'
|
# '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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
AC_PREREQ([2.69])
|
AC_PREREQ([2.69])
|
||||||
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
|
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
|
||||||
AC_CONFIG_AUX_DIR([build-aux])
|
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
|
AM_INIT_AUTOMAKE([foreign subdir-objects]) # Does not require NEWS, COPYING, AUTHORS, ChangeLog or README
|
||||||
|
|
||||||
# silent make https://autotools.io/automake/silent.html
|
# 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
|
# AM_SILENT_RULES() # use make -s to get silent output
|
||||||
|
|
||||||
AC_CONFIG_SRCDIR([src/main.c])
|
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_CONFIG_MACRO_DIR([build])
|
||||||
|
|
||||||
AC_LANG([C]) # Use C not C++
|
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
|
fi
|
||||||
|
|
||||||
AC_CONFIG_FILES([Makefile])
|
AC_CONFIG_FILES([Makefile])
|
||||||
GLIB_TESTS
|
|
||||||
AC_REQUIRE_AUX_FILE([tap-driver.sh])
|
AC_REQUIRE_AUX_FILE([tap-driver.sh])
|
||||||
AC_REQUIRE_AUX_FILE([tap-test])
|
AC_REQUIRE_AUX_FILE([tap-test])
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
|
5
src/add.c
Normal file
5
src/add.c
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#include "add.h"
|
||||||
|
|
||||||
|
int add(int a, int b) {
|
||||||
|
return a + b;
|
||||||
|
}
|
6
src/add.h
Normal file
6
src/add.h
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef ADD_H
|
||||||
|
#define ADD_H
|
||||||
|
|
||||||
|
int add(int a,int b);
|
||||||
|
|
||||||
|
#endif /* ADD_H */
|
30
tests/add.c
Normal file
30
tests/add.c
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#include "minunit.h"
|
||||||
|
#include "add.h"
|
||||||
|
#include <stdlib.h> /* exit() */
|
||||||
|
#include <stdio.h> /* 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;
|
||||||
|
}
|
8
tests/minunit.h
Normal file
8
tests/minunit.h
Normal file
|
@ -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 */
|
Loading…
Reference in New Issue
Block a user