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