From e6f46314a9946872cb204f6f0e8e9f6ff2e021c9 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Tue, 11 Nov 2014 01:30:29 +0100 Subject: [PATCH] Introduced a test suite for the configure project --- Makefile | 7 ++- project.conf | 2 +- tests/Makefile | 26 ++++++++++ tests/library/Makefile.NetBSD | 42 +++++++++++++++++ tests/library/project.conf | 6 +++ tests/project.conf | 7 +++ tests/tests.sh | 89 +++++++++++++++++++++++++++++++++++ 7 files changed, 177 insertions(+), 2 deletions(-) create mode 100644 tests/Makefile create mode 100644 tests/library/Makefile.NetBSD create mode 100644 tests/library/project.conf create mode 100644 tests/project.conf create mode 100755 tests/tests.sh diff --git a/Makefile b/Makefile index ffa491c..9ca50b2 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ PACKAGE = configure VERSION = 0.1.0 -SUBDIRS = doc src tools +SUBDIRS = doc src tests tools OBJDIR = PREFIX = /usr/local DESTDIR = @@ -57,6 +57,11 @@ dist: $(PACKAGE)-$(VERSION)/src/makefile.h \ $(PACKAGE)-$(VERSION)/src/settings.h \ $(PACKAGE)-$(VERSION)/src/project.conf \ + $(PACKAGE)-$(VERSION)/tests/Makefile \ + $(PACKAGE)-$(VERSION)/tests/tests.sh \ + $(PACKAGE)-$(VERSION)/tests/library/project.conf \ + $(PACKAGE)-$(VERSION)/tests/library/Makefile.NetBSD \ + $(PACKAGE)-$(VERSION)/tests/project.conf \ $(PACKAGE)-$(VERSION)/tools/pkg-config.c \ $(PACKAGE)-$(VERSION)/tools/Makefile \ $(PACKAGE)-$(VERSION)/tools/project.conf \ diff --git a/project.conf b/project.conf index 38fc205..7df523a 100644 --- a/project.conf +++ b/project.conf @@ -2,7 +2,7 @@ package=configure version=0.1.0 config=h,sh -subdirs=doc,src,tools +subdirs=doc,src,tests,tools dist=Makefile,AUTHORS,BUGS,CHANGES,COPYING,config.h,config.sh,INSTALL,README [AUTHORS] diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..c195b11 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,26 @@ +TARGETS = tests.log +PREFIX = /usr/local +DESTDIR = +RM = rm -f +LN = ln -f +MKDIR = mkdir -m 0755 -p +INSTALL = install + + +all: $(TARGETS) + +tests.log: ../src/configure library/project.conf library/Makefile.NetBSD tests.sh + ./tests.sh -P "$(PREFIX)" -- "tests.log" + +clean: + $(RM) -- $(tests.log_OBJS) + ./tests.sh -c -P "$(PREFIX)" -- "tests.log" + +distclean: clean + $(RM) -- $(TARGETS) + +install: $(TARGETS) + +uninstall: + +.PHONY: all clean distclean install uninstall diff --git a/tests/library/Makefile.NetBSD b/tests/library/Makefile.NetBSD new file mode 100644 index 0000000..8b76fe9 --- /dev/null +++ b/tests/library/Makefile.NetBSD @@ -0,0 +1,42 @@ +TARGETS = libtest.a libtest.so.0.0 libtest.so.0 libtest.so +PREFIX = /usr/local +DESTDIR = +LIBDIR = $(PREFIX)/lib +AR = ar +RANLIB = ranlib +CCSHARED= $(CC) -shared +RM = rm -f +LN = ln -f +MKDIR = mkdir -m 0755 -p +INSTALL = install + + +all: $(TARGETS) + +libtest_OBJS = test.o +libtest_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) +libtest_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) + +libtest.a: $(libtest_OBJS) + $(AR) -rc libtest.a $(libtest_OBJS) + $(RANLIB) libtest.a + +libtest.so.0.0 libtest.so.0 libtest.so: $(libtest_OBJS) + $(CCSHARED) -o libtest.so.0.0 -Wl,-soname,libtest.so.0 $(libtest_OBJS) $(libtest_LDFLAGS) + $(LN) -s -- libtest.so.0.0 libtest.so.0 + $(LN) -s -- libtest.so.0.0 libtest.so + +test.o: test.c + $(CC) $(libtest_CFLAGS) -c test.c + +clean: + $(RM) -- $(libtest_OBJS) + +distclean: clean + $(RM) -- $(TARGETS) + +install: $(TARGETS) + +uninstall: + +.PHONY: all clean distclean install uninstall diff --git a/tests/library/project.conf b/tests/library/project.conf new file mode 100644 index 0000000..ecfee8d --- /dev/null +++ b/tests/library/project.conf @@ -0,0 +1,6 @@ +targets=libtest +dist=Makefile + +[libtest] +type=library +sources=test.c diff --git a/tests/project.conf b/tests/project.conf new file mode 100644 index 0000000..db8f319 --- /dev/null +++ b/tests/project.conf @@ -0,0 +1,7 @@ +targets=tests.log +dist=Makefile,tests.sh,library/project.conf,library/Makefile.NetBSD + +[tests.log] +type=script +script=./tests.sh +depends=../src/configure,library/project.conf,library/Makefile.NetBSD,tests.sh diff --git a/tests/tests.sh b/tests/tests.sh new file mode 100755 index 0000000..7042d18 --- /dev/null +++ b/tests/tests.sh @@ -0,0 +1,89 @@ +#!/bin/sh +#$Id$ +#Copyright (c) 2014 Pierre Pronchery +# +#Redistribution and use in source and binary forms, with or without +#modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +#AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +#IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +#DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +#FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +#DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +#SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +#OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + +#variables +#executables +CONFIGURE="../src/configure" +DATE="date" +DIFF="diff" + + +#functions +#test +_test() +{ + [ $# -eq 2 ] || return 2 + system="$1" + subdir="$2" + + echo "Testing: $system $subdir" + $CONFIGURE -O "$system" -- "$subdir" 2>&1 || return 2 + $DIFF -- "$subdir/Makefile" "$subdir/Makefile.$system" 2>&1 + res=$? + if [ $res -ne 0 ]; then + echo "Failed with error code $res" + echo "$system $subdir: FAIL" 1>&2 + else + echo "$system $subdir: PASS" 1>&2 + fi +} + + +#usage +_usage() +{ + echo "Usage: test.sh target" 1>&2 + return 1 +} + + +#main +clean=0 +while getopts "cP:" name; do + case "$name" in + c) + clean=1 + ;; + P) + #we can ignore it + ;; + ?) + _usage + exit $? + ;; + esac +done +shift $(($OPTIND - 1)) +if [ $# -ne 1 ]; then + _usage + exit $? +fi + +[ "$clean" -ne 0 ] && exit 0 + +($DATE +echo +_test "NetBSD" "library") > "tests.log"