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