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