chiark / gitweb /
Test suite: Break out bm-prep-ownpackage-branches
[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         *" -b") e_source=false; e_targets='build binary'                ;;
45         *" -B") e_source=false; e_targets='build-arch binary-arch'      ;;
46         *" -A") e_source=false; e_targets='build-indep binary-indep'    ;;
47         *" -S") e_source=true;  e_targets=' '                           ;;
48         *" -F") e_source=true;  e_targets='build binary'                ;;
49         *" -G") e_source=true;  e_targets='build-arch binary-arch'      ;;
50         *" -g") e_source=true;  e_targets='build-indep binary-indep'    ;;
51         *)      e_source=true;  e_targets='build binary'                ;;
52         esac
53 }
54
55
56 bm-report-source () {
57         if "$@"; then
58                 echo >&4 "SOURCE EXISTS"
59         else
60                 echo >&4 "SOURCE MISSING"
61         fi
62 }
63
64 bm-build-deps-ok () {
65         case "$branch" in
66         *bad-build-deps*)       return 1        ;;
67         *)                      return 0        ;;
68         esac
69 }
70
71 bm-compute-expected () {
72         require_fail=unexpect # or required
73         tolerate_fail=unexpect # or tolerate
74
75         exec 4>$bmexp
76         echo >&4 "$heading"
77
78         case $cleanmode in
79         git)            echo >&4 'BUILD-MODES PROGRAM git clean -xdf' ;;
80         git-ff)         echo >&4 'BUILD-MODES PROGRAM git clean -xdff' ;;
81         check)          echo >&4 'BUILD-MODES PROGRAM git clean -xdn' ;;
82         dpkg-source-d)  echo >&4 "EXAMPLE RULES TARGET clean" ;;
83         dpkg-source)    bm-build-deps-ok || tolerate_fail=tolerate
84                         echo >&4 "EXAMPLE RULES TARGET clean"
85                         ;;
86         none)           ;;
87         *)              fail "t-compute-expected-run $cleanmode ??" ;;
88         esac
89
90         if [ "x$e_targets" != x ]; then
91                 # e_targets can be " " to mean `/may/ fail due to b-d'
92                 bm-build-deps-ok || tolerate_fail=tolerate
93         fi
94
95         for t in $e_targets; do
96                 bm-build-deps-ok || require_fail=required
97                 echo >&4 "EXAMPLE RULES TARGET $t"
98         done
99
100         bm-report-source $e_source
101
102         exec 4>&-
103 }
104
105 bm-run-one () {
106         local args="$DGIT_TEST_BM_BASEARGS --clean=$cleanmode $real_act"
107
108         bmid="$act,$cleanmode,$branch"
109         bmid=${bmid// /_}
110
111         heading="===== [$bmid] dgit $args ====="
112
113         bmlog=$tmp/run.$bmid.output
114         bmexp=$tmp/run.$bmid.expected
115         bmgot=$tmp/run.$bmid.results
116
117         bm-compute-expected
118
119         git checkout $branch
120         git clean -xdf # since we might not do any actual cleaning
121
122         dsc='../example_1.0.dsc'
123         rm -f $dsc
124
125         set +o pipefail
126         t-dgit --rm-old-changes --git=$tmp/stunt-git $args 2>&1 | tee $bmlog
127         local ps="${PIPESTATUS[*]}"
128         set -o pipefail
129
130         $bm_quirk_after_act
131
132         exec 4>$bmgot
133         echo >&4 "$heading"
134
135         case $ps in
136         "0 0")  actual_status=success ;;
137         *" 0")  actual_status=failure; echo >&4 "OPERATION FAILED"; ;;
138         *)      fail "tee failed" ;;
139         esac
140
141         case "$require_fail-$tolerate_fail-$actual_status" in
142         required-********-failure) echo >>$bmexp "REQUIRED FAILURE" ;;
143         ********-tolerate-failure) echo >>$bmexp "TOLERATED FAILURE" ;;
144         unexpect-********-success) ;;
145         *)      fail "RF=$require_fail TF=$tolerate_fail AS=$actual_status" ;;
146         esac
147
148         egrep >&4 '^EXAMPLE RULES TARGET|^BUILD-MODES' $bmlog || [ $? = 1 ]
149
150         bm-report-source [ -e $dsc ]
151
152         exec 4>&-
153
154         $bm_quirk_before_diff
155
156         [ $actual_status = failure ] || diff -U10 $bmexp $bmgot
157 }
158
159 bm-act-iterate () {
160         for cleanmode in $cleanmodes; do
161                 for branch in $bm_branches; do
162                         bm-run-one
163                 done
164         done
165         : bm-act-iterate done.
166 }
167
168 bm-alwayssplit () {
169         local t=${0##*/}
170         DGIT_TEST_BM_BASEARGS+=' --always-split-source-build'
171         export DGIT_TEST_BM_BASEARGS
172         t-chain-test "${t%%-asplit}"
173 }