I had only done this partway, because it seemed easier, but not surprisingly, it ended up being more complex.
In addition to those renames, this commit includes fixes to whatever tests I needed to fix to confirm that things were again working. I think most of these broken tests have been broken for a while. Signed-off-by: Luke Kanies <[email protected]> --- lib/puppet/parser/ast/collection.rb | 2 +- lib/puppet/parser/ast/resource.rb | 10 ++-- lib/puppet/parser/ast/resource_defaults.rb | 4 +- lib/puppet/parser/ast/resource_override.rb | 8 ++-- lib/puppet/parser/collector.rb | 4 +- lib/puppet/parser/grammar.ra | 6 +- lib/puppet/parser/parser.rb | 6 +- lib/puppet/type/component.rb | 2 +- spec/integration/parser/collector.rb | 38 ++++++++++++++++++ spec/integration/parser/functions/require.rb | 2 +- spec/unit/other/transbucket.rb | 2 +- spec/unit/parser/ast/resource.rb | 6 +- spec/unit/parser/ast/resource_defaults.rb | 22 ++++++++++ spec/unit/parser/ast/resource_override.rb | 10 ++-- spec/unit/parser/collector.rb | 24 ++++++------ spec/unit/parser/parser.rb | 2 +- spec/unit/type.rb | 4 +- spec/unit/type/component.rb | 6 +- spec/unit/util/reference_serializer.rb | 2 +- test/language/ast.rb | 55 +------------------------- test/language/functions.rb | 11 ++--- test/language/scope.rb | 55 +------------------------- test/language/snippets.rb | 4 +- test/lib/puppettest/parsertesting.rb | 16 +++---- test/lib/puppettest/railstesting.rb | 2 +- test/lib/puppettest/resourcetesting.rb | 8 ++-- test/lib/puppettest/support/collection.rb | 29 ------------- 27 files changed, 132 insertions(+), 208 deletions(-) create mode 100755 spec/integration/parser/collector.rb create mode 100755 spec/unit/parser/ast/resource_defaults.rb delete mode 100644 test/lib/puppettest/support/collection.rb diff --git a/lib/puppet/parser/ast/collection.rb b/lib/puppet/parser/ast/collection.rb index 55e99fc..f3690c1 100644 --- a/lib/puppet/parser/ast/collection.rb +++ b/lib/puppet/parser/ast/collection.rb @@ -31,7 +31,7 @@ class Collection < AST::Branch end newcoll.add_override( - :params => params, + :parameters => params, :file => @file, :line => @line, :source => scope.source, diff --git a/lib/puppet/parser/ast/resource.rb b/lib/puppet/parser/ast/resource.rb index 095e097..5488724 100644 --- a/lib/puppet/parser/ast/resource.rb +++ b/lib/puppet/parser/ast/resource.rb @@ -8,13 +8,13 @@ class Resource < AST::ResourceReference associates_doc attr_accessor :title, :type, :exported, :virtual - attr_reader :params + attr_reader :parameters # Does not actually return an object; instead sets an object # in the current scope. def evaluate(scope) # Evaluate all of the specified params. - paramobjects = params.collect { |param| + paramobjects = parameters.collect { |param| param.safeevaluate(scope) } @@ -58,11 +58,11 @@ class Resource < AST::ResourceReference end # Set the parameters for our object. - def params=(params) + def parameters=(params) if params.is_a?(AST::ASTArray) - @params = params + @parameters = params else - @params = AST::ASTArray.new( + @parameters = AST::ASTArray.new( :line => params.line, :file => params.file, :children => [params] diff --git a/lib/puppet/parser/ast/resource_defaults.rb b/lib/puppet/parser/ast/resource_defaults.rb index f0746ec..aec86d0 100644 --- a/lib/puppet/parser/ast/resource_defaults.rb +++ b/lib/puppet/parser/ast/resource_defaults.rb @@ -4,7 +4,7 @@ class Puppet::Parser::AST # A statement syntactically similar to an ResourceDef, but uses a # capitalized object type and cannot have a name. class ResourceDefaults < AST::Branch - attr_accessor :type, :params + attr_accessor :type, :parameters associates_doc @@ -14,7 +14,7 @@ class Puppet::Parser::AST # Use a resource reference to canonize the type ref = Puppet::Resource.new(@type, "whatever") type = ref.type - params = @params.safeevaluate(scope) + params = @parameters.safeevaluate(scope) parsewrap do scope.setdefaults(type, params) diff --git a/lib/puppet/parser/ast/resource_override.rb b/lib/puppet/parser/ast/resource_override.rb index 2d4f7a8..93ddf4d 100644 --- a/lib/puppet/parser/ast/resource_override.rb +++ b/lib/puppet/parser/ast/resource_override.rb @@ -8,11 +8,11 @@ class Puppet::Parser::AST associates_doc attr_accessor :object - attr_reader :params + attr_reader :parameters # Iterate across all of our children. def each - [...@object,@params].flatten.each { |param| + [...@object,@parameters].flatten.each { |param| #Puppet.debug("yielding param %s" % param) yield param } @@ -27,7 +27,7 @@ class Puppet::Parser::AST hash = {} # Evaluate all of the specified params. - params = @params.collect { |param| + params = @parameters.collect { |param| param.safeevaluate(scope) } @@ -37,7 +37,7 @@ class Puppet::Parser::AST resource = resource.collect do |r| res = Puppet::Parser::Resource.new(r.type, r.title, - :params => params, + :parameters => params, :file => file, :line => line, :source => scope.source, diff --git a/lib/puppet/parser/collector.rb b/lib/puppet/parser/collector.rb index 67bd336..9126cb2 100644 --- a/lib/puppet/parser/collector.rb +++ b/lib/puppet/parser/collector.rb @@ -42,7 +42,7 @@ class Puppet::Parser::Collector objects.each do |res| unless @collected.include?(res.ref) newres = Puppet::Parser::Resource.new(res.type, res.title, - :params => overrides[:params], + :parameters => overrides[:parameters], :file => overrides[:file], :line => overrides[:line], :source => overrides[:source], @@ -83,7 +83,7 @@ class Puppet::Parser::Collector # add a resource override to the soon to be exported/realized resources def add_override(hash) - unless hash[:params] + unless hash[:parameters] raise ArgumentError, "Exported resource try to override without parameters" end diff --git a/lib/puppet/parser/grammar.ra b/lib/puppet/parser/grammar.ra index 0aa31e5..a8bc822 100644 --- a/lib/puppet/parser/grammar.ra +++ b/lib/puppet/parser/grammar.ra @@ -153,20 +153,20 @@ resource: classname LBRACE resourceinstances endsemi RBRACE { result.push ast(AST::Resource, :type => val[0], :title => instance[0], - :params => instance[1]) + :parameters => instance[1]) } } | classname LBRACE params endcomma RBRACE { # This is a deprecated syntax. error "All resource specifications require names" } | classref LBRACE params endcomma RBRACE { # a defaults setting for a type - result = ast(AST::ResourceDefaults, :type => val[0], :params => val[2]) + result = ast(AST::ResourceDefaults, :type => val[0], :parameters => val[2]) } # Override a value set elsewhere in the configuration. resourceoverride: resourceref LBRACE anyparams endcomma RBRACE { @lexer.commentpop - result = ast AST::ResourceOverride, :object => val[0], :params => val[2] + result = ast AST::ResourceOverride, :object => val[0], :parameters => val[2] } # Exported and virtual resources; these don't get sent to the client diff --git a/lib/puppet/parser/parser.rb b/lib/puppet/parser/parser.rb index a1d2341..ffcd458 100644 --- a/lib/puppet/parser/parser.rb +++ b/lib/puppet/parser/parser.rb @@ -1199,7 +1199,7 @@ module_eval(<<'.,.,', 'grammar.ra', 138) result.push ast(AST::Resource, :type => val[0], :title => instance[0], - :params => instance[1]) + :parameters => instance[1]) } result @@ -1218,7 +1218,7 @@ module_eval(<<'.,.,', 'grammar.ra', 158) module_eval(<<'.,.,', 'grammar.ra', 161) def _reduce_36(val, _values, result) # a defaults setting for a type - result = ast(AST::ResourceDefaults, :type => val[0], :params => val[2]) + result = ast(AST::ResourceDefaults, :type => val[0], :parameters => val[2]) result end @@ -1227,7 +1227,7 @@ module_eval(<<'.,.,', 'grammar.ra', 161) module_eval(<<'.,.,', 'grammar.ra', 167) def _reduce_37(val, _values, result) @lexer.commentpop - result = ast AST::ResourceOverride, :object => val[0], :params => val[2] + result = ast AST::ResourceOverride, :object => val[0], :parameters => val[2] result end diff --git a/lib/puppet/type/component.rb b/lib/puppet/type/component.rb index d16cdda..b62954b 100644 --- a/lib/puppet/type/component.rb +++ b/lib/puppet/type/component.rb @@ -40,7 +40,7 @@ Puppet::Type.newtype(:component) do if reference.type == "Class" # 'main' is the top class, so we want to see '//' instead of # its name. - if reference.title == "main" + if reference.title.to_s.downcase == "main" myname = "" else myname = reference.title diff --git a/spec/integration/parser/collector.rb b/spec/integration/parser/collector.rb new file mode 100755 index 0000000..4b1279e --- /dev/null +++ b/spec/integration/parser/collector.rb @@ -0,0 +1,38 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/parser/collector' + +describe Puppet::Parser::Collector do + before do + @scope = Puppet::Parser::Scope.new(:compiler => Puppet::Parser::Compiler.new(Puppet::Node.new("mynode"))) + + @resource = Puppet::Parser::Resource.new("file", "/tmp/testing", :scope => @scope, :source => "fakesource") + {:owner => "root", :group => "bin", :mode => "644"}.each do |param, value| + @resource[param] = value + end + end + + def query(text) + code = "File <| #{text} |>" + parser = Puppet::Parser::Parser.new(@scope.compiler) + parser.parse(code).hostclass("").code[0].query + end + + {true => [%{title == "/tmp/testing"}, %{(title == "/tmp/testing")}, %{group == bin}, + %{title == "/tmp/testing" and group == bin}, %{title == bin or group == bin}, + %{title == "/tmp/testing" or title == bin}, %{title == "/tmp/testing"}, + %{(title == "/tmp/testing" or title == bin) and group == bin}], + false => [%{title == bin}, %{title == bin or (title == bin and group == bin)}, + %{title != "/tmp/testing"}, %{title != "/tmp/testing" and group != bin}] + }.each do |result, ary| + ary.each do |string| + it "should return '#{result}' when collecting resources with '#{string}'" do + str, code = query(string).evaluate @scope + code.should be_instance_of(Proc) + code.call(@resource).should == result + end + end + end +end diff --git a/spec/integration/parser/functions/require.rb b/spec/integration/parser/functions/require.rb index 87c6781..0cb8402 100755 --- a/spec/integration/parser/functions/require.rb +++ b/spec/integration/parser/functions/require.rb @@ -22,6 +22,6 @@ describe "The require function" do @scope.resource["require"].should_not be_nil ref = @scope.resource["require"] ref.type.should == "Class" - ref.title.should == "requiredclass" + ref.title.should == "Requiredclass" end end diff --git a/spec/unit/other/transbucket.rb b/spec/unit/other/transbucket.rb index 63b5137..a761951 100755 --- a/spec/unit/other/transbucket.rb +++ b/spec/unit/other/transbucket.rb @@ -44,7 +44,7 @@ describe Puppet::TransBucket do it "should return use 'component' as the type and the provided type as the title if only a name is provided" do @bucket.name = "mystuff" - @bucket.to_ref.should == "Class[mystuff]" + @bucket.to_ref.should == "Class[Mystuff]" end it "should return nil as its reference when type and name are missing" do diff --git a/spec/unit/parser/ast/resource.rb b/spec/unit/parser/ast/resource.rb index 40074c7..2473fda 100755 --- a/spec/unit/parser/ast/resource.rb +++ b/spec/unit/parser/ast/resource.rb @@ -10,14 +10,14 @@ describe Puppet::Parser::AST::Resource do @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("mynode")) @scope = Puppet::Parser::Scope.new(:compiler => @compiler) @scope.stubs(:resource).returns(stub_everything) - @resource = ast::Resource.new(:title => @title, :type => "file", :params => ast::ASTArray.new(:children => []) ) + @resource = ast::Resource.new(:title => @title, :type => "file", :parameters => ast::ASTArray.new(:children => []) ) @resource.stubs(:qualified_type).returns("Resource") end it "should evaluate all its parameters" do param = stub 'param' param.expects(:safeevaluate).with(@scope).returns Puppet::Parser::Resource::Param.new(:name => "myparam", :value => "myvalue", :source => stub("source")) - @resource.stubs(:params).returns [param] + @resource.stubs(:parameters).returns [param] @resource.evaluate(@scope) end @@ -98,7 +98,7 @@ describe Puppet::Parser::AST::Resource do def resource(type, params = nil) params ||= Puppet::Parser::AST::ASTArray.new(:children => []) - Puppet::Parser::AST::Resource.new(:type => type, :title => Puppet::Parser::AST::String.new(:value => "myresource"), :params => params) + Puppet::Parser::AST::Resource.new(:type => type, :title => Puppet::Parser::AST::String.new(:value => "myresource"), :parameters => params) end it "should be able to generate resources with fully qualified type information" do diff --git a/spec/unit/parser/ast/resource_defaults.rb b/spec/unit/parser/ast/resource_defaults.rb new file mode 100755 index 0000000..b2cec31 --- /dev/null +++ b/spec/unit/parser/ast/resource_defaults.rb @@ -0,0 +1,22 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +describe Puppet::Parser::AST::ResourceDefaults do + + ast = Puppet::Parser::AST + + before :each do + @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("mynode")) + @scope = Puppet::Parser::Scope.new(:compiler => @compiler) + @params = Puppet::Parser::AST::ASTArray.new({}) + @compiler.stubs(:add_override) + end + + it "should add defaults when evaluated" do + default = Puppet::Parser::AST::ResourceDefaults.new :type => "file", :parameters => Puppet::Parser::AST::ASTArray.new(:children => []) + default.evaluate @scope + + @scope.lookupdefaults("file").should_not be_nil + end +end diff --git a/spec/unit/parser/ast/resource_override.rb b/spec/unit/parser/ast/resource_override.rb index 2735757..d327b57 100755 --- a/spec/unit/parser/ast/resource_override.rb +++ b/spec/unit/parser/ast/resource_override.rb @@ -7,7 +7,7 @@ describe Puppet::Parser::AST::ResourceOverride do ast = Puppet::Parser::AST before :each do - @compiler = stub 'compiler' + @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("mynode")) @scope = Puppet::Parser::Scope.new(:compiler => @compiler) @params = ast::ASTArray.new({}) @compiler.stubs(:add_override) @@ -17,7 +17,7 @@ describe Puppet::Parser::AST::ResourceOverride do klass = stub 'klass', :title => "title", :type => "type" object = mock 'object' object.expects(:safeevaluate).with(@scope).returns(klass) - ast::ResourceOverride.new(:object => object, :params => @params ).evaluate(@scope) + ast::ResourceOverride.new(:object => object, :parameters => @params ).evaluate(@scope) end it "should tell the compiler to override the resource with our own" do @@ -25,13 +25,13 @@ describe Puppet::Parser::AST::ResourceOverride do klass = stub 'klass', :title => "title", :type => "one" object = mock 'object', :safeevaluate => klass - ast::ResourceOverride.new(:object => object , :params => @params).evaluate(@scope) + ast::ResourceOverride.new(:object => object , :parameters => @params).evaluate(@scope) end it "should return the overriden resource directly when called with one item" do klass = stub 'klass', :title => "title", :type => "one" object = mock 'object', :safeevaluate => klass - override = ast::ResourceOverride.new(:object => object , :params => @params).evaluate(@scope) + override = ast::ResourceOverride.new(:object => object , :parameters => @params).evaluate(@scope) override.should be_an_instance_of(Puppet::Parser::Resource) override.title.should == "title" override.type.should == "One" @@ -43,7 +43,7 @@ describe Puppet::Parser::AST::ResourceOverride do object = mock 'object', :safeevaluate => [klass1,klass2] - override = ast::ResourceOverride.new(:object => object , :params => @params).evaluate(@scope) + override = ast::ResourceOverride.new(:object => object , :parameters => @params).evaluate(@scope) override.should have(2).elements override.each {|o| o.should be_an_instance_of(Puppet::Parser::Resource) } end diff --git a/spec/unit/parser/collector.rb b/spec/unit/parser/collector.rb index 78d47c6..42da3ff 100755 --- a/spec/unit/parser/collector.rb +++ b/spec/unit/parser/collector.rb @@ -42,7 +42,7 @@ describe Puppet::Parser::Collector, "when initializing" do it "should accept an optional resource override" do @collector = Puppet::Parser::Collector.new(@scope, "resource::type", @equery, @vquery, @form) - override = { :params => "whatever" } + override = { :parameters => "whatever" } @collector.add_override(override) @collector.overrides.should equal(override) end @@ -181,9 +181,9 @@ describe Puppet::Parser::Collector, "when collecting virtual and catalog resourc @compiler.expects(:resources).returns([one]) - @collector.add_override(:params => param ) + @collector.add_override(:parameters => param ) Puppet::Parser::Resource.expects(:new).with { |type, title, h| - h[:params] == param + h[:parameters] == param } @collector.evaluate @@ -197,7 +197,7 @@ describe Puppet::Parser::Collector, "when collecting virtual and catalog resourc @compiler.expects(:resources).returns([one]) - @collector.add_override(:params => param, :source => source ) + @collector.add_override(:parameters => param, :source => source ) Puppet::Parser::Resource.stubs(:new) source.expects(:meta_def).with { |name,block| name == :child_of? } @@ -213,9 +213,9 @@ describe Puppet::Parser::Collector, "when collecting virtual and catalog resourc @compiler.expects(:resources).at_least(2).returns([one]) - @collector.add_override(:params => param ) + @collector.add_override(:parameters => param ) Puppet::Parser::Resource.expects(:new).once.with { |type, title, h| - h[:params] == param + h[:parameters] == param } @collector.evaluate @@ -239,7 +239,7 @@ describe Puppet::Parser::Collector, "when collecting virtual and catalog resourc one.expects(:virtual=).with(false) @compiler.expects(:resources).returns([one]) - @collector.add_override(:params => param ) + @collector.add_override(:parameters => param ) Puppet::Parser::Resource.stubs(:new).returns("whatever") @compiler.expects(:add_override).with("whatever") @@ -266,14 +266,14 @@ describe Puppet::Parser::Collector, "when collecting exported resources" do confine "Cannot test Rails integration without ActiveRecord" => Puppet.features.rails? before do - @scope = stub 'scope', :host => "myhost", :debug => nil - @compiler = mock 'compile' - @scope.stubs(:compiler).returns(@compiler) + @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("mynode")) + @scope = Puppet::Parser::Scope.new :compiler => @compiler @resource_type = "Mytype" @equery = "test = true" @vquery = proc { |r| true } Puppet.settings.stubs(:value).with(:storeconfigs).returns true + Puppet.settings.stubs(:value).with(:environment).returns "production" @collector = Puppet::Parser::Collector.new(@scope, @resource_type, @equery, @vquery, :exported) end @@ -374,9 +374,9 @@ describe Puppet::Parser::Collector, "when collecting exported resources" do @compiler.stubs(:add_override) @compiler.stubs(:add_resource) - @collector.add_override(:params => param ) + @collector.add_override(:parameters => param ) Puppet::Parser::Resource.expects(:new).once.with { |type, title, h| - h[:params] == param + h[:parameters] == param } @collector.evaluate diff --git a/spec/unit/parser/parser.rb b/spec/unit/parser/parser.rb index 8cc29c9..909a73c 100755 --- a/spec/unit/parser/parser.rb +++ b/spec/unit/parser/parser.rb @@ -154,7 +154,7 @@ describe Puppet::Parser do it "should create an ast::ResourceOverride" do ast::ResourceOverride.expects(:new).with { |arg| - arg[:line]==1 and arg[:object].is_a?(ast::ResourceReference) and arg[:params].is_a?(ast::ResourceParam) + arg[:line]==1 and arg[:object].is_a?(ast::ResourceReference) and arg[:parameters].is_a?(ast::ResourceParam) } @parser.parse('Resource["title1","title2"] { param => value }') end diff --git a/spec/unit/type.rb b/spec/unit/type.rb index 58c378f..57d5b4b 100755 --- a/spec/unit/type.rb +++ b/spec/unit/type.rb @@ -429,9 +429,9 @@ describe Puppet::Type::RelationshipMetaparam do param = Puppet::Type.metaparamclass(:require).new(:resource => resource, :value => %w{Foo[bar] Class[test]}) catalog.expects(:resource).with("Foo[bar]").returns "something" - catalog.expects(:resource).with("Class[test]").returns nil + catalog.expects(:resource).with("Class[Test]").returns nil - param.expects(:fail).with { |string| string.include?("Class[test]") } + param.expects(:fail).with { |string| string.include?("Class[Test]") } param.validate_relationship end diff --git a/spec/unit/type/component.rb b/spec/unit/type/component.rb index 64d26d5..ab60e02 100755 --- a/spec/unit/type/component.rb +++ b/spec/unit/type/component.rb @@ -10,11 +10,11 @@ describe component do end it "should use Class as its type when a normal string is provided as the title" do - component.new(:name => "bar").ref.should == "Class[bar]" + component.new(:name => "bar").ref.should == "Class[Bar]" end it "should always produce a resource reference string as its title" do - component.new(:name => "bar").title.should == "Class[bar]" + component.new(:name => "bar").title.should == "Class[Bar]" end it "should have a reference string equivalent to its title" do @@ -49,7 +49,7 @@ describe component do describe "when building up the path" do it "should produce the class name if the component models a class" do - component.new(:name => "Class[foo]").pathbuilder.must == ["foo"] + component.new(:name => "Class[foo]").pathbuilder.must == ["Foo"] end it "should produce an empty string if the component models the 'main' class" do diff --git a/spec/unit/util/reference_serializer.rb b/spec/unit/util/reference_serializer.rb index c3da45a..cfabec4 100644 --- a/spec/unit/util/reference_serializer.rb +++ b/spec/unit/util/reference_serializer.rb @@ -14,7 +14,7 @@ describe Puppet::Util::ReferenceSerializer do describe "when serializing" do it "should yaml-dump resource references" do - ref = Puppet::Parser::Resource::Reference.new(:type => "file", :title => "/foo") + ref = Puppet::Resource.new("file", "/foo") @tester.serialize_value(ref).should =~ /^---/ end diff --git a/test/language/ast.rb b/test/language/ast.rb index 916c34d..a4d4d87 100755 --- a/test/language/ast.rb +++ b/test/language/ast.rb @@ -6,12 +6,10 @@ require 'puppettest' require 'puppet/parser/parser' require 'puppettest/resourcetesting' require 'puppettest/parsertesting' -require 'puppettest/support/collection' class TestAST < Test::Unit::TestCase include PuppetTest::ParserTesting include PuppetTest::ResourceTesting - include PuppetTest::Support::Collection def test_if scope = mkscope @@ -56,41 +54,13 @@ class TestAST < Test::Unit::TestCase ref = resourceoverride("file", "/yayness", "owner" => "blah", "group" => "boo") end - Puppet::Parser::Resource.expects(:new).with { |type, title, o| o.is_a?(Hash) }.returns(:override) - scope.compiler.expects(:add_override).with(:override) + scope.compiler.expects(:add_override).with { |res| res.is_a?(Puppet::Parser::Resource) } ret = nil assert_nothing_raised do ret = ref.evaluate scope end - assert_equal(:override, ret, "Did not return override") - end - - # make sure our resourcedefaults ast object works correctly. - def test_resourcedefaults - scope = mkscope - - # Now make some defaults for files - args = {:source => "/yay/ness", :group => "yayness"} - assert_nothing_raised do - obj = defaultobj "file", args - obj.evaluate scope - end - - hash = nil - assert_nothing_raised do - hash = scope.lookupdefaults("File") - end - - hash.each do |name, value| - assert_instance_of(Symbol, name) # params always convert - assert_instance_of(Puppet::Parser::Resource::Param, value) - end - - args.each do |name, value| - assert(hash[name], "Did not get default %s" % name) - assert_equal(value, hash[name].value) - end + assert_instance_of(Puppet::Parser::Resource, ret, "Did not return override") end def test_collection @@ -114,25 +84,4 @@ class TestAST < Test::Unit::TestCase colls = scope.compiler.instance_variable_get("@collections") assert_equal([ret], colls, "Did not store collector in config's collection list") end - - def test_virtual_collexp - scope = mkscope - - # make a resource - resource = mkresource(:type => "file", :title => "/tmp/testing", - :scope => scope, :params => {:owner => "root", :group => "bin", :mode => "644"}) - - run_collection_queries(:virtual) do |string, result, query| - code = nil - assert_nothing_raised do - str, code = query.evaluate scope - end - - assert_instance_of(Proc, code) - assert_nothing_raised do - assert_equal(result, code.call(resource), - "'#{string}' failed") - end - end - end end diff --git a/test/language/functions.rb b/test/language/functions.rb index 70605f8..8797a46 100755 --- a/test/language/functions.rb +++ b/test/language/functions.rb @@ -382,16 +382,13 @@ class TestLangFunctions < Test::Unit::TestCase end def test_search - parser = mkparser - scope = mkscope(:parser => parser) + scope = mkscope - fun = parser.newdefine("yay::ness") - foo = parser.newdefine("foo::bar") + fun = scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "yay::ness") + foo = scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "foo::bar") search = Puppet::Parser::Functions.function(:search) - assert_nothing_raised do - scope.function_search(["foo", "yay"]) - end + scope.function_search(["foo", "yay"]) ffun = ffoo = nil assert_nothing_raised("Search path change did not work") do diff --git a/test/language/scope.rb b/test/language/scope.rb index d2f6ec7..07f8aa7 100755 --- a/test/language/scope.rb +++ b/test/language/scope.rb @@ -118,53 +118,6 @@ class TestScope < Test::Unit::TestCase assert_equal(top, sub.parent, "Did not find parent scope on second call") end - def test_includefunction - parser = mkparser - scope = mkscope :parser => parser - - myclass = parser.newclass "myclass" - otherclass = parser.newclass "otherclass" - - function = Puppet::Parser::AST::Function.new( - :name => "include", - :ftype => :statement, - :arguments => AST::ASTArray.new( - :children => [nameobj("myclass"), nameobj("otherclass")] - ) - ) - - assert_nothing_raised do - function.evaluate scope - end - - scope.compiler.send(:evaluate_generators) - - [myclass, otherclass].each do |klass| - assert(scope.compiler.class_scope(klass), - "%s was not set" % klass.name) - end - end - - def test_definedfunction - Puppet::Parser::Functions.function(:defined) - parser = mkparser - %w{one two}.each do |name| - parser.newdefine name - end - - scope = mkscope :parser => parser - - assert_nothing_raised { - %w{one two file user}.each do |type| - assert(scope.function_defined([type]), - "Class #{type} was not considered defined") - end - - assert(!scope.function_defined(["nopeness"]), - "Class 'nopeness' was incorrectly considered defined") - } - end - # Make sure we know what we consider to be truth. def test_truth assert_equal(true, Puppet::Parser::Scope.true?("a string"), @@ -179,23 +132,19 @@ class TestScope < Test::Unit::TestCase "undef considered true") end - # Verify that we recursively mark as exported the results of collectable - # components. def test_virtual_definitions_do_not_get_evaluated - config = mkcompiler parser = mkparser + config = mkcompiler # Create a default source parser.newclass("") config.topscope.source = parser.known_resource_types.hostclass("") # And a scope resource - scope_res = Puppet::Parser::Resource.new(:file, "/file", :scope => "scope", :source => "source") + scope_res = Puppet::Parser::Resource.new(:file, "/file", :scope => config.topscope) config.topscope.resource = scope_res args = AST::ASTArray.new( - :file => tempfile(), - :line => rand(100), :children => [nameobj("arg")] ) diff --git a/test/language/snippets.rb b/test/language/snippets.rb index 1ef91be..a0fbe78 100755 --- a/test/language/snippets.rb +++ b/test/language/snippets.rb @@ -123,7 +123,7 @@ class TestSnippets < Test::Unit::TestCase end def randeach(type) - [:properties, :metaparams, :params].collect { |thing| + [:properties, :metaparams, :parameters].collect { |thing| randthing(thing,type) } end @@ -206,7 +206,7 @@ class TestSnippets < Test::Unit::TestCase assert_nothing_raised { assert_equal( - "//testing/Mytype[componentname]/File[/tmp/classtest]", + "//Testing/Mytype[componentname]/File[/tmp/classtest]", file.path) } end diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb index 44c78f2..0cc3dde 100644 --- a/test/lib/puppettest/parsertesting.rb +++ b/test/lib/puppettest/parsertesting.rb @@ -53,9 +53,7 @@ module PuppetTest::ParserTesting def mknode(name = nil) require 'puppet/node' - name ||= "nodename" - Puppet::Network::Handler.handler(:node) - Puppet::Node.new(name) + Puppet::Node.new(name || "nodename") end def mkparser @@ -64,9 +62,9 @@ module PuppetTest::ParserTesting end def mkscope(hash = {}) - hash[:parser] ||= mkparser - compiler ||= mkcompiler(hash[:parser]) - compiler.topscope.source = (hash[:parser].find_hostclass("", "") || hash[:parser].newclass("")) + parser ||= mkparser + compiler ||= mkcompiler + compiler.topscope.source = (parser.find_hostclass("", "") || parser.newclass("")) unless compiler.topscope.source raise "Could not find source for scope" @@ -108,7 +106,7 @@ module PuppetTest::ParserTesting :line => __LINE__, :title => title, :type => type, - :params => resourceinst(params) + :parameters => resourceinst(params) ) } end @@ -126,7 +124,7 @@ module PuppetTest::ParserTesting :line => __LINE__, :object => resourceref(type, title), :type => type, - :params => resourceinst(params) + :parameters => resourceinst(params) ) } end @@ -273,7 +271,7 @@ module PuppetTest::ParserTesting :file => __FILE__, :line => __LINE__, :type => type, - :params => past + :parameters => past ) } end diff --git a/test/lib/puppettest/railstesting.rb b/test/lib/puppettest/railstesting.rb index fb5c15f..04ed0bf 100644 --- a/test/lib/puppettest/railstesting.rb +++ b/test/lib/puppettest/railstesting.rb @@ -33,7 +33,7 @@ module PuppetTest::RailsTesting # Now build a resource resources = [] resources << mkresource(:type => type, :title => title, :exported => true, - :params => params) + :parameters => params) # Now collect our facts facts = Facter.to_hash diff --git a/test/lib/puppettest/resourcetesting.rb b/test/lib/puppettest/resourcetesting.rb index 95fe5bc..2e4db1d 100644 --- a/test/lib/puppettest/resourcetesting.rb +++ b/test/lib/puppettest/resourcetesting.rb @@ -23,11 +23,11 @@ module PuppetTest::ResourceTesting args[param] ||= value end - params = args[:params] || {:one => "yay", :three => "rah"} - if args[:params] == :none - args.delete(:params) + params = args[:parameters] || {:one => "yay", :three => "rah"} + if args[:parameters] == :none + args.delete(:parameters) else - args[:params] = paramify args[:source], params + args[:parameters] = paramify args[:source], params end Parser::Resource.new(type, title, args) diff --git a/test/lib/puppettest/support/collection.rb b/test/lib/puppettest/support/collection.rb deleted file mode 100644 index 9da15ea..0000000 --- a/test/lib/puppettest/support/collection.rb +++ /dev/null @@ -1,29 +0,0 @@ - -module PuppetTest::Support::Collection - def run_collection_queries(form) - {true => [%{title == "/tmp/testing"}, %{(title == "/tmp/testing")}, %{group == bin}, - %{title == "/tmp/testing" and group == bin}, %{title == bin or group == bin}, - %{title == "/tmp/testing" or title == bin}, %{title == "/tmp/testing"}, - %{(title == "/tmp/testing" or title == bin) and group == bin}], - false => [%{title == bin}, %{title == bin or (title == bin and group == bin)}, - %{title != "/tmp/testing"}, %{title != "/tmp/testing" and group != bin}] - }.each do |res, ary| - ary.each do |str| - if form == :virtual - code = "File <| #{str} |>" - else - code = "File <<| #{str} |>>" - end - parser = mkparser - query = nil - - assert_nothing_raised("Could not parse '#{str}'") do - query = parser.parse(code).hostclass("").code[0].query - end - - yield str, res, query - end - end - end -end - -- 1.6.1 -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
