From 363ffadd4686467d09f3c9301769c7e371ac1d89 Mon Sep 17 00:00:00 2001 From: Francesco Salvestrini Date: Sat, 8 Aug 2009 15:50:30 +0200 Subject: [PATCH 1/2] Added testing framework --- .gitignore | 4 + Makefile.am | 2 + configure.ac | 2 +- tests/Makefile.am | 31 ++++++++ tests/aclocal-1.test | 19 +++++ tests/autoconf-1.test | 21 +++++ tests/ax_compare_version-1.test | 39 ++++++++++ tests/ax_compare_version-2.test | 29 +++++++ tests/ax_need_awk-1.test | 29 +++++++ tests/ax_prog_perl_version-1.test | 39 ++++++++++ tests/ax_with_prog-1.test | 33 ++++++++ tests/defs.in | 151 +++++++++++++++++++++++++++++++++++++ tests/fail-1.test | 10 +++ tests/success-1.test | 10 +++ 14 files changed, 418 insertions(+), 1 deletions(-) create mode 100644 tests/Makefile.am create mode 100755 tests/aclocal-1.test create mode 100755 tests/autoconf-1.test create mode 100755 tests/ax_compare_version-1.test create mode 100755 tests/ax_compare_version-2.test create mode 100755 tests/ax_need_awk-1.test create mode 100755 tests/ax_prog_perl_version-1.test create mode 100755 tests/ax_with_prog-1.test create mode 100644 tests/defs.in create mode 100755 tests/fail-1.test create mode 100755 tests/success-1.test diff --git a/.gitignore b/.gitignore index 5f3fe03..f462fae 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,7 @@ /configure /gnulib /maint.mk +/tests/Makefile +/tests/Makefile.in +/tests/defs +/tests/*.dir diff --git a/Makefile.am b/Makefile.am index ca7f018..6772d6f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,6 +13,8 @@ dist_html_DATA = $(HTMLFILE) EXTRA_DIST = build-aux/git-version-gen +SUBDIRS = tests + # maintainer rules dist-hook: diff --git a/configure.ac b/configure.ac index 0b43b7a..3a0cb9a 100644 --- a/configure.ac +++ b/configure.ac @@ -35,7 +35,7 @@ done AC_SUBST([HTMLFILE]) AC_MSG_RESULT([done]) -AC_CONFIG_FILES([Makefile]) +AC_CONFIG_FILES([Makefile tests/Makefile tests/defs]) AC_OUTPUT dnl Responsibility shifts to the user after this point. diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..877e1e4 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,31 @@ +# Tests environment for the Autoconf Archive. +# +# Copyright (c) 2009 by Francesco Salvestrini +# Licensed under the terms of the GNU General Public License. + +CLEANFILES = defs +EXTRA_DIST = defs.in + +check_SCRIPTS = defs + +FAIL_TESTS = \ + fail-1.test \ + ax_compare_version-2.test + +SUCCESS_TESTS = \ + success-1.test \ + aclocal-1.test \ + autoconf-1.test \ + ax_need_awk-1.test \ + ax_compare_version-1.test \ + ax_with_prog-1.test \ + ax_prog_perl_version-1.test + +XFAIL_TESTS = $(FAIL_TESTS) +TESTS = $(FAIL_TESTS) $(SUCCESS_TESTS) + + +clean-local: clean-local-check +.PHONY: clean-local-check +clean-local-check: + @rm -rf *.dir diff --git a/tests/aclocal-1.test b/tests/aclocal-1.test new file mode 100755 index 0000000..69ca5d0 --- /dev/null +++ b/tests/aclocal-1.test @@ -0,0 +1,19 @@ +#! /bin/sh + +# Copyright (C) 2009 Francesco Salvestrini +# Licensed under the terms of the GNU General Public License. + +# Test to ensure that the test environment has a good set-up + +must_have="aclocal" + +. ./defs || exit 1 + +cat > ./configure.ac < ./configure.ac < ./configure.ac < ./configure.ac < ./configure.ac < ./configure.ac < ./configure.ac </dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' +elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then + set -o posix +fi + +# Ensure we are running from the right directory. +test -f ./defs || { + echo "defs: not found in current directory" 1>&2 + exit 1 +} + +# If srcdir is not set, then we are not running from `make check', be verbose. +if test -z "$srcdir"; then + test -z "$VERBOSE" && VERBOSE=x + # compute $srcdir. + srcdir=`echo "$0" | sed -e 's,/[^\\/]*$,,'` + test $srcdir = $0 && srcdir=. +fi + +# Ensure $srcdir is set correctly. +test -f $srcdir/defs.in || { + echo "$srcdir/defs.in not found, check \$srcdir" 1>&2 + exit 1 +} + +me=`echo "$0" | sed -e 's,.*[\\/],,;s/\.test$//'` + +# See how redirections should work. User can set VERBOSE to see all +# output. +test -z "$VERBOSE" && { + exec > /dev/null 2>&1 +} + +# Make sure we override the user shell. +SHELL='@SHELL@' +export SHELL + +test -z "$AUTOCONF" && AUTOCONF="autoconf" +test -z "$ACLOCAL" && ACLOCAL="aclocal -I @abs_top_srcdir@/m4" +test -z "$AUTOMAKE" && AUTOMAKE="automake" + +PATH=`pwd`:$PATH +echo $PATH + +# +# NOTE: +# exit 77 means SKIP to automake +# + +# Check that each must_have tool is present. +if test -n "$must_have" +then + for tool in $must_have + do + case $tool in + lua) + echo "$me: running lua -v" + ( lua -v ) && one_found="yes" + ;; + # Generic case: the tool must support --version. + *) + echo "$me: running $tool --version" + ( $tool --version ) || exit 77 + ;; + esac + done +fi + +# Check that at least one should_have tool is present. +if test -n "$should_have" +then + one_found="no" + for tool in $should_have + do + case $tool in + lua) + echo "$me: running lua -v" + ( lua -v ) && one_found="yes" + ;; + # Generic case: the tool must support --version. + *) + echo "$me: running $tool --version" + ( $tool --version ) && one_found="yes" + ;; + esac + done + if test x"$one_found" == x"no" ; then + exit 77 + fi +fi + +# Always use an absolute srcdir. Otherwise symlinks made in subdirs +# of the test dir just won't work. +case "$srcdir" in + [\\/]* | ?:[\\/]*) + ;; + + *) + srcdir=`CDPATH=: && cd "$srcdir" && pwd` + ;; +esac + +testname=`basename $0 .test` +chmod -R a+rwx ${testname}.dir > /dev/null 2>&1 +rm -rf ${testname}.dir > /dev/null 2>&1 +mkdir ${testname}.dir + +cd ./${testname}.dir + +echo "=== Running test $0" + +# The tests call `make -e' but we do not want $srcdir from the environment +# to override the definition from the Makefile. +testsrcdir=$srcdir +unset srcdir + +# Turn on shell traces when VERBOSE=x. +if test "x$VERBOSE" = xx; then + set -x +else + : +fi + +pwd diff --git a/tests/fail-1.test b/tests/fail-1.test new file mode 100755 index 0000000..5d5e51d --- /dev/null +++ b/tests/fail-1.test @@ -0,0 +1,10 @@ +#! /bin/sh + +# Copyright (C) 2009 Francesco Salvestrini +# Licensed under the terms of the GNU General Public License. + +# Test to ensure that the test environment has a good set-up + +. ./defs || exit 1 + +exit 1 diff --git a/tests/success-1.test b/tests/success-1.test new file mode 100755 index 0000000..c9d47f9 --- /dev/null +++ b/tests/success-1.test @@ -0,0 +1,10 @@ +#! /bin/sh + +# Copyright (C) 2009 Francesco Salvestrini +# Licensed under the terms of the GNU General Public License. + +# Test to ensure that the test environment has a good set-up + +. ./defs || exit 1 + +exit 0 -- 1.6.3.3