This is an automated email from the ASF dual-hosted git repository.

donaldp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/buildr.git

commit 5484453e7951711349c19ca3ca496cd5c3978280
Author: Peter Donald <pe...@realityforge.org>
AuthorDate: Mon Nov 11 13:01:26 2019 +1100

    Ensure that if TestNG tests all fail in setup then the test task fails
---
 CHANGELOG                |  3 +++
 lib/buildr/java/tests.rb | 16 +++++++++-------
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 7ebd1fd..b78f0f9 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -8,6 +8,9 @@
           incorrect types for the default values for the `exploded` optional 
property. This is unlikely to have
           caused problems during normal usage but could lead to unexpected 
behaviour when the innards of these
           methods were monkey patched and expected the "correct" type for 
these properties.
+* Fixed:  If all of the TestNG tests failed during the test setup then these 
tests would not be written to the
+          list of failed tests which would mean that buildr would not mark the 
containing projects test task as
+          failing when it runs. This has been patched to report any errors and 
fail the test task as expected.
 
 1.5.8 (2019-07-14)
 * Fixed:  Changed references to `https://repo1.maven.org/maven2` to use https 
where possible.
diff --git a/lib/buildr/java/tests.rb b/lib/buildr/java/tests.rb
index 3cb1156..23bf719 100644
--- a/lib/buildr/java/tests.rb
+++ b/lib/buildr/java/tests.rb
@@ -330,16 +330,18 @@ module Buildr #:nodoc:
         tmp.write cmd_args.join("\n")
         tmp.close
         Java::Commands.java ['org.testng.TestNG', "@#{tmp.path}"], cmd_options
-        return tests
-      rescue
-        # testng-failed.xml contains the list of failed tests *only*
-        report = File.read(File.join(task.report_to.to_s, 'testng-failed.xml'))
+      ensure
+        tmp.close unless tmp.nil?
+      end
+      # testng-failed.xml contains the list of failed tests *only*
+      failed_tests = File.join(task.report_to.to_s, 'testng-failed.xml')
+      if File.exist?(failed_tests)
+        report = File.read(failed_tests)
         failed = report.scan(/<class name="(.*?)">/im).flatten
-        error "TestNG regexp returned unexpected failed tests 
#{failed.inspect}" unless (failed - tests).empty?
         # return the list of passed tests
         return tests - failed
-      ensure
-        tmp.close unless tmp.nil?
+      else
+        return tests
       end
     end
 

Reply via email to