@@ -28,9 +28,9 @@ def print_errors_summary(program, errors, link = '')
28
28
29
29
msg = ''
30
30
if errors == 1
31
- msg = "#{ program } reports about #{ errors } error. Please, fix it."
31
+ msg = "#{ program } reported about #{ errors } error. Please, fix it."
32
32
elsif errors > 0
33
- msg = "#{ program } reports about #{ errors } errors. Please, fix them."
33
+ msg = "#{ program } reported about #{ errors } errors. Please, fix them."
34
34
end
35
35
36
36
unless link . empty?
@@ -127,12 +127,12 @@ else
127
127
errors_cnt = errors . size ( )
128
128
error_msgs = errors . join ( "</li>\n <li>" )
129
129
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 " \
131
131
"<ul><li>#{ error_msgs } </li></ul>\n " \
132
132
"Please, fix it by executing `mvn license:format`\n " \
133
133
"See also: <a href=\" #{ link } \" >#{ link } </a>" )
134
134
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 " \
136
136
"<ul><li>#{ error_msgs } </li></ul>\n " \
137
137
"Please, fix them by executing `mvn license:format`\n " \
138
138
"See also: <a href=\" #{ link } \" >#{ link } </a>" )
@@ -166,12 +166,12 @@ else
166
166
errors_cnt = errors . size ( )
167
167
error_msgs = errors . join ( "</li>\n <li>" )
168
168
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 " \
170
170
"<ul><li>#{ error_msgs } </li></ul>\n " \
171
171
"Please, fix it by executing `mvn sortpom:sort`\n " \
172
172
"See also: <a href=\" #{ link } \" >#{ link } </a>" )
173
173
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 " \
175
175
"<ul><li>#{ error_msgs } </li></ul>\n " \
176
176
"Please, fix them by executing `mvn sortpom:sort`\n " \
177
177
"See also: <a href=\" #{ link } \" >#{ link } </a>" )
@@ -400,6 +400,50 @@ else
400
400
end
401
401
end
402
402
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 } :\n Test 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
+
403
447
# Handle `mvn findbugs:check` results
404
448
findbugs_report = 'target/findbugsXml.xml'
405
449
unless File . file? ( findbugs_report )
0 commit comments