chiark / gitweb /
test suite: enumerate-tests: Refactor dependencies, support NO-DEFAULT
[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         whynot="${whynot//
19 / / }"
20         set -e
21         case "$rc.$whynot" in
22         0.)     ;;
23         1.?*)   whynots="$whynots${whynots:+; }$whynot" ;;
24         *)      fail "restriction $r for $t gave $rc $whynot !"
25         esac
26 }
27
28 dependencies- () {
29         :
30 }
31
32 test-done- () {
33         case "$whynots" in
34         '')     echo $t ;;
35         ?*)     echo >&2 "SKIP $t $whynots" ;;
36         esac
37 }
38
39 finish- () {
40         :
41 }
42
43 test-begin-gencontrol () {
44         restrictions=''
45         dependencies='dgit, dgit-infrastructure, devscripts, debhelper (>=8), fakeroot, build-essential, chiark-utils-bin'
46 }
47
48 restriction-gencontrol () {
49         restrictions+=" $r"
50 }
51
52 gencontrol-add-deps () {
53         for dep in "$@"; do
54                 dependencies+="${dependencies:+, }$dep"
55         done
56 }
57
58 dependencies-gencontrol () {
59         for dep in "$deps"; do
60                 case "$dep" in
61                 NO-DEFAULT) dependencies='' ;;
62                 *) gencontrol-add-deps "$dep" ;;
63                 esac
64         done
65 }
66
67 test-done-gencontrol () {
68         stanza=$(
69                 add_Depends="$dependencies" \
70                 perl <debian/tests/control.in -wpe '
71                         if (/^(\w+):/) {
72                                 my $h = $1;
73                                 s{$}{ $ENV{"add_$h"} // "" }e;
74                         }
75                 ' 
76                 case "$restrictions" in
77                 ?*) echo "Restrictions:$restrictions" ;;
78                 esac
79                 )
80         key=$(printf "%s" "$stanza" | sha256sum)
81         key=${key%% *}
82         eval "
83                 stanza_$key=\"\$stanza\"
84                 tests_$key+=\" \${t#tests/tests/}\"
85         "
86         keys=" ${keys/ $key /}"
87         keys+=" $key "
88 }
89
90 finish-gencontrol () {
91         for key in $keys; do
92                 eval "
93                         stanza=\$stanza_$key
94                         tests=\$tests_$key
95                 "
96                 printf "Tests:%s\n%s\n\n" "$tests" "$stanza"
97         done
98 }
99
100 seddery () {
101         local seddery=$1
102         sed <$t -n '
103                 20q;
104                 /^: t-enumerate-tests-end$/q;
105                 '"$seddery"'
106         '
107 }
108
109 for t in $(run-parts --list tests/tests); do
110         test-begin-$mode
111         for r in $(seddery 's/^t-restrict //p'); do
112                 restriction-$mode
113         done
114         for deps in $(seddery 's/^t-dependencies //p'); do
115                 dependencies-$mode
116         done
117         test-done-$mode
118 done
119
120 finish-$mode