From: Ian Jackson Date: Sat, 25 Jul 2015 16:36:18 +0000 (+0100) Subject: Test suite: Introduce tests/list-tests X-Git-Tag: debian/1.1~53 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=commitdiff_plain;h=ada48ca013e77d7e821d326db40bc1a59ba639ea;ds=sidebyside Test suite: Introduce tests/list-tests --- diff --git a/tests/Makefile b/tests/Makefile index 011bd3c2..157b487b 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,7 +1,7 @@ # usage: tests/using-intree make -f tests/Makefile # (optionally setting TESTSCRIPTS='tests/tests/foo tests/tests/bar') -TESTSCRIPTS ?= $(shell run-parts --list tests/tests) +TESTSCRIPTS ?= $(shell tests/list-tests) TESTNAMES := $(notdir $(TESTSCRIPTS)) all: $(foreach t,$(TESTNAMES),tests/tmp/$t.ok) diff --git a/tests/lib b/tests/lib index e81a62ad..d131e7b2 100644 --- a/tests/lib +++ b/tests/lib @@ -5,6 +5,7 @@ set -x set -o pipefail . tests/lib-core +. tests/lib-restricts t-set-intree @@ -596,6 +597,11 @@ t-policy-periodic () { test-dummy $drs_dispatch '' --cron } +t-restrict () { + local restriction=$1 + (cd $root; t-restriction-$restriction >&2) +} + t-chain-test () { local ct=$1 local d=${0%/*} diff --git a/tests/lib-restricts b/tests/lib-restricts new file mode 100644 index 00000000..aca66926 --- /dev/null +++ b/tests/lib-restricts @@ -0,0 +1,13 @@ +#!/bin/sh + +t-restriction-x-dgit-intree-only () { + if [ "x$DGIT_TEST_INTREE" != x ]; then return 0; fi + echo 'running installed package version' + return 1 +} + +t-restriction-x-dgit-git-only () { + if test -d .git; then return 0; fi + echo 'not running out of git clone' + return 1 +} diff --git a/tests/list-tests b/tests/list-tests new file mode 100755 index 00000000..21f96b47 --- /dev/null +++ b/tests/list-tests @@ -0,0 +1,43 @@ +#!/bin/bash + +set -e + +. tests/lib-core +. tests/lib-restricts + +mode=$1 + +test-begin- () { + whynots='' +} + +restriction- () { + set +e + whynot=$(t-restriction-$r) + rc=$? + set -e + case "$rc.$whynot" in + 0.) ;; + 1.?*) whynots="$whynots${whynots:+; }$whynot" ;; + *) fail "restriction $r for $t gave $rc $whynot !" + esac +} + +test-done- () { + case "$whynots" in + '') echo $t ;; + ?*) echo >&2 "SKIP $t $whynots" ;; + esac +} + +for t in $(run-parts --list tests/tests); do + test-begin-$mode + for r in $(sed <$t -n ' + 20q; + /^: t-list-tests-end$/q; + s/^t-restrict //p + '); do + restriction-$mode + done + test-done-$mode +done diff --git a/tests/tests/dsd-clone-drs b/tests/tests/dsd-clone-drs index aa162bb0..16bfa2ea 100755 --- a/tests/tests/dsd-clone-drs +++ b/tests/tests/dsd-clone-drs @@ -2,15 +2,8 @@ set -e . tests/lib -if [ "x$DGIT_TEST_INTREE" = x ]; then - echo >&2 'running installed package version, cannot test self-clone' - exit 0 -fi - -if ! test -d $root/.git; then - echo >&2 'not running out of git clone, cannot test self-clone' - exit 0 -fi +t-restrict x-dgit-intree-only +t-restrict x-dgit-git-only t-dsd