lib/java/test.rb in buildr-1.2.5 vs lib/java/test.rb in buildr-1.2.6
- old
+ new
@@ -140,11 +140,11 @@
# List of supported test framework, first one being a default. Test frameworks are added by
# including them in TestTask (e.g. JUnit, TestNG).
TEST_FRAMEWORKS = []
# Default options already set on each test task.
- DEFAULT_OPTIONS = { :fail_on_failure=>true, :fork=>:once, :properties=>{} }
+ DEFAULT_OPTIONS = { :fail_on_failure=>true, :fork=>:once, :properties=>{}, :environment=>{} }
# JMock version..
JMOCK_VERSION = "1.2.0"
# JMock specification.
JMOCK_REQUIRES = "jmock:jmock:jar:#{JMOCK_VERSION}"
@@ -256,10 +256,11 @@
# Currently supports the following options:
# * :fail_on_failure -- True to fail on test failure (default is true).
# * :fork -- Fork test cases (JUnit only).
# * :java_args -- Java arguments when forking a new JVM.
# * :properties -- System properties.
+ # * :environment -- Environment variables.
#
# The :fork option takes the following values:
# * :once -- Fork one JVM for each project (default).
# * :each -- Fork one JVM for each test case.
# * false -- Do not fork, running all test cases in the same JVM.
@@ -308,11 +309,11 @@
def classes()
base = Pathname.new(compile.target.to_s)
patterns = self.class.const_get("#{framework.to_s.upcase}_TESTS_PATTERN").to_a
FileList[patterns.map { |pattern| "#{base}/**/#{pattern}.class" }].
map { |file| Pathname.new(file).relative_path_from(base).to_s.ext("").gsub(File::SEPARATOR, ".") }.
- select { |name| include?(name) }.flatten.sort
+ select { |name| include?(name) }.reject { |name| name =~ /\$/ }.sort
end
# List of failed test classes. Set after running the tests.
attr_reader :failed_tests
@@ -367,11 +368,12 @@
puts "Running tests in #{@project.name}" if verbose
@failed_tests = send("#{framework}_run",
:classes => classes,
:classpath => @classpath + [compile.target],
:properties => { "baseDir" => compile.target.to_s }.merge(options[:properties] || {}),
- :java_args => options[:java_args])
+ :environment=> options[:environment] || {},
+ :java_args => options[:java_args] || Buildr.options.java_args)
unless @failed_tests.empty?
warn "The following tests failed:\n#{@failed_tests.join("\n")}" if verbose
fail "Tests failed!"
end
end
@@ -481,12 +483,16 @@
when true, :once
forking = { :fork=>true, :forkmode=>"once" }
else
fail "Option fork must be :once, :each or false."
end
- ant.junit forking do
+ ant.junit forking.merge(:clonevm=>true) do
ant.classpath :path=>args[:classpath].map(&:to_s).each { |path| file(path).invoke }.join(File::PATH_SEPARATOR)
args[:properties].each { |key, value| ant.sysproperty :key=>key, :value=>value }
+ args[:environment].each { |key, value| ant.env :key=>key, :value=>value }
+ java_args = args[:java_args]
+ java_args = java_args.split(" ") if String === java_args
+ java_args.each { |value| ant.jvmarg :value=>value } if java_args
ant.formatter :type=>"plain"
ant.formatter :type=>"xml"
ant.formatter :type=>"plain", :usefile=>false # log test
ant.formatter :type=>"xml"
ant.batchtest :todir=>report_to.to_s, :failureproperty=>"failed" do