chiark / gitweb /
Test suite: rename list-tests to enumerate-tests for ease of completion over tests...
[dgit.git] / tests / enumerate-tests
1 #!/bin/bash
2
3 set -e
4
5 . tests/lib-core
6 . tests/lib-restricts
7
8 mode=$1
9
10 test-begin- () {
11         whynots=''
12 }
13
14 restriction- () {
15         set +e
16         whynot=$(t-restriction-$r)
17         rc=$?
18         set -e
19         case "$rc.$whynot" in
20         0.)     ;;
21         1.?*)   whynots="$whynots${whynots:+; }$whynot" ;;
22         *)      fail "restriction $r for $t gave $rc $whynot !"
23         esac
24 }
25
26 dependencies- () {
27         :
28 }
29
30 test-done- () {
31         case "$whynots" in
32         '')     echo $t ;;
33         ?*)     echo >&2 "SKIP $t $whynots" ;;
34         esac
35 }
36
37 finish- () {
38         :
39 }
40
41 test-begin-gencontrol () {
42         restrictions=''
43         dependencies=''
44 }
45
46 restriction-gencontrol () {
47         restrictions+=" $r"
48 }
49
50 dependencies-gencontrol () {
51         dependencies+=", $deps"
52 }
53
54 test-done-gencontrol () {
55         stanza=$(
56                 add_Depends="$dependencies" \
57                 perl <debian/tests/control.in -wpe '
58                         if (/^(\w+):/) {
59                                 my $h = $1;
60                                 s{$}{ $ENV{"add_$h"} // "" }e;
61                         }
62                 ' 
63                 case "$restrictions" in
64                 ?*) echo "Restrictions:$restrictions" ;;
65                 esac
66                 )
67         key=$(printf "%s" "$stanza" | sha256sum)
68         key=${key%% *}
69         eval "
70                 stanza_$key=\"\$stanza\"
71                 tests_$key+=\" \${t#tests/tests/}\"
72         "
73         keys=" ${keys/ $key /}"
74         keys+=" $key "
75 }
76
77 finish-gencontrol () {
78         for key in $keys; do
79                 eval "
80                         stanza=\$stanza_$key
81                         tests=\$tests_$key
82                 "
83                 printf "Tests:%s\n%s\n\n" "$tests" "$stanza"
84         done
85 }
86
87 seddery () {
88         local seddery=$1
89         sed <$t -n '
90                 20q;
91                 /^: t-enumerate-tests-end$/q;
92                 '"$seddery"'
93         '
94 }
95
96 for t in $(run-parts --list tests/tests); do
97         test-begin-$mode
98         for r in $(seddery 's/^t-restrict //p'); do
99                 restriction-$mode
100         done
101         for deps in $(seddery 's/^t-dependencies //p'); do
102                 dependencies-$mode
103         done
104         test-done-$mode
105 done
106
107 finish-$mode