sharness/junit: review
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Mar 14, 2018 at 19:30 UTC
b2b68c8214e4d33f8628ddc8ddb8a2edf0d5685f
2 files changed
+58
-34
test/sharness/Rules.mk
+5
-1
@@ -39,9 +39,13 @@ endif
39
$(d)/aggregate: $(T_$(d))
40
@echo "*** $@ ***"
41
@(cd $(@D) && ./lib/test-aggregate-results.sh)
42
- @(cd $(@D) && ./lib/gen-junit-report.sh)
42
.PHONY: $(d)/aggregate
43
44
+$(d)/test-results/sharness.xml: export TEST_GENERATE_JUNIT=1
45
+$(d)/test-results/sharness.xml: test_sharness_expensive
46
+ @echo "*** $@ ***"
47
+ @(cd $(@D) && ./lib/gen-junit-report.sh)
48
+
49
$(d)/clean-test-results:
50
rm -rf $(@D)/test-results
51
.PHONY: $(d)/clean-test-results
test/sharness/lib/0001-Generate-partial-JUnit-reports.patch
+53
-33
@@ -1,14 +1,14 @@
1
-From 0e2a489651e8e2b1aa4abf1cb2587fc3d0f78ce6 Mon Sep 17 00:00:00 2001
1
+From 8b4a5cd6ebf9dfa462d869559b85b17d2b277d06 Mon Sep 17 00:00:00 2001
2
From: =?UTF-8?q?=C5=81ukasz=20Magiera?= <magik6k@gmail.com>
3
-Date: Thu, 28 Dec 2017 19:24:55 +0100
3
+Date: Wed, 14 Mar 2018 21:26:35 +0100
4
Subject: [PATCH] Generate partial JUnit reports
5
6
---
7
- sharness.sh | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
8
- 1 file changed, 73 insertions(+), 6 deletions(-)
7
+ sharness.sh | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
8
+ 1 file changed, 93 insertions(+), 6 deletions(-)
9
10
diff --git a/sharness.sh b/sharness.sh
11
-index 6750ff7..55e10ac 100644
11
+index 6750ff7..dc99ef9 100644
12
--- a/sharness.sh
13
+++ b/sharness.sh
14
@@ -1,4 +1,4 @@
@@ -17,25 +17,29 @@ index 6750ff7..55e10ac 100644
17
#
18
# Copyright (c) 2011-2012 Mathias Lafeldt
19
# Copyright (c) 2005-2012 Git project
20
-@@ -106,6 +106,8 @@ if test -n "$color"; then
20
+@@ -106,6 +106,10 @@ if test -n "$color"; then
21
test -n "$quiet" && return;;
22
esac
23
shift
24
+
25
-+ echo "$*" >> .junit/tout
25
++ if test -n "$TEST_GENERATE_JUNIT"; then
26
++ echo "$*" >> .junit/tout
27
++ fi
28
printf "%s" "$*"
29
tput sgr0
30
echo
29
-@@ -115,6 +117,8 @@ else
31
+@@ -115,6 +119,10 @@ else
32
say_color() {
33
test -z "$1" && test -n "$quiet" && return
34
shift
35
+
34
-+ echo "$*" >> .junit/tout
36
++ if test -n "$TEST_GENERATE_JUNIT"; then
37
++ echo "$*" >> .junit/tout
38
++ fi
39
printf "%s\n" "$*"
40
}
41
fi
38
-@@ -129,6 +133,12 @@ say() {
42
+@@ -129,6 +137,12 @@ say() {
43
say_color info "$*"
44
}
45
@@ -48,11 +52,17 @@ index 6750ff7..55e10ac 100644
52
test -n "$test_description" || error "Test script did not set test_description."
53
54
if test "$help" = "t"; then
51
-@@ -251,30 +261,69 @@ test_have_prereq() {
55
+@@ -251,30 +265,75 @@ test_have_prereq() {
56
test $total_prereq = $ok_prereq
57
}
58
59
++# junit_testcase generates a testcase xml file after each test
60
++
61
+junit_testcase() {
62
++ if test -z "$TEST_GENERATE_JUNIT"; then
63
++ return
64
++ fi
65
++
66
+ test_name=$1
67
+ tc_file=".junit/case-$(printf "%04d" $test_count)"
68
+
@@ -118,16 +128,20 @@ index 6750ff7..55e10ac 100644
128
}
129
130
# Public: Execute commands in debug mode.
121
-@@ -310,7 +359,7 @@ test_pause() {
131
+@@ -310,7 +369,11 @@ test_pause() {
132
test_eval_() {
133
# This is a separate function because some tests use
134
# "return" to end a test_expect_success block early.
135
- eval </dev/null >&3 2>&4 "$*"
126
-+ eval </dev/null > >(tee -a .junit/tout >&3) 2> >(tee -a .junit/terr >&4) "$*"
136
++ if test -n "$TEST_GENERATE_JUNIT"; then
137
++ eval </dev/null > >(tee -a .junit/tout >&3) 2> >(tee -a .junit/terr >&4) "$*"
138
++ else
139
++ eval </dev/null >&3 2>&4 "$*"
140
++ fi
141
}
142
143
test_run_() {
130
-@@ -355,8 +404,16 @@ test_skip_() {
144
+@@ -355,8 +418,18 @@ test_skip_() {
145
of_prereq=" of $test_prereq"
146
fi
147
@@ -136,17 +150,19 @@ index 6750ff7..55e10ac 100644
150
+ say_color skip >&3 "skipping test: $1"
151
+ say_color skip "ok $test_count # skip $1 (missing $missing_prereqm${of_prereq})"
152
+
139
-+ cat > ".junit/case-$(printf "%04d" $test_count)" <<-EOF
140
-+ <testcase name="$test_count - $(echo $2 | esc_xml)">
141
-+ <skipped>
142
-+ skip $(echo $1 | esc_xml) (missing $missing_prereq${of_prereq})
143
-+ </skipped>
144
-+ </testcase>
145
-+ EOF
153
++ if test -n "$TEST_GENERATE_JUNIT"; then
154
++ cat > ".junit/case-$(printf "%04d" $test_count)" <<-EOF
155
++ <testcase name="$test_count - $(echo $2 | esc_xml)">
156
++ <skipped>
157
++ skip $(echo $1 | esc_xml) (missing $missing_prereq${of_prereq})
158
++ </skipped>
159
++ </testcase>
160
++ EOF
161
++ fi
162
: true
163
;;
164
*)
149
-@@ -403,7 +460,7 @@ test_expect_success() {
165
+@@ -403,7 +476,7 @@ test_expect_success() {
166
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
167
test "$#" = 2 || error "bug in the test script: not 2 or 3 parameters to test_expect_success"
168
export test_prereq
@@ -155,7 +171,7 @@ index 6750ff7..55e10ac 100644
171
say >&3 "expecting success: $2"
172
if test_run_ "$2"; then
173
test_ok_ "$1"
158
-@@ -442,7 +499,7 @@ test_expect_failure() {
174
+@@ -442,7 +515,7 @@ test_expect_failure() {
175
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
176
test "$#" = 2 || error "bug in the test script: not 2 or 3 parameters to test_expect_failure"
177
export test_prereq
@@ -164,7 +180,7 @@ index 6750ff7..55e10ac 100644
180
say >&3 "checking known breakage: $2"
181
if test_run_ "$2" expecting_failure; then
182
test_known_broken_ok_ "$1"
167
-@@ -675,6 +732,7 @@ test_done() {
183
+@@ -675,6 +748,7 @@ test_done() {
184
test_results_dir="$SHARNESS_TEST_DIRECTORY/test-results"
185
mkdir -p "$test_results_dir"
186
test_results_path="$test_results_dir/${SHARNESS_TEST_FILE%.$SHARNESS_TEST_EXTENSION}.$$.counts"
@@ -172,29 +188,33 @@ index 6750ff7..55e10ac 100644
188
189
cat >>"$test_results_path" <<-EOF
190
total $test_count
175
-@@ -684,6 +742,12 @@ test_done() {
191
+@@ -684,6 +758,14 @@ test_done() {
192
failed $test_failure
193
194
EOF
195
+
180
-+ cat >>"$junit_results_path" <<-EOF
181
-+ <testsuite errors="$test_broken" failures="$((test_failure+test_fixed))" tests="$test_count" name="$SHARNESS_TEST_FILE">
182
-+ $(find .junit -name 'case-*' | sort | xargs -i cat "{}")
183
-+ </testsuite>
184
-+ EOF
196
++ if test -n "$TEST_GENERATE_JUNIT"; then
197
++ cat >>"$junit_results_path" <<-EOF
198
++ <testsuite errors="$test_broken" failures="$((test_failure+test_fixed))" tests="$test_count" name="$SHARNESS_TEST_FILE">
199
++ $(find .junit -name 'case-*' | sort | xargs -i cat "{}")
200
++ </testsuite>
201
++ EOF
202
++ fi
203
fi
204
205
if test "$test_fixed" != 0; then
188
-@@ -771,6 +835,9 @@ mkdir -p "$test_dir" || exit 1
206
+@@ -771,6 +853,11 @@ mkdir -p "$test_dir" || exit 1
207
# in subprocesses like git equals our $PWD (for pathname comparisons).
208
cd -P "$test_dir" || exit 1
209
210
+# Prepare JUnit report dir
193
-+mkdir -p .junit
211
++if test -n "$TEST_GENERATE_JUNIT"; then
212
++ mkdir -p .junit
213
++fi
214
+
215
this_test=${SHARNESS_TEST_FILE##*/}
216
this_test=${this_test%.$SHARNESS_TEST_EXTENSION}
217
for skp in $SKIP_TESTS; do
218
--
199
-2.15.1
219
+2.16.2
220