chiark / gitweb /
Test suite: Introduce tests/list-tests
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 25 Jul 2015 16:36:18 +0000 (17:36 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 25 Jul 2015 17:32:29 +0000 (18:32 +0100)
tests/Makefile
tests/lib
tests/lib-restricts [new file with mode: 0644]
tests/list-tests [new file with mode: 0755]
tests/tests/dsd-clone-drs

index 011bd3c..157b487 100644 (file)
@@ -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)
index e81a62a..d131e7b 100644 (file)
--- 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 (file)
index 0000000..aca6692
--- /dev/null
@@ -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 (executable)
index 0000000..21f96b4
--- /dev/null
@@ -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
index aa162bb..16bfa2e 100755 (executable)
@@ -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