chiark / gitweb /
Test suite: import-nonnative: Test tarbombs
[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=''
46 }
47
48 restriction-gencontrol () {
49         restrictions+=" $r"
50 }
51
52 dependencies-gencontrol () {
53         dependencies+=", $deps"
54 }
55
56 test-done-gencontrol () {
57         stanza=$(
58                 add_Depends="$dependencies" \
59                 perl <debian/tests/control.in -wpe '
60                         if (/^(\w+):/) {
61                                 my $h = $1;
62                                 s{$}{ $ENV{"add_$h"} // "" }e;
63                         }
64                 ' 
65                 case "$restrictions" in
66                 ?*) echo "Restrictions:$restrictions" ;;
67                 esac
68                 )
69         key=$(printf "%s" "$stanza" | sha256sum)
70         key=${key%% *}
71         eval "
72                 stanza_$key=\"\$stanza\"
73                 tests_$key+=\" \${t#tests/tests/}\"
74         "
75         keys=" ${keys/ $key /}"
76         keys+=" $key "
77 }
78
79 finish-gencontrol () {
80         for key in $keys; do
81                 eval "
82                         stanza=\$stanza_$key
83                         tests=\$tests_$key
84                 "
85                 printf "Tests:%s\n%s\n\n" "$tests" "$stanza"
86         done
87 }
88
89 seddery () {
90         local seddery=$1
91         sed <$t -n '
92                 20q;
93                 /^: t-enumerate-tests-end$/q;
94                 '"$seddery"'
95         '
96 }
97
98 for t in $(run-parts --list tests/tests); do
99         test-begin-$mode
100         for r in $(seddery 's/^t-restrict //p'); do
101                 restriction-$mode
102         done
103         for deps in $(seddery 's/^t-dependencies //p'); do
104                 dependencies-$mode
105         done
106         test-done-$mode
107 done
108
109 finish-$mode