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 011bd3c2b75effc9df9c8fc5b9c580f8bcffa339..157b487bcd988abacdc1ed23dc04ae68954519c3 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 e81a62ad3dd381f438c39d2435e64280db39eba6..d131e7b2a8dc4a6328a32d8cb1016135a896ba58 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 aa162bb09d33e9febcda1a5b0d8d0f0630d74d1a..16bfa2eaa87886326c23d7e9e9708a0fb1d41ec0 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