chiark / gitweb /
Test suite: build-modes: Move sbuild knowledge to lib
[dgit.git] / tests / lib-build-modes
1
2 bm-prep-ownpackage-branches () {
3         cat <<'END' >$tmp/stunt-git
4 #!/bin/sh -e
5 case "$*" in
6 *clean*) echo >&2 "BUILD-MODES PROGRAM git $*" ;;
7 esac
8 exec git "$@"
9 END
10         chmod +x $tmp/stunt-git
11
12         bm_branches="$1"
13 }
14
15 bm-prep () {
16         t-tstunt-parsechangelog
17
18         t-prep-newpackage example 1.0
19
20         cd $p
21
22         git checkout -b bad-build-deps indep-arch
23         perl -pe 's/Build-Depends.*/$&, x-dgit-no-such-package/' \
24                 -i debian/control
25         git commit -a -m bad-build-deps
26
27         bm-prep-ownpackage-branches 'indep-arch bad-build-deps'
28
29         if zgrep 'dpkg-buildpackage: Make dependency checks fatal for -S' \
30                 /usr/share/doc/dpkg-dev/changelog.gz; then
31                         dpkgbuildpackage_deps_for_clean=true
32         else
33                         dpkgbuildpackage_deps_for_clean=false
34         fi
35
36         cleanmodes_default="git none dpkg-source dpkg-source-d"
37         cleanmodes_all="$cleanmodes_default git-ff check"
38         cleanmodes="$cleanmodes_default"
39 }
40
41 bm-guess-e-source-e-targets () {
42         local some_act=$1
43         case "$some_act" in
44         sbuild*" --no-arch-all"*)
45                 e_source=true;  e_targets='build-arch binary-arch'      ;;
46         build-source)
47                 e_source=true;  e_targets=''                            ;;
48         *" -b") e_source=false; e_targets='build binary'                ;;
49         *" -B") e_source=false; e_targets='build-arch binary-arch'      ;;
50         *" -A") e_source=false; e_targets='build-indep binary-indep'    ;;
51         *" -S") e_source=true;  e_targets=' '                           ;;
52         *" -F") e_source=true;  e_targets='build binary'                ;;
53         *" -G") e_source=true;  e_targets='build-arch binary-arch'      ;;
54         *" -g") e_source=true;  e_targets='build-indep binary-indep'    ;;
55         *)      e_source=true;  e_targets='build binary'                ;;
56         esac
57 }
58
59
60 bm-report-source () {
61         if "$@"; then
62                 echo >&4 "SOURCE EXISTS"
63         else
64                 echo >&4 "SOURCE MISSING"
65         fi
66 }
67
68 bm-build-deps-ok () {
69         case "$branch" in
70         *bad-build-deps*)       return 1        ;;
71         *)                      return 0        ;;
72         esac
73 }
74
75 bm-compute-expected () {
76         require_fail=unexpect # or required
77         tolerate_fail=unexpect # or tolerate
78
79         exec 4>$bmexp
80         echo >&4 "$heading"
81
82         case $cleanmode in
83         git)            echo >&4 'BUILD-MODES PROGRAM git clean -xdf' ;;
84         git-ff)         echo >&4 'BUILD-MODES PROGRAM git clean -xdff' ;;
85         check)          echo >&4 'BUILD-MODES PROGRAM git clean -xdn' ;;
86         dpkg-source-d)  echo >&4 "EXAMPLE RULES TARGET clean" ;;
87         dpkg-source)    bm-build-deps-ok || tolerate_fail=tolerate
88                         echo >&4 "EXAMPLE RULES TARGET clean"
89                         ;;
90         none)           ;;
91         *)              fail "t-compute-expected-run $cleanmode ??" ;;
92         esac
93
94         if [ "x$e_targets" != x ]; then
95                 # e_targets can be " " to mean `/may/ fail due to b-d'
96                 bm-build-deps-ok || tolerate_fail=tolerate
97         fi
98
99         for t in $e_targets; do
100                 bm-build-deps-ok || require_fail=required
101                 echo >&4 "EXAMPLE RULES TARGET $t"
102         done
103
104         bm-report-source $e_source
105
106         exec 4>&-
107 }
108
109 bm-run-one () {
110         local args="$DGIT_TEST_BM_BASEARGS --clean=$cleanmode $real_act"
111
112         bmid="$act,$cleanmode,$branch"
113         bmid=${bmid// /_}
114
115         heading="===== [$bmid] dgit $args ====="
116
117         bmlog=$tmp/run.$bmid.output
118         bmexp=$tmp/run.$bmid.expected
119         bmgot=$tmp/run.$bmid.results
120
121         bm-compute-expected
122
123         git checkout $branch
124         git clean -xdf # since we might not do any actual cleaning
125
126         dsc='../example_1.0.dsc'
127         rm -f $dsc
128
129         set +o pipefail
130         t-dgit --rm-old-changes --git=$tmp/stunt-git $args 2>&1 | tee $bmlog
131         local ps="${PIPESTATUS[*]}"
132         set -o pipefail
133
134         $bm_quirk_after_act
135
136         exec 4>$bmgot
137         echo >&4 "$heading"
138
139         case $ps in
140         "0 0")  actual_status=success ;;
141         *" 0")  actual_status=failure; echo >&4 "OPERATION FAILED"; ;;
142         *)      fail "tee failed" ;;
143         esac
144
145         case "$require_fail-$tolerate_fail-$actual_status" in
146         required-********-failure) echo >>$bmexp "REQUIRED FAILURE" ;;
147         ********-tolerate-failure) echo >>$bmexp "TOLERATED FAILURE" ;;
148         unexpect-********-success) ;;
149         *)      fail "RF=$require_fail TF=$tolerate_fail AS=$actual_status" ;;
150         esac
151
152         egrep >&4 '^EXAMPLE RULES TARGET|^BUILD-MODES' $bmlog || [ $? = 1 ]
153
154         bm-report-source [ -e $dsc ]
155
156         exec 4>&-
157
158         $bm_quirk_before_diff
159
160         [ $actual_status = failure ] || diff -U10 $bmexp $bmgot
161 }
162
163 bm-act-iterate () {
164         for cleanmode in $cleanmodes; do
165                 for branch in $bm_branches; do
166                         bm-run-one
167                 done
168         done
169         : bm-act-iterate done.
170 }
171
172 bm-alwayssplit () {
173         local t=${0##*/}
174         DGIT_TEST_BM_BASEARGS+=' --always-split-source-build'
175         export DGIT_TEST_BM_BASEARGS
176         t-chain-test "${t%%-asplit}"
177 }