diff options
-rw-r--r-- | lib/puppet/parser/compile.rb | 9 | ||||
-rwxr-xr-x | spec/unit/parser/compile.rb | 25 |
2 files changed, 30 insertions, 4 deletions
diff --git a/lib/puppet/parser/compile.rb b/lib/puppet/parser/compile.rb index 7f568f1b3..93ba180a7 100644 --- a/lib/puppet/parser/compile.rb +++ b/lib/puppet/parser/compile.rb @@ -269,10 +269,11 @@ class Puppet::Parser::Compile found_something = false exceptwrap do - @collections.each do |collection| - if collection.evaluate - found_something = true - end + # We have to iterate over a dup of the array because + # collections can delete themselves from the list, which + # changes its length and causes some collections to get missed. + @collections.dup.each do |collection| + found_something = true if collection.evaluate end end diff --git a/spec/unit/parser/compile.rb b/spec/unit/parser/compile.rb index 5f239636b..3be7d1637 100755 --- a/spec/unit/parser/compile.rb +++ b/spec/unit/parser/compile.rb @@ -71,6 +71,31 @@ describe Puppet::Parser::Compile, " when evaluating classes" do end end +describe Puppet::Parser::Compile, " when evaluating collections" do + before do + @node = stub 'node', :name => 'mynode' + @parser = stub 'parser', :version => "1.0" + @scope = stub 'scope', :source => mock("source") + @compile = Puppet::Parser::Compile.new(@node, @parser) + end + + it "should evaluate each collection" do + 2.times { |i| + coll = mock 'coll%s' % i + @compile.add_collection(coll) + + # This is the hard part -- we have to emulate the fact that + # collections delete themselves if they are done evaluating. + coll.expects(:evaluate).with do + @compile.delete_collection(coll) + end + } + + @compile.class.publicize_methods(:evaluate_collections) { @compile.evaluate_collections } + end +end + + describe Puppet::Parser::Compile, " when evaluating found classes" do before do @node = stub 'node', :name => 'mynode' |