chiark / gitweb /
c80a35c94c0ba4181be1db87af4bfe2f88043764
[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, bc, faketime'
46 }
47
48 gencontrol-add-things () {
49         local varname=$1; shift
50         local thing
51         eval '
52                 for thing in "$@"; do
53                         case " $'$varname'," in
54                         *" "$thing","*) continue ;;
55                         esac
56                         '$varname'+="${'$varname':+, }$thing"
57                 done
58         '
59 }
60
61 restriction-gencontrol () {
62         if [ $r = x-dgit-out-of-tree-only ]; then return; fi
63         restrictions+=" $r"
64 }
65
66 gencontrol-add-deps () {
67         gencontrol-add-things dependencies "$@"
68 }
69
70 dependencies-gencontrol () {
71         for dep in "$deps"; do
72                 case "$dep" in
73                 NO-DGIT) dependencies='chiark-utils-bin, faketime' ;;
74                 NO-DEFAULT) dependencies='' ;;
75                 GDR) gencontrol-add-deps \
76                         git-debrebase git-buildpackage
77                         ;;
78                 DEBORIG) gencontrol-add-deps \
79                         devscripts libdpkg-perl \
80                         libgit-wrapper-perl liblist-compare-perl \
81                         libstring-shellquote-perl libtry-tiny-perl \
82                         # NB git-deborig is not compatible with
83                         #  t-tstunt-parsechangelog
84                         ;;
85                 *) gencontrol-add-deps "$dep" ;;
86                 esac
87         done
88 }
89
90 test-done-gencontrol () {
91         stanza=$(
92                 add_Depends="$dependencies" \
93                 perl <debian/tests/control.in -wpe '
94                         if (/^(\w+):/) {
95                                 my $h = $1;
96                                 s{$}{ $ENV{"add_$h"} // "" }e;
97                         }
98                 ' 
99                 case "$restrictions" in
100                 ?*) echo "Restrictions:$restrictions" ;;
101                 esac
102                 )
103         key=$(printf "%s" "$stanza" | sha256sum)
104         key=${key%% *}
105         eval "
106                 stanza_$key=\"\$stanza\"
107                 tests_$key+=\" \${t#tests/tests/}\"
108         "
109         keys=" ${keys/ $key /}"
110         keys+=" $key "
111 }
112
113 finish-gencontrol () {
114         for key in $keys; do
115                 eval "
116                         stanza=\$stanza_$key
117                         tests=\$tests_$key
118                 "
119                 printf "Tests:%s\n%s\n\n" "$tests" "$stanza"
120         done
121 }
122
123 seddery () {
124         local seddery=$1
125         sed <$tf -n '
126                 20q;
127                 /^: t-enumerate-tests-end$/q;
128                 '"$seddery"'
129         '
130 }
131
132 allsedderies () {
133         local tf=$1
134         for r in $(seddery 's/^t-restrict //p'); do
135                 restriction-$mode
136         done
137         for deps in $(seddery 's/^t-dependencies //p'); do
138                 dependencies-$mode
139         done
140         for import in $(seddery 's/^t-setup-import //p'); do
141                 allsedderies tests/setup/$import
142         done
143 }
144
145 for t in $(run-parts --list tests/tests); do
146         test-begin-$mode
147         allsedderies $t
148         test-done-$mode
149 done
150
151 finish-$mode