Author: lacton
Date: Sun Oct 5 10:13:06 2008
New Revision: 701831
URL: http://svn.apache.org/viewvc?rev=701831&view=rev
Log:
Fixed test property setting when in a subproject. (BUILDR-126's fix was
incomplete)
Each call to test.options[:properties] was returning a different hash when used
in a subproject. The problem was that the block given to the OpenObject's
underlying hash was not setting the hash itself, but only returning a clone of
the parent's property.
The ruby documentation is quite clear on this issue:
"Hash.new {|hash, key| block } => aHash
<snip>
If a block is specified, it will be called with the hash object and the key,
and should return the default value. It is the blockās responsibility to store
the value in the hash if required."
Modified:
incubator/buildr/trunk/lib/buildr/core/test.rb
incubator/buildr/trunk/spec/core/test_spec.rb
Modified: incubator/buildr/trunk/lib/buildr/core/test.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/test.rb?rev=701831&r1=701830&r2=701831&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/test.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/test.rb Sun Oct 5 10:13:06 2008
@@ -191,7 +191,7 @@
@forced_need = false
parent_task = Project.parent_task(name)
if parent_task.respond_to?(:options)
- @options = OpenObject.new { |hash, key| parent_task.options[key].clone
rescue parent_task.options[key] }
+ @options = OpenObject.new { |hash, key| hash[key] =
parent_task.options[key].clone rescue hash[key] = parent_task.options[key] }
else
@options = OpenObject.new(default_options)
end
Modified: incubator/buildr/trunk/spec/core/test_spec.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/core/test_spec.rb?rev=701831&r1=701830&r2=701831&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/core/test_spec.rb (original)
+++ incubator/buildr/trunk/spec/core/test_spec.rb Sun Oct 5 10:13:06 2008
@@ -470,6 +470,22 @@
end
end
+ it 'should accept to set a test property in the top project' do
+ define 'foo' do
+ test.options[:properties][:foo] = 'bar'
+ end
+ project('foo').test.options[:properties][:foo].should == 'bar'
+ end
+
+ it 'should accept to set a test property in a subproject' do
+ define 'foo' do
+ define 'bar' do
+ test.options[:properties][:bar] = 'baz'
+ end
+ end
+ project('foo:bar').test.options[:properties][:bar].should == 'baz'
+ end
+
it 'should not change options of unrelated projects when using #options' do
define 'foo' do
test.options[:properties][:foo] = 'bar'