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