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