Skip to content

Commit 8f38f10

Browse files
committed
handle surefire
1 parent 9261002 commit 8f38f10

File tree

3 files changed

+56
-7
lines changed

3 files changed

+56
-7
lines changed

Dangerfile

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ def print_errors_summary(program, errors, link = '')
2828

2929
msg = ''
3030
if errors == 1
31-
msg = "#{program} reports about #{errors} error. Please, fix it."
31+
msg = "#{program} reported about #{errors} error. Please, fix it."
3232
elsif errors > 0
33-
msg = "#{program} reports about #{errors} errors. Please, fix them."
33+
msg = "#{program} reported about #{errors} errors. Please, fix them."
3434
end
3535

3636
unless link.empty?
@@ -127,12 +127,12 @@ else
127127
errors_cnt = errors.size()
128128
error_msgs = errors.join("</li>\n<li>")
129129
if errors_cnt == 1
130-
fail("license-maven-plugin reports about #{errors_cnt} error:\n"\
130+
fail("license-maven-plugin reported about #{errors_cnt} error:\n"\
131131
"<ul><li>#{error_msgs}</li></ul>\n"\
132132
"Please, fix it by executing `mvn license:format`\n"\
133133
"See also: <a href=\"#{link}\">#{link}</a>")
134134
elsif errors_cnt > 1
135-
fail("license-maven-plugin reports about #{errors_cnt} errors:\n"\
135+
fail("license-maven-plugin reported about #{errors_cnt} errors:\n"\
136136
"<ul><li>#{error_msgs}</li></ul>\n"\
137137
"Please, fix them by executing `mvn license:format`\n"\
138138
"See also: <a href=\"#{link}\">#{link}</a>")
@@ -166,12 +166,12 @@ else
166166
errors_cnt = errors.size()
167167
error_msgs = errors.join("</li>\n<li>")
168168
if errors_cnt == 1
169-
fail("sortpom-maven-plugin reports about #{errors_cnt} error:\n"\
169+
fail("sortpom-maven-plugin reported about #{errors_cnt} error:\n"\
170170
"<ul><li>#{error_msgs}</li></ul>\n"\
171171
"Please, fix it by executing `mvn sortpom:sort`\n"\
172172
"See also: <a href=\"#{link}\">#{link}</a>")
173173
elsif errors_cnt > 1
174-
fail("sortpom-maven-plugin reports about #{errors_cnt} errors:\n"\
174+
fail("sortpom-maven-plugin reported about #{errors_cnt} errors:\n"\
175175
"<ul><li>#{error_msgs}</li></ul>\n"\
176176
"Please, fix them by executing `mvn sortpom:sort`\n"\
177177
"See also: <a href=\"#{link}\">#{link}</a>")
@@ -400,6 +400,50 @@ else
400400
end
401401
end
402402

403+
# Handle `mvn test` reports
404+
# maven-surefire-plugin generates multiple XML files (one result file per test class).
405+
#
406+
# Example:
407+
# <testsuite name="ru.mystamps.web.service.CronServiceImplTest" time="0.175" tests="7" errors="0" skipped="0" failures="2">
408+
# <testcase name="sendDailyStatistics() should prepare report and pass it to mail service" classname="ru.mystamps.web.service.CronServiceImplTest" time="0.107">
409+
# <failure message="Condition not satisfied: bla bla bla" type="org.spockframework.runtime.SpockComparisonFailure">
410+
# org.spockframework.runtime.SpockComparisonFailure: bla bla bla
411+
# </failure>
412+
# </testcase>
413+
# </testsuite>
414+
#
415+
test_reports_pattern = 'target/surefire-reports/TEST-*.xml'
416+
test_reports = Dir.glob(test_reports_pattern)
417+
if test_reports.empty?
418+
warn("Couldn't find #{test_reports_pattern}. maven-surefire-plugin results is unknown")
419+
else
420+
errors_count = 0
421+
test_reports.each do |file|
422+
doc = Nokogiri::XML(File.open(file))
423+
testsuite = doc.xpath('/testsuite').first
424+
failures = testsuite['failures']
425+
if failures.to_i == 0
426+
next
427+
end
428+
429+
testsuite.xpath('.//failure').each do |failure|
430+
errors_count += 1
431+
msg = failure['message']
432+
tc = failure.parent
433+
file = tc['classname'].gsub(/\./, '/')
434+
path = "src/test/groovy/#{file}.groovy"
435+
if File.file?(path)
436+
file = path
437+
end
438+
# TODO: try to findout the test case and use it for highlighting line numbers
439+
file = github.html_link(file)
440+
testcase = tc['name']
441+
fail("maven-surefire-plugin error in #{file}:\nTest case `#{testcase}` fails with message:\n#{msg}")
442+
end
443+
end
444+
print_errors_summary 'maven-surefire-plugin', errors_count, 'https://github.com/php-coder/mystamps/wiki/unit-tests'
445+
end
446+
403447
# Handle `mvn findbugs:check` results
404448
findbugs_report = 'target/findbugsXml.xml'
405449
unless File.file?(findbugs_report)

pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,10 @@
436436
<commons.lang.version>3.4</commons.lang.version>
437437
<compiler.plugin.version>3.6.1</compiler.plugin.version>
438438
<coveralls.plugin.version>2.2.0</coveralls.plugin.version>
439+
440+
<!-- Disable XML reports by default. Enabled manually by passing -DdisableXmlReport=false in CI environment -->
441+
<disableXmlReport>true</disableXmlReport>
442+
439443
<enforcer.plugin.version>1.4.1</enforcer.plugin.version>
440444
<failsafe.plugin.version>2.19.1</failsafe.plugin.version>
441445
<fest.assert.version>2.0M8</fest.assert.version>
@@ -796,7 +800,7 @@
796800
<version>${surefire.plugin.version}</version>
797801
<configuration>
798802
<skipTests>${skipUnitTests}</skipTests>
799-
<disableXmlReport>true</disableXmlReport>
803+
<disableXmlReport>${disableXmlReport}</disableXmlReport>
800804
<!-- Run junit tests only (see #SUREFIRE-377) -->
801805
<testNGArtifactName>none:none</testNGArtifactName>
802806
</configuration>

src/main/scripts/ci/check-build-and-verify.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then
5353
-Denforcer.skip=true \
5454
-Dmaven.resources.skip=true \
5555
-DskipMinify=true \
56+
-DdisableXmlReport=false \
5657
>test.log 2>&1 || TEST_FAIL=yes
5758
# run after tests for getting compiled sources
5859
mvn --batch-mode findbugs:check >findbugs.log 2>&1 || FINDBUGS_FAIL=yes

0 commit comments

Comments
 (0)