From e9a181c67d7d9bccc4aafd172b14996ae4dc5d43 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 1 May 2013 15:26:21 -0400 Subject: [PATCH] Install tests Matching https://live.gnome.org/GnomeGoals/InstalledTests --- Makefile-tests.am | 49 +++++++++++++++++++++++++++++++++++ Makefile.am | 2 ++ configure.ac | 6 +++++ tests/libtest.sh | 23 ++++------------ tests/t0000-basic.sh | 3 +-- tests/t0001-archive.sh | 2 +- tests/t0002-archivez.sh | 2 +- tests/t0003-log.sh | 2 +- tests/t0004-remote-add.sh | 2 +- tests/t0005-corruption.sh | 2 +- tests/t0006-libarchive.sh | 2 +- tests/t0011-pull-archive-z.sh | 6 ++--- 12 files changed, 72 insertions(+), 29 deletions(-) create mode 100644 Makefile-tests.am diff --git a/Makefile-tests.am b/Makefile-tests.am new file mode 100644 index 00000000..cd22ab2c --- /dev/null +++ b/Makefile-tests.am @@ -0,0 +1,49 @@ +# Makefile for tests code +# +# Copyright (C) 2013 Colin Walters +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + + +if BUILDOPT_INSTALL_TESTS +insttestdir=$(pkglibexecdir)/installed-tests +testfiles = t0000-basic \ + t0001-archive \ + t0002-archivez \ + t0003-log \ + t0004-remote-add \ + t0005-corruption \ + t0006-libarchive \ + t0011-pull-archive-z \ + $(NULL) +insttest_SCRIPTS = $(addprefix tests/,$(testfiles:=.sh)) + +insttest_DATA = tests/archive-test.sh \ + tests/pull-test.sh \ + tests/libtest.sh \ + $(NULL) + +%.test: tests/%.sh Makefile + $(AM_V_GEN) (echo '[Test]' > $@.tmp; \ + echo 'Exec=$(pkglibexecdir)/installed-tests/$(notdir $<)' >> $@.tmp; \ + echo 'Type=session' >> $@.tmp; \ + echo 'Output=TAP' >> $@.tmp; \ + mv $@.tmp $@) + +testmetadir = $(datadir)/installed-tests/$(PACKAGE) +testmeta_DATA = $(testfiles:=.test) + +endif diff --git a/Makefile.am b/Makefile.am index e73c988b..e3ce06cf 100644 --- a/Makefile.am +++ b/Makefile.am @@ -84,6 +84,8 @@ include Makefile-libostree.am include Makefile-ostree.am include Makefile-switchroot.am include Makefile-triggers.am +include Makefile-tests.am + # Docbook generation copied from systemd/Makefile.am # diff --git a/configure.ac b/configure.ac index a81deadc..d95f5d8e 100644 --- a/configure.ac +++ b/configure.ac @@ -33,6 +33,12 @@ AC_ARG_ENABLE(triggers-only, enable_triggers_only=no) AM_CONDITIONAL(TRIGGERS_ONLY, test x$enable_triggers_only != xno) +AC_ARG_ENABLE(installed_tests, + AS_HELP_STRING([--enable-installed-tests], + [Install test programs (default: no)]),, + [enable_installed_tests=no]) +AM_CONDITIONAL(BUILDOPT_INSTALL_TESTS, test x$enable_installed_tests = xyes) + AC_CHECK_HEADER([attr/xattr.h],,[AC_MSG_ERROR([You must have attr/xattr.h from libattr])]) PKG_PROG_PKG_CONFIG diff --git a/tests/libtest.sh b/tests/libtest.sh index 93f8a7d4..e4518f1f 100644 --- a/tests/libtest.sh +++ b/tests/libtest.sh @@ -17,14 +17,8 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -cd `dirname $0` -SRCDIR=`pwd` -cd - -TMPDIR=${TMPDIR:-/tmp} -export TMPDIR -test_tmpdir=`mktemp -d "$TMPDIR/ostree-tests.XXXXXXXXXX"` -cd "$test_tmpdir" -touch "$test_tmpdir/.test$$" +SRCDIR=$(dirname $0) +test_tmpdir=$(pwd) export G_DEBUG=fatal-warnings @@ -36,14 +30,6 @@ if test -n "$OT_TESTS_VALGRIND"; then CMD_PREFIX="env G_SLICE=always-malloc valgrind -q --leak-check=full --num-callers=30 --suppressions=${SRCDIR}/ostree-valgrind.supp" fi -die () { - if test -z "$OT_TESTS_DEBUG"; then - test -f "$test_tmpdir/.test$$" && rm -rf "$test_tmpdir" - else - echo "Temporary files saved in $test_tmpdir" - fi -} - assert_streq () { test "$1" = "$2" || (echo 1>&2 "$1 != $2"; exit 1) } @@ -110,6 +96,9 @@ setup_test_repository () { } setup_fake_remote_repo1() { + if ! test -x ${SRCDIR}/run-apache; then + exit 77 + fi mode=$1 shift oldpwd=`pwd` @@ -170,5 +159,3 @@ EOF export OSTREE="ostree --repo=repo" } - -trap 'die' EXIT diff --git a/tests/t0000-basic.sh b/tests/t0000-basic.sh index 60c20a67..a55c748c 100755 --- a/tests/t0000-basic.sh +++ b/tests/t0000-basic.sh @@ -21,7 +21,7 @@ set -e echo "1..30" -. libtest.sh +. $(dirname $0)/libtest.sh setup_test_repository "bare" echo "ok setup" @@ -218,4 +218,3 @@ echo "ok subdir enoent" cd ${test_tmpdir} $OSTREE checkout test2 --allow-noent --subpath /enoent 2>/dev/null echo "ok subdir noent" - diff --git a/tests/t0001-archive.sh b/tests/t0001-archive.sh index 642cdf9e..c9f934c4 100755 --- a/tests/t0001-archive.sh +++ b/tests/t0001-archive.sh @@ -19,7 +19,7 @@ set -e -. libtest.sh +. $(dirname $0)/libtest.sh echo '1..11' diff --git a/tests/t0002-archivez.sh b/tests/t0002-archivez.sh index 08448162..b9f41919 100755 --- a/tests/t0002-archivez.sh +++ b/tests/t0002-archivez.sh @@ -19,7 +19,7 @@ set -e -. libtest.sh +. $(dirname $0)/libtest.sh echo '1..11' diff --git a/tests/t0003-log.sh b/tests/t0003-log.sh index 2fb5ea80..7c415ff8 100755 --- a/tests/t0003-log.sh +++ b/tests/t0003-log.sh @@ -19,7 +19,7 @@ set -e -. libtest.sh +. $(dirname $0)/libtest.sh echo "1..1" diff --git a/tests/t0004-remote-add.sh b/tests/t0004-remote-add.sh index ffab0fa9..252090b3 100755 --- a/tests/t0004-remote-add.sh +++ b/tests/t0004-remote-add.sh @@ -19,7 +19,7 @@ set -e -. libtest.sh +. $(dirname $0)/libtest.sh echo '1..2' diff --git a/tests/t0005-corruption.sh b/tests/t0005-corruption.sh index 3961d46b..258e0bdc 100755 --- a/tests/t0005-corruption.sh +++ b/tests/t0005-corruption.sh @@ -21,7 +21,7 @@ set -e echo "1..1" -. libtest.sh +. $(dirname $0)/libtest.sh setup_test_repository "bare" $OSTREE checkout test2 checkout-test2 diff --git a/tests/t0006-libarchive.sh b/tests/t0006-libarchive.sh index d941f472..4936389c 100755 --- a/tests/t0006-libarchive.sh +++ b/tests/t0006-libarchive.sh @@ -21,7 +21,7 @@ set -e echo "1..7" -. libtest.sh +. $(dirname $0)/libtest.sh setup_test_repository "bare" cd ${test_tmpdir} diff --git a/tests/t0011-pull-archive-z.sh b/tests/t0011-pull-archive-z.sh index c06003fa..0d208528 100755 --- a/tests/t0011-pull-archive-z.sh +++ b/tests/t0011-pull-archive-z.sh @@ -19,10 +19,10 @@ set -e -. libtest.sh - -echo '1..2' +. $(dirname $0)/libtest.sh setup_fake_remote_repo1 "archive-z2" +echo '1..2' + . ${SRCDIR}/pull-test.sh