chiark / gitweb /
d0582f65a93ac86b8eabfde404c1f5b1ec472063
[dgit.git] / tests / list-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         set -e
19         case "$rc.$whynot" in
20         0.)     ;;
21         1.?*)   whynots="$whynots${whynots:+; }$whynot" ;;
22         *)      fail "restriction $r for $t gave $rc $whynot !"
23         esac
24 }
25
26 test-done- () {
27         case "$whynots" in
28         '')     echo $t ;;
29         ?*)     echo >&2 "SKIP $t $whynots" ;;
30         esac
31 }
32
33 finish- () {
34         :
35 }
36
37 test-begin-gencontrol () {
38         restrictions=''
39 }
40
41 restriction-gencontrol () {
42         restrictions+=" $r"
43 }
44
45 test-done-gencontrol () {
46         stanza=$(
47                 sed <debian/tests/control.in ''
48                 case "$restrictions" in
49                 ?*) echo "Restrictions:$restrictions" ;;
50                 esac
51                 )
52         key=$(printf "%s" "$stanza" | sha256sum)
53         key=${key%% *}
54         eval "
55                 stanza_$key=\"\$stanza\"
56                 tests_$key+=\" \${t#tests/tests/}\"
57         "
58         keys=" ${keys/ $key /}"
59         keys+=" $key "
60 }
61
62 finish-gencontrol () {
63         for key in $keys; do
64                 eval "
65                         stanza=\$stanza_$key
66                         tests=\$tests_$key
67                 "
68                 printf "Tests:%s\n%s\n\n" "$tests" "$stanza"
69         done
70 }
71
72 for t in $(run-parts --list tests/tests); do
73         test-begin-$mode
74         for r in $(sed <$t -n '
75                 20q;
76                 /^: t-list-tests-end$/q;                
77                 s/^t-restrict //p
78         '); do
79                 restriction-$mode
80         done
81         test-done-$mode
82 done
83
84 finish-$mode