Debian Codegraph @

shell/subunit-ui.patch

raw
1 Index: shUnit
2 ===================================================================
3 RCS file: /cvsroot/shunit/ShUnit/shUnit,v
4 retrieving revision 1.14
5 diff -u -p -r1.14 shUnit
6 --- shUnit 18 Mar 2006 04:53:18 -0000 1.14
7 +++ shUnit 14 Apr 2006 16:18:51 -0000
8 @@ -88,16 +88,59 @@ shuFmtNbrTests() {
9 fi
10 }
11
12 +function shuPrintStartRun () {
13 + # print out the start of a test run.
14 + printf "\n****** `basename ${0}` ******\n"
15 + printf "%s to run:\n" "$shuRetFmtNbrTests"
16 +}
17 +
18 +function shuPrintStart () {
19 + # print out the prelude to a single test
20 + # $1 is the test name
21 + # $2 the test number
22 + printf " Test %i: %s " ${2} "${1}"
23 +}
24 +
25 +function shuPrintAfter () {
26 + # print out the result of a single test
27 + # $1 is the test name
28 + # SHU_STR_FAILED contains error text (if any)
29 + printf "\n"
30 +
31 + if test -n "${SHU_STR_FAILED}"
32 + then
33 +
34 + OLD_IFS="${IFS}"
35 + IFS="^"
36 + set -- ${SHU_STR_FAILED}
37 + IFS="${OLD_IFS}"
38 + while [ ${#} -gt 0 ]
39 + do
40 + printf " \"%s\" failed.\n" "${1}"
41 + shift
42 + done
43 + fi
44 +}
45 +
46 +function shuPrintAfterRun () {
47 + # print out the result of the run
48 + # $1 is the number of tests run
49 + # $2 the pass count
50 + # $3 the failure count.
51 + printf "\n%s run.\n" "${1}"
52 + printf " %s succeeded.\n" "${2}"
53 + printf " %s failed.\n\n" "${3}"
54 +}
55 +
56 shuStart() {
57 strInitFunction="${1}"
58
59 eval ${strInitFunction}
60
61 - printf "\n****** `basename ${0}` ******\n"
62 -
63 SHU_TOTAL_NR_OF_TESTS=`echo ${SHU_STR_ALL_TESTS} | wc -w | sed -e 's/ *//'`
64 shuFmtNbrTests "${SHU_TOTAL_NR_OF_TESTS}"
65 - printf "%s to run:\n" "$shuRetFmtNbrTests"
66 +
67 + shuPrintStartRun
68
69 SHU_TOTAL_NR_SUCCEEDED=0
70 shuTestNbr=0
71 @@ -105,33 +148,19 @@ shuStart() {
72 do
73 SHU_STR_FAILED=""
74 shuTestNbr=`expr ${shuTestNbr} + 1`
75 - printf " Test %i: %s " ${shuTestNbr} "${STR_TEST}"
76 + shuPrintStart "${STR_TEST}" ${shuTestNbr}
77 shuRunOneTest ${STR_TEST}
78 - printf "\n"
79 -
80 - if test -n "${SHU_STR_FAILED}"
81 - then
82 -
83 - OLD_IFS="${IFS}"
84 - IFS="^"
85 - set -- ${SHU_STR_FAILED}
86 - IFS="${OLD_IFS}"
87 - while [ ${#} -gt 0 ]
88 - do
89 - printf " \"%s\" failed.\n" "${1}"
90 - shift
91 - done
92 - fi
93 + shuPrintAfter "${STR_TEST}"
94 done
95
96 shuFmtNbrTests "${shuTestNbr}"
97 - printf "\n%s run.\n" "${shuRetFmtNbrTests}"
98 -
99 + number_run="${shuRetFmtNbrTests}"
100 shuFmtNbrTests "${SHU_TOTAL_NR_SUCCEEDED}"
101 - printf " %s succeeded.\n" "${shuRetFmtNbrTests}"
102 -
103 + number_passed="${shuRetFmtNbrTests}"
104 shuFmtNbrTests `expr ${shuTestNbr} - ${SHU_TOTAL_NR_SUCCEEDED}`
105 - printf " %s failed.\n\n" "${shuRetFmtNbrTests}"
106 + number_failed="${shuRetFmtNbrTests}"
107 +
108 + shuPrintAfterRun "${number_run}" "${number_passed}" "${number_failed}"
109 }
110
111 shuRegisterFailedTest() {
112 Index: shUnitTest
113 ===================================================================
114 RCS file: /cvsroot/shunit/ShUnit/shUnitTest,v
115 retrieving revision 1.16
116 diff -u -p -r1.16 shUnitTest
117 --- shUnitTest 31 Dec 2005 06:35:29 -0000 1.16
118 +++ shUnitTest 14 Apr 2006 16:18:51 -0000
119 @@ -121,6 +121,53 @@ TestShuFmtNbrTests() {
120 shuAssert "Failed test case 100 returned [$shuRetFmtNbrTests]" $?
121 }
122
123 +
124 +TestShuPrintStartRun() {
125 + # when not using subunit, print output an idea of what tests will run before starting.
126 + expected=$(printf "\n****** `basename ${0}` ******\n"; printf "%s to run:\n" "$shuRetFmtNbrTests")
127 + result=$(shuPrintStartRun)
128 + [ "x$expected" = "x$result" ] && pass=0 || pass=1
129 + shuAssert "Failed test case incorrect output [$result] wanted [$expected]" ${pass}
130 +}
131 +
132 +
133 +TestShuPrintStart() {
134 + # when not using subunit, print output a human readable pre-test intro.
135 + expected=$(printf " Test 1: phwoar ")
136 + result=$(shuPrintStart phwoar 1)
137 + [ "x$expected" = "x$result" ] && pass=0 || pass=1
138 + shuAssert "Failed test case incorrect output [$result] wanted [$expected]" ${pass}
139 +}
140 +
141 +
142 +TestShuPrintAfter() {
143 + # when not using subunit, print the error text normally.
144 +
145 + # case one : passes
146 + expected=$(printf "\n")
147 + SHU_STR_FAILED=""
148 + result=$(shuPrintAfter phwoar)
149 + [ "x$expected" = "x$result" ] && pass=0 || pass=1
150 + shuAssert "Failed test case incorrect output [$result] wanted [$expected]" ${pass}
151 +
152 + # case two: errors
153 + SHU_STR_FAILED=$(printf "some test\nmore text")
154 + expected=$(printf "\n \"some test\nmore text\" failed.")
155 + result=$(shuPrintAfter phwoar)
156 + SHU_STR_FAILED=""
157 + [ "x$expected" = "x$result" ] && pass=0 || pass=1
158 + shuAssert "Failed test case incorrect output [$result] wanted [$expected]" ${pass}
159 +}
160 +
161 +
162 +TestShuPrintAfterRun() {
163 + # print out a summary of the tests run
164 + expected=$(printf "\n5 run.\n 4 succeeded.\n 1 failed.\n\n")
165 + result=$(shuPrintAfterRun 5 4 1)
166 + [ "x$expected" = "x$result" ] && pass=0 || pass=1
167 + shuAssert "Failed test case incorrect output [$result] wanted [$expected]" ${pass}
168 +}
169 +
170 InitFunction() {
171 shuRegTest TestIntentionalFailure
172 shuRegTest TestShuRegisterFailedTest
173 @@ -130,6 +177,10 @@ InitFunction() {
174 shuRegTest TestShuRunOneTest
175 shuRegTest TestSetupCalledCorrectly
176 shuRegTest TestShuFmtNbrTests
177 + shuRegTest TestShuPrintStartRun
178 + shuRegTest TestShuPrintAfterRun
179 + shuRegTest TestShuPrintStart
180 + shuRegTest TestShuPrintAfter
181 }
182
183
184 --- /dev/null 2006-03-28 06:29:48.000000000 +1100
185 +++ shUnitSubUnit 2006-04-15 02:17:38.000000000 +1000
186 @@ -0,0 +1,74 @@
187 +################################################################################
188 +# shUnit subunit integration
189 +# original by Robert Collins
190 +# $Source: $
191 +# $Id: $
192 +################################################################################
193 +#
194 +
195 +. subunit.sh
196 +
197 +function shuPrintStartRun () {
198 + # print out the start of a test run. This prints nothing
199 + # when using subunit, because we are no longer doing the UI.
200 + :
201 +}
202 +
203 +function shuPrintAfterRun () {
204 + # print out the end of a test run. This prints nothing
205 + # when using subunit, because we are no longer doing the UI.
206 + :
207 +}
208 +
209 +function shuPrintStart () {
210 + # print out the prelude to a single test
211 + # $1 is the test name
212 + # $2 the test number
213 + subunit_start_test "${1}"
214 +}
215 +
216 +function shuPrintAfter () {
217 + # print out the result of a single test
218 + # $1 is the test name
219 + # SHU_STR_FAILED contains error text (if any)
220 + test_name="${1}"
221 + if test -n "${SHU_STR_FAILED}"
222 + then
223 +
224 + OLD_IFS="${IFS}"
225 + IFS="^"
226 + set -- ${SHU_STR_FAILED}
227 + subunit_fail_test "${test_name}" <<<${SHU_STR_FAILED}
228 + IFS="${OLD_IFS}"
229 + else
230 + subunit_pass_test "${1}"
231 + fi
232 +}
233 +
234 +
235 +shuAssert() {
236 + # override assert to be quiet.
237 + strMessage="${1:-}"
238 + boolResult="${2:-${SHU_FALSE}}"
239 +
240 + if [ ${boolResult} -ne ${SHU_TRUE} ]
241 + then
242 + shuRegisterFailedTest "${strMessage}"
243 + else
244 + SHU_TEST_SUCCEEDED=${SHU_TRUE}
245 + fi
246 +}
247 +
248 +shuDeny() {
249 + # override deny to be quiet.
250 + strMessage="${1:-}"
251 + boolResult="${2:-${SHU_TRUE}}"
252 +
253 + if [ ${boolResult} -eq ${SHU_TRUE} ]
254 + then
255 + shuRegisterFailedTest "${strMessage}"
256 + else
257 + SHU_TEST_SUCCEEDED=${SHU_TRUE}
258 + fi
259 +}
260 +
261 --- /dev/null 2006-03-28 06:29:48.000000000 +1100
262 +++ shUnitSubUnitTest 2006-04-15 02:18:19.000000000 +1000
263 @@ -0,0 +1,99 @@
264 +#! /usr/bin/env sh
265 +# Tests for the subunit client UI.
266 +################################################################################
267 +# $Id: $
268 +################################################################################
269 +
270 +#
271 +# find the shUnit file using the command as a reference
272 +#
273 +inherit() {
274 + d=`expr ${0} : '\([a-zA-Z/._-]*\/\)'`
275 + test `expr "$d" : '[./]'` -eq 0 && d="./$d"
276 + . ${d}${1}
277 +}
278 +
279 +inherit shUnit
280 +inherit shUnitSubUnit
281 +
282 +
283 +shuSetUp() {
284 + touch ./test.$$
285 +}
286 +
287 +shuTearDown() {
288 + [ -f ./test.$$ ] && rm ./test.$$
289 +}
290 +
291 +TestShuAssert() {
292 + shuAssert "" "${SHU_TRUE}"
293 + shuAssert "Test case ${SHU_TRUE} failed" "${SHU_TRUE}"
294 +}
295 +
296 +TestShuDeny() {
297 + shuDeny "" "${SHU_FALSE}"
298 + shuDeny "return code ${SHU_FALSE} failed" "${SHU_FALSE}"
299 + shuDeny "return code -1 failed" -1
300 + shuDeny "return code 222 failed" 222
301 +}
302 +
303 +TestShuPrintAfter() {
304 + # for subunit, we delegate to subunit on pass and fail output.
305 +
306 + # case one : passes
307 + expected=$(subunit_pass_test "Test 1")
308 + SHU_STR_FAILED=""
309 + result=$(shuPrintAfter "Test 1")
310 + [ "x$expected" = "x$result" ] && pass=0 || pass=1
311 + shuAssert "Failed test case incorrect output [$result] wanted [$expected]" ${pass}
312 +
313 + # case two: errors
314 + SHU_STR_FAILED=$(printf "some test\nmore text")
315 + expected=$(subunit_fail_test "phwoar" <<END
316 +some test
317 +more text
318 +END)
319 + result=$(shuPrintAfter phwoar)
320 + SHU_STR_FAILED=""
321 + [ "x$expected" = "x$result" ] && pass=0 || pass=1
322 + shuAssert "Failed test case incorrect output [$result] wanted [$expected]" ${pass}
323 +}
324 +
325 +TestShuPrintStartRun() {
326 + # when using subunit, print nothing at the start of the program run
327 + expected=""
328 + result=$(shuPrintStartRun)
329 + [ "x$expected" = "x$result" ] && pass=0 || pass=1
330 + shuAssert "Failed test case incorrect output [$result] wanted [$expected]" ${pass}
331 +}
332 +
333 +TestShuPrintStart() {
334 + # when using subunit, print the subunit header
335 + expected=$(subunit_start_test phwoar)
336 + result=$(shuPrintStart phwoar 1)
337 + [ "x$expected" = "x$result" ] && pass=0 || pass=1
338 + shuAssert "Failed test case incorrect output [$result] wanted [$expected]" ${pass}
339 +}
340 +
341 +TestShuPrintAfterRun() {
342 + # in subunit the runner UI prints out statistics.
343 + expected=""
344 + result=$(shuPrintAfterRun 5 4 1)
345 + [ "x$expected" = "x$result" ] && pass=0 || pass=1
346 + shuAssert "Failed test case incorrect output [$result] wanted [$expected]" ${pass}
347 +}
348 +
349 +InitFunction() {
350 + shuRegTest TestShuAssert
351 + shuRegTest TestShuDeny
352 + shuRegTest TestShuPrintStartRun
353 + shuRegTest TestShuPrintAfterRun
354 + shuRegTest TestShuPrintStart
355 + shuRegTest TestShuPrintAfter
356 +}
357 +
358 +
359 +### Main
360 +
361 +shuStart InitFunction
362 +