summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/parser')
-rwxr-xr-xspec/unit/parser/ast/arithmetic_operator_spec.rb2
-rwxr-xr-xspec/unit/parser/ast/astarray_spec.rb51
-rw-r--r--spec/unit/parser/ast/asthash_spec.rb2
-rwxr-xr-xspec/unit/parser/ast/boolean_operator_spec.rb2
-rwxr-xr-xspec/unit/parser/ast/casestatement_spec.rb28
-rwxr-xr-xspec/unit/parser/ast/collection_spec.rb2
-rwxr-xr-xspec/unit/parser/ast/collexpr_spec.rb2
-rwxr-xr-xspec/unit/parser/ast/comparison_operator_spec.rb2
-rw-r--r--spec/unit/parser/ast/definition_spec.rb22
-rw-r--r--spec/unit/parser/ast/function_spec.rb2
-rw-r--r--spec/unit/parser/ast/hostclass_spec.rb73
-rwxr-xr-xspec/unit/parser/ast/ifstatement_spec.rb2
-rw-r--r--spec/unit/parser/ast/in_operator_spec.rb2
-rwxr-xr-xspec/unit/parser/ast/leaf_spec.rb2
-rwxr-xr-xspec/unit/parser/ast/match_operator_spec.rb2
-rwxr-xr-xspec/unit/parser/ast/minus_spec.rb2
-rw-r--r--spec/unit/parser/ast/node_spec.rb31
-rwxr-xr-xspec/unit/parser/ast/nop_spec.rb2
-rwxr-xr-xspec/unit/parser/ast/not_spec.rb2
-rw-r--r--spec/unit/parser/ast/relationship_spec.rb2
-rwxr-xr-xspec/unit/parser/ast/resource_defaults_spec.rb2
-rwxr-xr-xspec/unit/parser/ast/resource_override_spec.rb2
-rwxr-xr-xspec/unit/parser/ast/resource_reference_spec.rb2
-rwxr-xr-xspec/unit/parser/ast/resource_spec.rb34
-rwxr-xr-xspec/unit/parser/ast/selector_spec.rb2
-rwxr-xr-xspec/unit/parser/ast/vardef_spec.rb2
-rw-r--r--spec/unit/parser/ast_spec.rb2
-rwxr-xr-xspec/unit/parser/collector_spec.rb2
-rwxr-xr-xspec/unit/parser/compiler_spec.rb26
-rw-r--r--spec/unit/parser/files_spec.rb2
-rwxr-xr-xspec/unit/parser/functions/defined_spec.rb5
-rwxr-xr-xspec/unit/parser/functions/extlookup_spec.rb7
-rwxr-xr-x[-rw-r--r--]spec/unit/parser/functions/fqdn_rand_spec.rb5
-rwxr-xr-xspec/unit/parser/functions/generate_spec.rb5
-rwxr-xr-x[-rw-r--r--]spec/unit/parser/functions/include_spec.rb5
-rwxr-xr-xspec/unit/parser/functions/inline_template_spec.rb7
-rwxr-xr-xspec/unit/parser/functions/realize_spec.rb5
-rwxr-xr-xspec/unit/parser/functions/regsubst_spec.rb5
-rwxr-xr-xspec/unit/parser/functions/require_spec.rb5
-rwxr-xr-xspec/unit/parser/functions/shellquote_spec.rb5
-rwxr-xr-xspec/unit/parser/functions/split_spec.rb5
-rwxr-xr-xspec/unit/parser/functions/sprintf_spec.rb5
-rwxr-xr-xspec/unit/parser/functions/tag_spec.rb5
-rwxr-xr-xspec/unit/parser/functions/template_spec.rb7
-rwxr-xr-xspec/unit/parser/functions/versioncmp_spec.rb5
-rw-r--r--spec/unit/parser/functions_spec.rb2
-rwxr-xr-xspec/unit/parser/lexer_spec.rb19
-rwxr-xr-xspec/unit/parser/parser_spec.rb158
-rw-r--r--spec/unit/parser/relationship_spec.rb2
-rwxr-xr-xspec/unit/parser/resource_spec.rb2
-rwxr-xr-xspec/unit/parser/scope_spec.rb5
-rwxr-xr-xspec/unit/parser/templatewrapper_spec.rb2
-rw-r--r--spec/unit/parser/type_loader_spec.rb195
53 files changed, 482 insertions, 295 deletions
diff --git a/spec/unit/parser/ast/arithmetic_operator_spec.rb b/spec/unit/parser/ast/arithmetic_operator_spec.rb
index 093cf94f1..381c5c629 100755
--- a/spec/unit/parser/ast/arithmetic_operator_spec.rb
+++ b/spec/unit/parser/ast/arithmetic_operator_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Puppet::Parser::AST::ArithmeticOperator do
diff --git a/spec/unit/parser/ast/astarray_spec.rb b/spec/unit/parser/ast/astarray_spec.rb
index f79d6c533..01082b3f0 100755
--- a/spec/unit/parser/ast/astarray_spec.rb
+++ b/spec/unit/parser/ast/astarray_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Puppet::Parser::AST::ASTArray do
before :each do
@@ -23,43 +23,26 @@ describe Puppet::Parser::AST::ASTArray do
operator.evaluate(@scope)
end
- it "should evaluate childrens of type ASTArray" do
- item1 = stub "item1", :is_a? => true
- item2 = stub "item2"
- item2.stubs(:is_a?).with(Puppet::Parser::AST).returns(true)
- item2.stubs(:instance_of?).with(Puppet::Parser::AST::ASTArray).returns(true)
- item2.stubs(:each).yields(item1)
-
- item1.expects(:safeevaluate).with(@scope).returns(123)
-
- operator = Puppet::Parser::AST::ASTArray.new :children => [item2]
- operator.evaluate(@scope).should == [123]
- end
-
- it "should flatten children coming from children ASTArray" do
- item1 = stub "item1", :is_a? => true
- item2 = stub "item2"
- item2.stubs(:is_a?).with(Puppet::Parser::AST).returns(true)
- item2.stubs(:instance_of?).with(Puppet::Parser::AST::ASTArray).returns(true)
- item2.stubs(:each).yields([item1])
-
- item1.expects(:safeevaluate).with(@scope).returns(123)
-
- operator = Puppet::Parser::AST::ASTArray.new :children => [item2]
- operator.evaluate(@scope).should == [123]
+ it "should not flatten children coming from children ASTArray" do
+ item = Puppet::Parser::AST::String.new :value => 'foo'
+ inner_array = Puppet::Parser::AST::ASTArray.new :children => [item, item]
+ operator = Puppet::Parser::AST::ASTArray.new :children => [inner_array, inner_array]
+ operator.evaluate(@scope).should == [['foo', 'foo'], ['foo', 'foo']]
end
it "should not flatten the results of children evaluation" do
- item1 = stub "item1", :is_a? => true
- item2 = stub "item2"
- item2.stubs(:is_a?).with(Puppet::Parser::AST).returns(true)
- item2.stubs(:instance_of?).with(Puppet::Parser::AST::ASTArray).returns(true)
- item2.stubs(:each).yields([item1])
-
- item1.expects(:safeevaluate).with(@scope).returns([123])
+ item = Puppet::Parser::AST::String.new :value => 'foo'
+ item.stubs(:evaluate).returns(['foo'])
+ operator = Puppet::Parser::AST::ASTArray.new :children => [item, item]
+ operator.evaluate(@scope).should == [['foo'], ['foo']]
+ end
- operator = Puppet::Parser::AST::ASTArray.new :children => [item2]
- operator.evaluate(@scope).should == [[123]]
+ it "should discard nil results from children evaluation" do
+ item1 = Puppet::Parser::AST::String.new :value => 'foo'
+ item2 = Puppet::Parser::AST::String.new :value => 'foo'
+ item2.stubs(:evaluate).returns(nil)
+ operator = Puppet::Parser::AST::ASTArray.new :children => [item1, item2]
+ operator.evaluate(@scope).should == ['foo']
end
it "should return a valid string with to_s" do
diff --git a/spec/unit/parser/ast/asthash_spec.rb b/spec/unit/parser/ast/asthash_spec.rb
index c70553c56..83f604545 100644
--- a/spec/unit/parser/ast/asthash_spec.rb
+++ b/spec/unit/parser/ast/asthash_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Puppet::Parser::AST::ASTHash do
before :each do
diff --git a/spec/unit/parser/ast/boolean_operator_spec.rb b/spec/unit/parser/ast/boolean_operator_spec.rb
index 10e987e31..529946694 100755
--- a/spec/unit/parser/ast/boolean_operator_spec.rb
+++ b/spec/unit/parser/ast/boolean_operator_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Puppet::Parser::AST::BooleanOperator do
diff --git a/spec/unit/parser/ast/casestatement_spec.rb b/spec/unit/parser/ast/casestatement_spec.rb
index 4d79e54cb..bce3ad801 100755
--- a/spec/unit/parser/ast/casestatement_spec.rb
+++ b/spec/unit/parser/ast/casestatement_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Puppet::Parser::AST::CaseStatement do
before :each do
@@ -13,11 +13,14 @@ describe Puppet::Parser::AST::CaseStatement do
@test = stub 'test'
@test.stubs(:safeevaluate).with(@scope).returns("value")
- @option1 = stub 'option1', :eachopt => nil, :default? => false
- @option2 = stub 'option2', :eachopt => nil, :default? => false
+ @option1 = Puppet::Parser::AST::CaseOpt.new({})
+ @option1.stubs(:eachopt)
+ @option1.stubs(:default?).returns false
+ @option2 = Puppet::Parser::AST::CaseOpt.new({})
+ @option2.stubs(:eachopt)
+ @option2.stubs(:default?).returns false
- @options = stub 'options'
- @options.stubs(:each).multiple_yields(@option1, @option2)
+ @options = Puppet::Parser::AST::ASTArray.new(:children => [@option1, @option2])
@casestmt = Puppet::Parser::AST::CaseStatement.new :test => @test, :options => @options
end
@@ -29,8 +32,6 @@ describe Puppet::Parser::AST::CaseStatement do
end
it "should scan each option" do
- @options.expects(:each).multiple_yields(@option1, @option2)
-
@casestmt.evaluate(@scope)
end
@@ -137,12 +138,15 @@ describe Puppet::Parser::AST::CaseStatement do
options = tests.collect do |result, values|
values = values.collect { |v| AST::Leaf.new :value => v }
- AST::CaseOpt.new(
- :value => AST::ASTArray.new(:children => values),
-
- :statements => AST::Leaf.new(:value => result))
+ AST::CaseOpt.new(
+ :value => AST::ASTArray.new(:children => values),
+ :statements => AST::Leaf.new(:value => result)
+ )
end
- options << AST::CaseOpt.new(:value => AST::Default.new(:value => "default"), :statements => AST::Leaf.new(:value => "default"))
+ options << AST::CaseOpt.new(
+ :value => AST::Default.new(:value => "default"),
+ :statements => AST::Leaf.new(:value => "default")
+ )
ast = nil
param = AST::Variable.new(:value => "testparam")
diff --git a/spec/unit/parser/ast/collection_spec.rb b/spec/unit/parser/ast/collection_spec.rb
index cc33075b7..99abc998d 100755
--- a/spec/unit/parser/ast/collection_spec.rb
+++ b/spec/unit/parser/ast/collection_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Puppet::Parser::AST::Collection do
before :each do
diff --git a/spec/unit/parser/ast/collexpr_spec.rb b/spec/unit/parser/ast/collexpr_spec.rb
index 01276dfb3..04ce69cd3 100755
--- a/spec/unit/parser/ast/collexpr_spec.rb
+++ b/spec/unit/parser/ast/collexpr_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Puppet::Parser::AST::CollExpr do
diff --git a/spec/unit/parser/ast/comparison_operator_spec.rb b/spec/unit/parser/ast/comparison_operator_spec.rb
index 931f936df..03c9069cb 100755
--- a/spec/unit/parser/ast/comparison_operator_spec.rb
+++ b/spec/unit/parser/ast/comparison_operator_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Puppet::Parser::AST::ComparisonOperator do
before :each do
diff --git a/spec/unit/parser/ast/definition_spec.rb b/spec/unit/parser/ast/definition_spec.rb
new file mode 100644
index 000000000..e7f55d258
--- /dev/null
+++ b/spec/unit/parser/ast/definition_spec.rb
@@ -0,0 +1,22 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
+
+describe Puppet::Parser::AST::Definition do
+ it "should make its context available through an accessor" do
+ definition = Puppet::Parser::AST::Definition.new('foo', :line => 5)
+ definition.context.should == {:line => 5}
+ end
+
+ describe "when instantiated" do
+ it "should create a definition with the proper type, name, context, and module name" do
+ definition = Puppet::Parser::AST::Definition.new('foo', :line => 5)
+ instantiated_definitions = definition.instantiate('modname')
+ instantiated_definitions.length.should == 1
+ instantiated_definitions[0].type.should == :definition
+ instantiated_definitions[0].name.should == 'foo'
+ instantiated_definitions[0].line.should == 5
+ instantiated_definitions[0].module_name.should == 'modname'
+ end
+ end
+end
diff --git a/spec/unit/parser/ast/function_spec.rb b/spec/unit/parser/ast/function_spec.rb
index 38e344157..cd4b0f94e 100644
--- a/spec/unit/parser/ast/function_spec.rb
+++ b/spec/unit/parser/ast/function_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Puppet::Parser::AST::Function do
before :each do
diff --git a/spec/unit/parser/ast/hostclass_spec.rb b/spec/unit/parser/ast/hostclass_spec.rb
new file mode 100644
index 000000000..390490788
--- /dev/null
+++ b/spec/unit/parser/ast/hostclass_spec.rb
@@ -0,0 +1,73 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
+
+describe Puppet::Parser::AST::Hostclass do
+ def ast
+ Puppet::Parser::AST
+ end
+
+ def newarray(*elems)
+ ast::ASTArray.new({}).push(*elems)
+ end
+
+ it "should make its name and context available through accessors" do
+ hostclass = ast::Hostclass.new('foo', :line => 5)
+ hostclass.name.should == 'foo'
+ hostclass.context.should == {:line => 5}
+ end
+
+ it "should make its code available through an accessor" do
+ code = newarray
+ hostclass = ast::Hostclass.new('foo', :code => code)
+ hostclass.code.should be_equal(code)
+ end
+
+ describe "when instantiated" do
+ it "should create a class with the proper type, code, name, context, and module name" do
+ code = newarray
+ hostclass = ast::Hostclass.new('foo', :code => code, :line => 5)
+ instantiated_class = hostclass.instantiate('modname')[0]
+ instantiated_class.type.should == :hostclass
+ instantiated_class.name.should == 'foo'
+ instantiated_class.code.should be_equal(code)
+ instantiated_class.line.should == 5
+ instantiated_class.module_name.should == 'modname'
+ end
+
+ it "should instantiate all nested classes, defines, and nodes with the same module name." do
+ nested_objects = newarray(ast::Hostclass.new('foo::child1'),
+ ast::Definition.new('foo::child2'),
+ ast::Definition.new('child3'))
+ hostclass = ast::Hostclass.new('foo', :code => nested_objects)
+ instantiated_classes = hostclass.instantiate('modname')
+ instantiated_classes.length.should == 4
+ instantiated_classes[0].name.should == 'foo'
+ instantiated_classes[1].name.should == 'foo::child1'
+ instantiated_classes[2].name.should == 'foo::child2'
+ instantiated_classes[3].name.should == 'child3'
+ instantiated_classes.each { |cls| cls.module_name.should == 'modname' }
+ end
+
+ it "should handle a nested class that contains its own nested classes." do
+ foo_bar_baz = ast::Hostclass.new('foo::bar::baz')
+ foo_bar = ast::Hostclass.new('foo::bar', :code => newarray(foo_bar_baz))
+ foo = ast::Hostclass.new('foo', :code => newarray(foo_bar))
+ instantiated_classes = foo.instantiate('')
+ instantiated_classes.length.should == 3
+ instantiated_classes[0].name.should == 'foo'
+ instantiated_classes[1].name.should == 'foo::bar'
+ instantiated_classes[2].name.should == 'foo::bar::baz'
+ end
+
+ it "should skip nested elements that are not classes, definitions, or nodes." do
+ func = ast::Function.new(:name => 'biz', :arguments => newarray(ast::Name.new(:value => 'baz')))
+ foo = ast::Hostclass.new('foo', :code => newarray(func))
+ instantiated_classes = foo.instantiate('')
+ instantiated_classes.length.should == 1
+ instantiated_classes[0].should be_a(Puppet::Resource::Type)
+ instantiated_classes[0].name.should == 'foo'
+ end
+ end
+end
+
diff --git a/spec/unit/parser/ast/ifstatement_spec.rb b/spec/unit/parser/ast/ifstatement_spec.rb
index 2a9e1e37b..6a2fed22c 100755
--- a/spec/unit/parser/ast/ifstatement_spec.rb
+++ b/spec/unit/parser/ast/ifstatement_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Puppet::Parser::AST::IfStatement do
before :each do
diff --git a/spec/unit/parser/ast/in_operator_spec.rb b/spec/unit/parser/ast/in_operator_spec.rb
index aebe442ab..08c01582e 100644
--- a/spec/unit/parser/ast/in_operator_spec.rb
+++ b/spec/unit/parser/ast/in_operator_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require 'puppet/parser/ast/in_operator'
diff --git a/spec/unit/parser/ast/leaf_spec.rb b/spec/unit/parser/ast/leaf_spec.rb
index a19c24115..2119a27a8 100755
--- a/spec/unit/parser/ast/leaf_spec.rb
+++ b/spec/unit/parser/ast/leaf_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Puppet::Parser::AST::Leaf do
before :each do
diff --git a/spec/unit/parser/ast/match_operator_spec.rb b/spec/unit/parser/ast/match_operator_spec.rb
index d6e998751..f2a68b676 100755
--- a/spec/unit/parser/ast/match_operator_spec.rb
+++ b/spec/unit/parser/ast/match_operator_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Puppet::Parser::AST::MatchOperator do
before :each do
diff --git a/spec/unit/parser/ast/minus_spec.rb b/spec/unit/parser/ast/minus_spec.rb
index 108c8812e..339087e80 100755
--- a/spec/unit/parser/ast/minus_spec.rb
+++ b/spec/unit/parser/ast/minus_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Puppet::Parser::AST::Minus do
before :each do
diff --git a/spec/unit/parser/ast/node_spec.rb b/spec/unit/parser/ast/node_spec.rb
new file mode 100644
index 000000000..c4e20ca67
--- /dev/null
+++ b/spec/unit/parser/ast/node_spec.rb
@@ -0,0 +1,31 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
+
+describe Puppet::Parser::AST::Node do
+ describe "when instantiated" do
+ it "should make its names and context available through accessors" do
+ node = Puppet::Parser::AST::Node.new(['foo', 'bar'], :line => 5)
+ node.names.should == ['foo', 'bar']
+ node.context.should == {:line => 5}
+ end
+
+ it "should create a node with the proper type, name, context, and module name" do
+ node = Puppet::Parser::AST::Node.new(['foo'], :line => 5)
+ instantiated_nodes = node.instantiate('modname')
+ instantiated_nodes.length.should == 1
+ instantiated_nodes[0].type.should == :node
+ instantiated_nodes[0].name.should == 'foo'
+ instantiated_nodes[0].line.should == 5
+ instantiated_nodes[0].module_name.should == 'modname'
+ end
+
+ it "should handle multiple names" do
+ node = Puppet::Parser::AST::Node.new(['foo', 'bar'])
+ instantiated_nodes = node.instantiate('modname')
+ instantiated_nodes.length.should == 2
+ instantiated_nodes[0].name.should == 'foo'
+ instantiated_nodes[1].name.should == 'bar'
+ end
+ end
+end
diff --git a/spec/unit/parser/ast/nop_spec.rb b/spec/unit/parser/ast/nop_spec.rb
index 3e493197a..3fa2fc0ee 100755
--- a/spec/unit/parser/ast/nop_spec.rb
+++ b/spec/unit/parser/ast/nop_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Puppet::Parser::AST::Nop do
diff --git a/spec/unit/parser/ast/not_spec.rb b/spec/unit/parser/ast/not_spec.rb
index 2ef6e0689..31a425132 100755
--- a/spec/unit/parser/ast/not_spec.rb
+++ b/spec/unit/parser/ast/not_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Puppet::Parser::AST::Not do
before :each do
diff --git a/spec/unit/parser/ast/relationship_spec.rb b/spec/unit/parser/ast/relationship_spec.rb
index 2a0f658df..d8bc3a535 100644
--- a/spec/unit/parser/ast/relationship_spec.rb
+++ b/spec/unit/parser/ast/relationship_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Puppet::Parser::AST::Relationship do
before do
diff --git a/spec/unit/parser/ast/resource_defaults_spec.rb b/spec/unit/parser/ast/resource_defaults_spec.rb
index 7843fd9a9..36eb8df5f 100755
--- a/spec/unit/parser/ast/resource_defaults_spec.rb
+++ b/spec/unit/parser/ast/resource_defaults_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Puppet::Parser::AST::ResourceDefaults do
diff --git a/spec/unit/parser/ast/resource_override_spec.rb b/spec/unit/parser/ast/resource_override_spec.rb
index 637ab41fc..7ca3a7e8c 100755
--- a/spec/unit/parser/ast/resource_override_spec.rb
+++ b/spec/unit/parser/ast/resource_override_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Puppet::Parser::AST::ResourceOverride do
diff --git a/spec/unit/parser/ast/resource_reference_spec.rb b/spec/unit/parser/ast/resource_reference_spec.rb
index 93419d963..492c25490 100755
--- a/spec/unit/parser/ast/resource_reference_spec.rb
+++ b/spec/unit/parser/ast/resource_reference_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Puppet::Parser::AST::ResourceReference do
diff --git a/spec/unit/parser/ast/resource_spec.rb b/spec/unit/parser/ast/resource_spec.rb
index 721c31a8d..b00fee587 100755
--- a/spec/unit/parser/ast/resource_spec.rb
+++ b/spec/unit/parser/ast/resource_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Puppet::Parser::AST::Resource do
ast = Puppet::Parser::AST
@@ -11,14 +11,15 @@ 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", :parameters => ast::ASTArray.new(:children => []) )
+ @instance = ast::ResourceInstance.new(:title => @title, :parameters => ast::ASTArray.new(:children => []))
+ @resource = ast::Resource.new(:type => "file", :instances => ast::ASTArray.new(:children => [@instance]))
@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(:parameters).returns [param]
+ @instance.stubs(:parameters).returns [param]
@resource.evaluate(@scope)
end
@@ -35,7 +36,7 @@ describe Puppet::Parser::AST::Resource do
array = Puppet::Parser::AST::ASTArray.new(:children => titles)
- @resource.title = array
+ @instance.title = array
result = @resource.evaluate(@scope).collect { |r| r.title }
result.should be_include("one")
result.should be_include("two")
@@ -49,12 +50,19 @@ describe Puppet::Parser::AST::Resource do
array = Puppet::Parser::AST::ASTArray.new(:children => titles)
- @resource.title = array
+ @instance.title = array
result = @resource.evaluate(@scope).collect { |r| r.title }
result.should be_include("one")
result.should be_include("two")
end
+ it "should implicitly iterate over instances" do
+ new_title = Puppet::Parser::AST::String.new(:value => "other_title")
+ new_instance = ast::ResourceInstance.new(:title => new_title, :parameters => ast::ASTArray.new(:children => []))
+ @resource.instances.push(new_instance)
+ @resource.evaluate(@scope).collect { |r| r.title }.should == ["mytitle", "other_title"]
+ end
+
it "should handover resources to the compiler" do
titles = []
%w{one two}.each do |title|
@@ -63,7 +71,7 @@ describe Puppet::Parser::AST::Resource do
array = Puppet::Parser::AST::ASTArray.new(:children => titles)
- @resource.title = array
+ @instance.title = array
result = @resource.evaluate(@scope)
result.each do |res|
@@ -91,16 +99,19 @@ describe Puppet::Parser::AST::Resource do
before do
@scope = Puppet::Parser::Scope.new :compiler => Puppet::Parser::Compiler.new(Puppet::Node.new("mynode"))
@parser = Puppet::Parser::Parser.new(Puppet::Node::Environment.new)
- @parser.newdefine "one"
- @parser.newdefine "one::two"
- @parser.newdefine "three"
+ ["one", "one::two", "three"].each do |name|
+ @parser.environment.known_resource_types.add(Puppet::Resource::Type.new(:definition, name, {}))
+ end
@twoscope = @scope.newscope(:namespace => "one")
@twoscope.resource = @scope.resource
end
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"), :parameters => params)
+ instance = Puppet::Parser::AST::ResourceInstance.new(
+ :title => Puppet::Parser::AST::String.new(:value => "myresource"), :parameters => params)
+ Puppet::Parser::AST::Resource.new(:type => type,
+ :instances => Puppet::Parser::AST::ASTArray.new(:children => [instance]))
end
it "should be able to generate resources with fully qualified type information" do
@@ -141,7 +152,8 @@ 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 => "Class", :parameters => ast::ASTArray.new(:children => []) )
+ @instance = ast::ResourceInstance.new(:title => @title, :parameters => ast::ASTArray.new(:children => []))
+ @resource = ast::Resource.new(:type => "Class", :instances => ast::ASTArray.new(:children => [@instance]))
@resource.stubs(:qualified_type).returns("Resource")
@type = Puppet::Resource::Type.new(:hostclass, "classname")
@compiler.known_resource_types.add(@type)
diff --git a/spec/unit/parser/ast/selector_spec.rb b/spec/unit/parser/ast/selector_spec.rb
index 42898475f..4c13aa7ba 100755
--- a/spec/unit/parser/ast/selector_spec.rb
+++ b/spec/unit/parser/ast/selector_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Puppet::Parser::AST::Selector do
before :each do
diff --git a/spec/unit/parser/ast/vardef_spec.rb b/spec/unit/parser/ast/vardef_spec.rb
index a90010f5a..9c8b77905 100755
--- a/spec/unit/parser/ast/vardef_spec.rb
+++ b/spec/unit/parser/ast/vardef_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe Puppet::Parser::AST::VarDef do
before :each do
diff --git a/spec/unit/parser/ast_spec.rb b/spec/unit/parser/ast_spec.rb
index 29dce2b9c..cdfb51869 100644
--- a/spec/unit/parser/ast_spec.rb
+++ b/spec/unit/parser/ast_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'puppet/parser/ast'
diff --git a/spec/unit/parser/collector_spec.rb b/spec/unit/parser/collector_spec.rb
index 4cab26c44..100a04daf 100755
--- a/spec/unit/parser/collector_spec.rb
+++ b/spec/unit/parser/collector_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'puppet/rails'
require 'puppet/parser/collector'
diff --git a/spec/unit/parser/compiler_spec.rb b/spec/unit/parser/compiler_spec.rb
index 687f2ecb9..e4b18e14b 100755
--- a/spec/unit/parser/compiler_spec.rb
+++ b/spec/unit/parser/compiler_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
class CompilerTestResource
attr_accessor :builtin, :virtual, :evaluated, :type, :title
@@ -576,18 +576,16 @@ describe Puppet::Parser::Compiler do
proc { @compiler.evaluate_classes(%w{one two}, scope) }.should raise_error(Puppet::DevError)
end
- it "should tag the catalog with the name of each not-found class" do
- @compiler.catalog.expects(:tag).with("notfound")
+ it "should raise an error if a class is not found" do
@scope.expects(:find_hostclass).with("notfound").returns(nil)
- @compiler.evaluate_classes(%w{notfound}, @scope)
+ lambda{ @compiler.evaluate_classes(%w{notfound}, @scope) }.should raise_error(Puppet::Error, /Could not find class/)
end
- # I wish it would fail
- it "should log when it can't find class" do
+
+ it "should raise an error when it can't find class" do
klasses = {'foo'=>nil}
@node.classes = klasses
@compiler.topscope.stubs(:find_hostclass).with('foo').returns(nil)
- Puppet.expects(:info).with('Could not find class foo for testnode')
- @compiler.compile
+ lambda{ @compiler.compile }.should raise_error(Puppet::Error, /Could not find class foo for testnode/)
end
end
@@ -714,18 +712,6 @@ describe Puppet::Parser::Compiler do
Puppet::Parser::Resource.expects(:new).never
@compiler.evaluate_classes(%w{MyClass}, @scope, false)
end
-
- it "should return the list of found classes" do
- @compiler.catalog.stubs(:tag)
-
- @compiler.stubs(:add_resource)
- @scope.stubs(:find_hostclass).with("notfound").returns(nil)
- @scope.stubs(:class_scope).with(@class)
-
- Puppet::Parser::Resource.stubs(:new).returns(@resource)
- @class.stubs :ensure_in_catalog
- @compiler.evaluate_classes(%w{myclass notfound}, @scope).should == %w{myclass}
- end
end
describe "when evaluating AST nodes with no AST nodes present" do
diff --git a/spec/unit/parser/files_spec.rb b/spec/unit/parser/files_spec.rb
index 3eb0db07e..525c83697 100644
--- a/spec/unit/parser/files_spec.rb
+++ b/spec/unit/parser/files_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'puppet/parser/files'
diff --git a/spec/unit/parser/functions/defined_spec.rb b/spec/unit/parser/functions/defined_spec.rb
index cf3f66e17..0113c3233 100755
--- a/spec/unit/parser/functions/defined_spec.rb
+++ b/spec/unit/parser/functions/defined_spec.rb
@@ -1,8 +1,11 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe "the 'defined' function" do
+ before :all do
+ Puppet::Parser::Functions.autoloader.loadall
+ end
before :each do
Puppet::Node::Environment.stubs(:current).returns(nil)
diff --git a/spec/unit/parser/functions/extlookup_spec.rb b/spec/unit/parser/functions/extlookup_spec.rb
index a3dcaa742..46cd3cc27 100755
--- a/spec/unit/parser/functions/extlookup_spec.rb
+++ b/spec/unit/parser/functions/extlookup_spec.rb
@@ -1,15 +1,16 @@
#! /usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require 'tempfile'
describe "the extlookup function" do
+ before :all do
+ Puppet::Parser::Functions.autoloader.loadall
+ end
before :each do
@scope = Puppet::Parser::Scope.new
-
@scope.stubs(:environment).returns(Puppet::Node::Environment.new('production'))
- Puppet::Parser::Functions.function("extlookup")
end
it "should exist" do
diff --git a/spec/unit/parser/functions/fqdn_rand_spec.rb b/spec/unit/parser/functions/fqdn_rand_spec.rb
index 81c12c6a7..be2e6fa76 100644..100755
--- a/spec/unit/parser/functions/fqdn_rand_spec.rb
+++ b/spec/unit/parser/functions/fqdn_rand_spec.rb
@@ -1,8 +1,11 @@
#! /usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe "the fqdn_rand function" do
+ before :all do
+ Puppet::Parser::Functions.autoloader.loadall
+ end
before :each do
@scope = Puppet::Parser::Scope.new
diff --git a/spec/unit/parser/functions/generate_spec.rb b/spec/unit/parser/functions/generate_spec.rb
index 27aabe261..d25015b56 100755
--- a/spec/unit/parser/functions/generate_spec.rb
+++ b/spec/unit/parser/functions/generate_spec.rb
@@ -1,8 +1,11 @@
#! /usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe "the generate function" do
+ before :all do
+ Puppet::Parser::Functions.autoloader.loadall
+ end
before :each do
@scope = Puppet::Parser::Scope.new
diff --git a/spec/unit/parser/functions/include_spec.rb b/spec/unit/parser/functions/include_spec.rb
index 4f609b055..cfaadfbb6 100644..100755
--- a/spec/unit/parser/functions/include_spec.rb
+++ b/spec/unit/parser/functions/include_spec.rb
@@ -1,8 +1,11 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe "the 'include' function" do
+ before :all do
+ Puppet::Parser::Functions.autoloader.loadall
+ end
before :each do
Puppet::Node::Environment.stubs(:current).returns(nil)
diff --git a/spec/unit/parser/functions/inline_template_spec.rb b/spec/unit/parser/functions/inline_template_spec.rb
index 62f389e5d..712c68c69 100755
--- a/spec/unit/parser/functions/inline_template_spec.rb
+++ b/spec/unit/parser/functions/inline_template_spec.rb
@@ -1,8 +1,11 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe "the inline_template function" do
+ before :all do
+ Puppet::Parser::Functions.autoloader.loadall
+ end
before :each do
@scope = Puppet::Parser::Scope.new
@@ -56,4 +59,4 @@ describe "the inline_template function" do
lambda { @scope.function_inline_template("1") }.should raise_error(Puppet::ParseError)
end
-end \ No newline at end of file
+end
diff --git a/spec/unit/parser/functions/realize_spec.rb b/spec/unit/parser/functions/realize_spec.rb
index 82f4fa251..3106c42b6 100755
--- a/spec/unit/parser/functions/realize_spec.rb
+++ b/spec/unit/parser/functions/realize_spec.rb
@@ -1,8 +1,11 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe "the realize function" do
+ before :all do
+ Puppet::Parser::Functions.autoloader.loadall
+ end
before :each do
@collector = stub_everything 'collector'
diff --git a/spec/unit/parser/functions/regsubst_spec.rb b/spec/unit/parser/functions/regsubst_spec.rb
index 47126dd7a..1fb8e410c 100755
--- a/spec/unit/parser/functions/regsubst_spec.rb
+++ b/spec/unit/parser/functions/regsubst_spec.rb
@@ -1,8 +1,11 @@
#! /usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe "the regsubst function" do
+ before :all do
+ Puppet::Parser::Functions.autoloader.loadall
+ end
before :each do
@scope = Puppet::Parser::Scope.new
diff --git a/spec/unit/parser/functions/require_spec.rb b/spec/unit/parser/functions/require_spec.rb
index 49c4bbf74..edcbc4ae6 100755
--- a/spec/unit/parser/functions/require_spec.rb
+++ b/spec/unit/parser/functions/require_spec.rb
@@ -1,8 +1,11 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe "the require function" do
+ before :all do
+ Puppet::Parser::Functions.autoloader.loadall
+ end
before :each do
@catalog = stub 'catalog'
diff --git a/spec/unit/parser/functions/shellquote_spec.rb b/spec/unit/parser/functions/shellquote_spec.rb
index 46b9f8d10..55302b97b 100755
--- a/spec/unit/parser/functions/shellquote_spec.rb
+++ b/spec/unit/parser/functions/shellquote_spec.rb
@@ -1,8 +1,11 @@
#! /usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe "the shellquote function" do
+ before :all do
+ Puppet::Parser::Functions.autoloader.loadall
+ end
before :each do
@scope = Puppet::Parser::Scope.new
diff --git a/spec/unit/parser/functions/split_spec.rb b/spec/unit/parser/functions/split_spec.rb
index a1c83bb0f..b892a5c2a 100755
--- a/spec/unit/parser/functions/split_spec.rb
+++ b/spec/unit/parser/functions/split_spec.rb
@@ -1,8 +1,11 @@
#! /usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe "the split function" do
+ before :all do
+ Puppet::Parser::Functions.autoloader.loadall
+ end
before :each do
@scope = Puppet::Parser::Scope.new
diff --git a/spec/unit/parser/functions/sprintf_spec.rb b/spec/unit/parser/functions/sprintf_spec.rb
index 01545a879..69fbb5e97 100755
--- a/spec/unit/parser/functions/sprintf_spec.rb
+++ b/spec/unit/parser/functions/sprintf_spec.rb
@@ -1,8 +1,11 @@
#! /usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe "the sprintf function" do
+ before :all do
+ Puppet::Parser::Functions.autoloader.loadall
+ end
before :each do
@scope = Puppet::Parser::Scope.new
diff --git a/spec/unit/parser/functions/tag_spec.rb b/spec/unit/parser/functions/tag_spec.rb
index dac134134..b6bb45252 100755
--- a/spec/unit/parser/functions/tag_spec.rb
+++ b/spec/unit/parser/functions/tag_spec.rb
@@ -1,8 +1,11 @@
#! /usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe "the 'tag' function" do
+ before :all do
+ Puppet::Parser::Functions.autoloader.loadall
+ end
before :each do
@scope = Puppet::Parser::Scope.new
diff --git a/spec/unit/parser/functions/template_spec.rb b/spec/unit/parser/functions/template_spec.rb
index 096b0598e..7eaf3554d 100755
--- a/spec/unit/parser/functions/template_spec.rb
+++ b/spec/unit/parser/functions/template_spec.rb
@@ -1,8 +1,11 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe "the template function" do
+ before :all do
+ Puppet::Parser::Functions.autoloader.loadall
+ end
before :each do
@scope = Puppet::Parser::Scope.new
@@ -59,4 +62,4 @@ describe "the template function" do
lambda { @scope.function_template("1") }.should raise_error(Puppet::ParseError)
end
-end \ No newline at end of file
+end
diff --git a/spec/unit/parser/functions/versioncmp_spec.rb b/spec/unit/parser/functions/versioncmp_spec.rb
index 380c6307a..ddc79cd85 100755
--- a/spec/unit/parser/functions/versioncmp_spec.rb
+++ b/spec/unit/parser/functions/versioncmp_spec.rb
@@ -1,8 +1,11 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe "the versioncmp function" do
+ before :all do
+ Puppet::Parser::Functions.autoloader.loadall
+ end
before :each do
@scope = Puppet::Parser::Scope.new
diff --git a/spec/unit/parser/functions_spec.rb b/spec/unit/parser/functions_spec.rb
index 18aee4b65..51e52faee 100644
--- a/spec/unit/parser/functions_spec.rb
+++ b/spec/unit/parser/functions_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe Puppet::Parser::Functions do
diff --git a/spec/unit/parser/lexer_spec.rb b/spec/unit/parser/lexer_spec.rb
index 4ef242cf5..bc9e22e48 100755
--- a/spec/unit/parser/lexer_spec.rb
+++ b/spec/unit/parser/lexer_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'puppet/parser/lexer'
@@ -667,11 +667,8 @@ describe "Puppet::Parser::Lexer in the old tests" do
end
end
-require File.dirname(__FILE__) + '/../../../test/lib/puppettest'
-require File.dirname(__FILE__) + '/../../../test/lib/puppettest/support/utils'
describe "Puppet::Parser::Lexer in the old tests when lexing example files" do
- extend PuppetTest::Support::Utils
- textfiles do |file|
+ my_fixtures('*.pp') do |file|
it "should correctly lex #{file}" do
lexer = Puppet::Parser::Lexer.new
lexer.file = file
@@ -679,3 +676,15 @@ describe "Puppet::Parser::Lexer in the old tests when lexing example files" do
end
end
end
+
+describe "when trying to lex an non-existent file" do
+ include PuppetSpec::Files
+
+ it "should return an empty list of tokens" do
+ lexer = Puppet::Parser::Lexer.new
+ lexer.file = nofile = tmpfile('lexer')
+ File.exists?(nofile).should == false
+
+ lexer.fullscan.should == [[false,false]]
+ end
+end
diff --git a/spec/unit/parser/parser_spec.rb b/spec/unit/parser/parser_spec.rb
index 2ed279fd9..01cdcb976 100755
--- a/spec/unit/parser/parser_spec.rb
+++ b/spec/unit/parser/parser_spec.rb
@@ -1,10 +1,10 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe Puppet::Parser do
- ast = Puppet::Parser::AST
+ Puppet::Parser::AST
before :each do
@known_resource_types = Puppet::Resource::TypeCollection.new("development")
@@ -64,14 +64,16 @@ describe Puppet::Parser do
lambda { @parser.parse("$var += ") }.should raise_error
end
- it "should call ast::VarDef with append=true" do
- ast::VarDef.expects(:new).with { |h| h[:append] == true }
- @parser.parse("$var += 2")
+ it "should create ast::VarDef with append=true" do
+ vardef = @parser.parse("$var += 2").code[0]
+ vardef.should be_a(Puppet::Parser::AST::VarDef)
+ vardef.append.should == true
end
it "should work with arrays too" do
- ast::VarDef.expects(:new).with { |h| h[:append] == true }
- @parser.parse("$var += ['test']")
+ vardef = @parser.parse("$var += ['test']").code[0]
+ vardef.should be_a(Puppet::Parser::AST::VarDef)
+ vardef.append.should == true
end
end
@@ -84,21 +86,21 @@ describe Puppet::Parser do
describe "when parsing 'if'" do
it "not, it should create the correct ast objects" do
- ast::Not.expects(:new).with { |h| h[:value].is_a?(ast::Boolean) }
+ Puppet::Parser::AST::Not.expects(:new).with { |h| h[:value].is_a?(Puppet::Parser::AST::Boolean) }
@parser.parse("if ! true { $var = 1 }")
end
it "boolean operation, it should create the correct ast objects" do
- ast::BooleanOperator.expects(:new).with {
- |h| h[:rval].is_a?(ast::Boolean) and h[:lval].is_a?(ast::Boolean) and h[:operator]=="or"
+ Puppet::Parser::AST::BooleanOperator.expects(:new).with {
+ |h| h[:rval].is_a?(Puppet::Parser::AST::Boolean) and h[:lval].is_a?(Puppet::Parser::AST::Boolean) and h[:operator]=="or"
}
@parser.parse("if true or true { $var = 1 }")
end
it "comparison operation, it should create the correct ast objects" do
- ast::ComparisonOperator.expects(:new).with {
- |h| h[:lval].is_a?(ast::Name) and h[:rval].is_a?(ast::Name) and h[:operator]=="<"
+ Puppet::Parser::AST::ComparisonOperator.expects(:new).with {
+ |h| h[:lval].is_a?(Puppet::Parser::AST::Name) and h[:rval].is_a?(Puppet::Parser::AST::Name) and h[:operator]=="<"
}
@parser.parse("if 1 < 2 { $var = 1 }")
@@ -109,13 +111,13 @@ describe Puppet::Parser do
describe "when parsing if complex expressions" do
it "should create a correct ast tree" do
aststub = stub_everything 'ast'
- ast::ComparisonOperator.expects(:new).with {
- |h| h[:rval].is_a?(ast::Name) and h[:lval].is_a?(ast::Name) and h[:operator]==">"
+ Puppet::Parser::AST::ComparisonOperator.expects(:new).with {
+ |h| h[:rval].is_a?(Puppet::Parser::AST::Name) and h[:lval].is_a?(Puppet::Parser::AST::Name) and h[:operator]==">"
}.returns(aststub)
- ast::ComparisonOperator.expects(:new).with {
- |h| h[:rval].is_a?(ast::Name) and h[:lval].is_a?(ast::Name) and h[:operator]=="=="
+ Puppet::Parser::AST::ComparisonOperator.expects(:new).with {
+ |h| h[:rval].is_a?(Puppet::Parser::AST::Name) and h[:lval].is_a?(Puppet::Parser::AST::Name) and h[:operator]=="=="
}.returns(aststub)
- ast::BooleanOperator.expects(:new).with {
+ Puppet::Parser::AST::BooleanOperator.expects(:new).with {
|h| h[:rval]==aststub and h[:lval]==aststub and h[:operator]=="and"
}
@parser.parse("if (1 > 2) and (1 == 2) { $var = 1 }")
@@ -138,9 +140,8 @@ describe Puppet::Parser do
end
it "should create an ast::ResourceReference" do
- ast::Resource.stubs(:new)
- ast::ResourceReference.expects(:new).with { |arg|
- arg[:line]==1 and arg[:type]=="File" and arg[:title].is_a?(ast::ASTArray)
+ Puppet::Parser::AST::ResourceReference.expects(:new).with { |arg|
+ arg[:line]==1 and arg[:type]=="File" and arg[:title].is_a?(Puppet::Parser::AST::ASTArray)
}
@parser.parse('exec { test: command => File["a","b"] }')
end
@@ -157,10 +158,14 @@ describe Puppet::Parser do
end
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[:parameters].is_a?(ast::ResourceParam)
- }
- @parser.parse('Resource["title1","title2"] { param => value }')
+ #Puppet::Parser::AST::ResourceOverride.expects(:new).with { |arg|
+ # arg[:line]==1 and arg[:object].is_a?(Puppet::Parser::AST::ResourceReference) and arg[:parameters].is_a?(Puppet::Parser::AST::ResourceParam)
+ #}
+ ro = @parser.parse('Resource["title1","title2"] { param => value }').code[0]
+ ro.should be_a(Puppet::Parser::AST::ResourceOverride)
+ ro.line.should == 1
+ ro.object.should be_a(Puppet::Parser::AST::ResourceReference)
+ ro.parameters[0].should be_a(Puppet::Parser::AST::ResourceParam)
end
end
@@ -180,17 +185,17 @@ describe Puppet::Parser do
end
it "should create a nop node for empty branch" do
- ast::Nop.expects(:new)
+ Puppet::Parser::AST::Nop.expects(:new)
@parser.parse("if true { }")
end
it "should create a nop node for empty else branch" do
- ast::Nop.expects(:new)
+ Puppet::Parser::AST::Nop.expects(:new)
@parser.parse("if true { notice('test') } else { }")
end
it "should build a chain of 'ifs' if there's an 'elsif'" do
- ast = @parser.parse(<<-PP)
+ lambda { @parser.parse(<<-PP) }.should_not raise_error
if true { notice('test') } elsif true {} else { }
PP
end
@@ -294,51 +299,6 @@ describe Puppet::Parser do
end
end
- describe "when creating a node" do
- before :each do
- @lexer = stub 'lexer'
- @lexer.stubs(:getcomment)
- @parser.stubs(:lexer).returns(@lexer)
- @node = stub_everything 'node'
- @parser.stubs(:ast_context).returns({})
- @parser.stubs(:node).returns(nil)
-
- @nodename = stub 'nodename', :is_a? => false, :value => "foo"
- @nodename.stubs(:is_a?).with(Puppet::Parser::AST::HostName).returns(true)
- end
-
- it "should return an array of nodes" do
- @parser.newnode(@nodename).should be_instance_of(Array)
- end
-
- it "should initialize the ast context with the correct line number" do
- @parser.expects(:ast_context).with { |a,b| b == 123 }.returns({})
- @parser.newnode(@nodename, { :line => 123 })
- end
- end
-
- %w{class define}.each do |entity|
- describe "when creating a #{entity}" do
- before :each do
- @parser.stubs(:ast_context).returns({})
-
- @name = stub "#{entity}name", :is_a? => false, :value => "foo"
- end
-
- it "should create and add the correct resource type" do
- instance = stub 'instance'
- Puppet::Resource::Type.expects(:new).returns(instance)
- @parser.known_resource_types.expects(:add).with(instance)
- @parser.send("new#{entity}", @name)
- end
-
- it "should initialize the ast context with the correct line number" do
- @parser.expects(:ast_context).with { |a,b| b == 123 }.returns({})
- @parser.send("new#{entity}", @name, { :line => 123 })
- end
- end
- end
-
describe "when retrieving a specific node" do
it "should delegate to the known_resource_types node" do
@known_resource_types.expects(:node).with("node")
@@ -391,30 +351,28 @@ describe Puppet::Parser do
@parser.stubs(:known_resource_types).returns @krt
end
- it "should create new classes" do
- @parser.parse("class foobar {}")
- @krt.hostclass("foobar").should be_instance_of(Puppet::Resource::Type)
+ it "should not create new classes" do
+ @parser.parse("class foobar {}").code[0].should be_a(Puppet::Parser::AST::Hostclass)
+ @krt.hostclass("foobar").should be_nil
end
it "should correctly set the parent class when one is provided" do
- @parser.parse("class foobar inherits yayness {}")
- @krt.hostclass("foobar").parent.should == "yayness"
+ @parser.parse("class foobar inherits yayness {}").code[0].instantiate('')[0].parent.should == "yayness"
end
it "should correctly set the parent class for multiple classes at a time" do
- @parser.parse("class foobar inherits yayness {}\nclass boo inherits bar {}")
- @krt.hostclass("foobar").parent.should == "yayness"
- @krt.hostclass("boo").parent.should == "bar"
+ statements = @parser.parse("class foobar inherits yayness {}\nclass boo inherits bar {}").code
+ statements[0].instantiate('')[0].parent.should == "yayness"
+ statements[1].instantiate('')[0].parent.should == "bar"
end
it "should define the code when some is provided" do
- @parser.parse("class foobar { $var = val }")
- @krt.hostclass("foobar").code.should_not be_nil
+ @parser.parse("class foobar { $var = val }").code[0].code.should_not be_nil
end
it "should define parameters when provided" do
- @parser.parse("class foobar($biz,$baz) {}")
- @krt.hostclass("foobar").arguments.should == {"biz" => nil, "baz" => nil}
+ foobar = @parser.parse("class foobar($biz,$baz) {}").code[0].instantiate('')[0]
+ foobar.arguments.should == {"biz" => nil, "baz" => nil}
end
end
@@ -431,13 +389,37 @@ describe Puppet::Parser do
end
it "should correctly mark exported resources as exported" do
- @parser.parse("@@file { '/file': }")
- @krt.hostclass("").code[0].exported.should be_true
+ @parser.parse("@@file { '/file': }").code[0].exported.should be_true
end
it "should correctly mark virtual resources as virtual" do
- @parser.parse("@file { '/file': }")
- @krt.hostclass("").code[0].virtual.should be_true
+ @parser.parse("@file { '/file': }").code[0].virtual.should be_true
+ end
+ end
+
+ describe "when parsing nodes" do
+ it "should be able to parse a node with a single name" do
+ node = @parser.parse("node foo { }").code[0]
+ node.should be_a Puppet::Parser::AST::Node
+ node.names.length.should == 1
+ node.names[0].value.should == "foo"
+ end
+
+ it "should be able to parse a node with two names" do
+ node = @parser.parse("node foo, bar { }").code[0]
+ node.should be_a Puppet::Parser::AST::Node
+ node.names.length.should == 2
+ node.names[0].value.should == "foo"
+ node.names[1].value.should == "bar"
+ end
+
+ it "should be able to parse a node with three names" do
+ node = @parser.parse("node foo, bar, baz { }").code[0]
+ node.should be_a Puppet::Parser::AST::Node
+ node.names.length.should == 3
+ node.names[0].value.should == "foo"
+ node.names[1].value.should == "bar"
+ node.names[2].value.should == "baz"
end
end
end
diff --git a/spec/unit/parser/relationship_spec.rb b/spec/unit/parser/relationship_spec.rb
index 57f1a772b..883a38d11 100644
--- a/spec/unit/parser/relationship_spec.rb
+++ b/spec/unit/parser/relationship_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'puppet/parser/relationship'
diff --git a/spec/unit/parser/resource_spec.rb b/spec/unit/parser/resource_spec.rb
index dae22fcaa..73c4412dd 100755
--- a/spec/unit/parser/resource_spec.rb
+++ b/spec/unit/parser/resource_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
# LAK: FIXME This is just new tests for resources; I have
# not moved all tests over yet.
diff --git a/spec/unit/parser/scope_spec.rb b/spec/unit/parser/scope_spec.rb
index 9895f446b..32a87f1f4 100755
--- a/spec/unit/parser/scope_spec.rb
+++ b/spec/unit/parser/scope_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe Puppet::Parser::Scope do
before :each do
@@ -29,8 +29,7 @@ describe Puppet::Parser::Scope do
end
it "should be able to retrieve its parent module name from the source of its parent type" do
- @topscope.source = Puppet::Resource::Type.new(:hostclass, :foo)
- @topscope.source.module_name = "foo"
+ @topscope.source = Puppet::Resource::Type.new(:hostclass, :foo, :module_name => "foo")
@scope.parent_module_name.should == "foo"
end
diff --git a/spec/unit/parser/templatewrapper_spec.rb b/spec/unit/parser/templatewrapper_spec.rb
index 68d90a1cc..aab169348 100755
--- a/spec/unit/parser/templatewrapper_spec.rb
+++ b/spec/unit/parser/templatewrapper_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'puppet/parser/templatewrapper'
describe Puppet::Parser::TemplateWrapper do
diff --git a/spec/unit/parser/type_loader_spec.rb b/spec/unit/parser/type_loader_spec.rb
index 02d543b02..12bc1ccd6 100644
--- a/spec/unit/parser/type_loader_spec.rb
+++ b/spec/unit/parser/type_loader_spec.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'puppet/parser/type_loader'
require 'puppet_spec/files'
@@ -28,85 +28,20 @@ describe Puppet::Parser::TypeLoader do
describe "when loading names from namespaces" do
it "should do nothing if the name to import is an empty string" do
@loader.expects(:name2files).never
- @loader.load_until(["foo"], "") { |f| false }.should be_nil
- end
-
- it "should turn the provided namespaces and name into a list of files" do
- @loader.expects(:name2files).with(["foo"], "bar").returns []
- @loader.load_until(["foo"], "bar") { |f| false }
+ @loader.try_load_fqname(:hostclass, "") { |filename, modname| raise :should_not_occur }.should be_nil
end
it "should attempt to import each generated name" do
- @loader.expects(:name2files).returns %w{foo bar}
- @loader.expects(:import).with("foo",nil)
- @loader.expects(:import).with("bar",nil)
- @loader.load_until(["foo"], "bar") { |f| false }
- end
-
- it "should yield after each import" do
- yielded = []
- @loader.expects(:name2files).returns %w{foo bar}
- @loader.expects(:import).with("foo",nil)
- @loader.expects(:import).with("bar",nil)
- @loader.load_until(["foo"], "bar") { |f| yielded << f; false }
- yielded.should == %w{foo bar}
- end
-
- it "should stop importing when the yielded block returns true" do
- yielded = []
- @loader.expects(:name2files).returns %w{foo bar baz}
- @loader.expects(:import).with("foo",nil)
- @loader.expects(:import).with("bar",nil)
- @loader.expects(:import).with("baz",nil).never
- @loader.load_until(["foo"], "bar") { |f| true if f == "bar" }
- end
-
- it "should return the result of the block" do
- yielded = []
- @loader.expects(:name2files).returns %w{foo bar baz}
- @loader.expects(:import).with("foo",nil)
- @loader.expects(:import).with("bar",nil)
- @loader.expects(:import).with("baz",nil).never
- @loader.load_until(["foo"], "bar") { |f| 10 if f == "bar" }.should == 10
- end
-
- it "should return nil if the block never returns true" do
- @loader.expects(:name2files).returns %w{foo bar}
- @loader.expects(:import).with("foo",nil)
- @loader.expects(:import).with("bar",nil)
- @loader.load_until(["foo"], "bar") { |f| false }.should be_nil
- end
-
- it "should set the module name on any created resource types" do
- type = Puppet::Resource::Type.new(:hostclass, "mytype")
-
- Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{one}]
- @loader.stubs(:parse_file)
- @loader.load_until(["foo"], "one") { |f| type }
-
- type.module_name.should == "modname"
- end
- end
-
- describe "when mapping names to files" do
- {
- [["foo"], "::bar::baz"] => %w{bar/baz},
- [[""], "foo::bar"] => %w{foo foo/bar},
- [%w{foo}, "bar"] => %w{foo foo/bar bar},
- [%w{a b}, "bar"] => %w{a a/bar b b/bar bar},
- [%w{a::b::c}, "bar"] => %w{a a/b/c/bar bar},
- [%w{a::b}, "foo::bar"] => %w{a a/b/foo/bar foo/bar}
- }.each do |inputs, outputs|
- it "should produce #{outputs.inspect} from the #{inputs[0].inspect} namespace and #{inputs[1]} name" do
- @loader.name2files(*inputs).should == outputs
- end
+ @loader.expects(:import).with("foo/bar",nil).returns([])
+ @loader.expects(:import).with("foo",nil).returns([])
+ @loader.try_load_fqname(:hostclass, "foo::bar") { |f| false }
end
end
describe "when importing" do
before do
Puppet::Parser::Files.stubs(:find_manifests).returns ["modname", %w{file}]
- Puppet::Parser::Parser.any_instance.stubs(:parse)
+ Puppet::Parser::Parser.any_instance.stubs(:parse).returns(Puppet::Parser::AST::Hostclass.new(''))
Puppet::Parser::Parser.any_instance.stubs(:file=)
end
@@ -138,19 +73,19 @@ describe Puppet::Parser::TypeLoader do
it "should parse each found file" do
Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{/one}]
- @loader.expects(:parse_file).with("/one")
+ @loader.expects(:parse_file).with("/one").returns(Puppet::Parser::AST::Hostclass.new(''))
@loader.import("myfile")
end
it "should make each file qualified before attempting to parse it" do
Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{one}]
- @loader.expects(:parse_file).with("/current/one")
+ @loader.expects(:parse_file).with("/current/one").returns(Puppet::Parser::AST::Hostclass.new(''))
@loader.import("myfile", "/current/file")
end
it "should not attempt to import files that have already been imported" do
Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{/one}]
- Puppet::Parser::Parser.any_instance.expects(:parse).once
+ Puppet::Parser::Parser.any_instance.expects(:parse).once.returns(Puppet::Parser::AST::Hostclass.new(''))
@loader.import("myfile")
# This will fail if it tries to reimport the file.
@@ -158,10 +93,107 @@ describe Puppet::Parser::TypeLoader do
end
end
+ describe "when importing all" do
+ before do
+ @base = tmpdir("base")
+
+ # Create two module path directories
+ @modulebase1 = File.join(@base, "first")
+ FileUtils.mkdir_p(@modulebase1)
+ @modulebase2 = File.join(@base, "second")
+ FileUtils.mkdir_p(@modulebase2)
+
+ Puppet[:modulepath] = "#{@modulebase1}:#{@modulebase2}"
+ end
+
+ def mk_module(basedir, name)
+ module_dir = File.join(basedir, name)
+
+ # Go ahead and make our manifest directory
+ FileUtils.mkdir_p(File.join(module_dir, "manifests"))
+
+ return Puppet::Module.new(name)
+ end
+
+ # We have to pass the base path so that we can
+ # write to modules that are in the second search path
+ def mk_manifests(base, mod, type, files)
+ exts = {"ruby" => ".rb", "puppet" => ".pp"}
+ files.collect do |file|
+ name = mod.name + "::" + file.gsub("/", "::")
+ path = File.join(base, mod.name, "manifests", file + exts[type])
+ FileUtils.mkdir_p(File.split(path)[0])
+
+ # write out the class
+ if type == "ruby"
+ File.open(path, "w") { |f| f.print "hostclass '#{name}' do\nend" }
+ else
+ File.open(path, "w") { |f| f.print "class #{name} {}" }
+ end
+ name
+ end
+ end
+
+ it "should load all puppet manifests from all modules in the specified environment" do
+ @module1 = mk_module(@modulebase1, "one")
+ @module2 = mk_module(@modulebase2, "two")
+
+ mk_manifests(@modulebase1, @module1, "puppet", %w{a b})
+ mk_manifests(@modulebase2, @module2, "puppet", %w{c d})
+
+ @loader.import_all
+
+ @loader.environment.known_resource_types.hostclass("one::a").should be_instance_of(Puppet::Resource::Type)
+ @loader.environment.known_resource_types.hostclass("one::b").should be_instance_of(Puppet::Resource::Type)
+ @loader.environment.known_resource_types.hostclass("two::c").should be_instance_of(Puppet::Resource::Type)
+ @loader.environment.known_resource_types.hostclass("two::d").should be_instance_of(Puppet::Resource::Type)
+ end
+
+ it "should load all ruby manifests from all modules in the specified environment" do
+ @module1 = mk_module(@modulebase1, "one")
+ @module2 = mk_module(@modulebase2, "two")
+
+ mk_manifests(@modulebase1, @module1, "ruby", %w{a b})
+ mk_manifests(@modulebase2, @module2, "ruby", %w{c d})
+
+ @loader.import_all
+
+ @loader.environment.known_resource_types.hostclass("one::a").should be_instance_of(Puppet::Resource::Type)
+ @loader.environment.known_resource_types.hostclass("one::b").should be_instance_of(Puppet::Resource::Type)
+ @loader.environment.known_resource_types.hostclass("two::c").should be_instance_of(Puppet::Resource::Type)
+ @loader.environment.known_resource_types.hostclass("two::d").should be_instance_of(Puppet::Resource::Type)
+ end
+
+ it "should not load manifests from duplicate modules later in the module path" do
+ @module1 = mk_module(@modulebase1, "one")
+
+ # duplicate
+ @module2 = mk_module(@modulebase2, "one")
+
+ mk_manifests(@modulebase1, @module1, "puppet", %w{a})
+ mk_manifests(@modulebase2, @module2, "puppet", %w{c})
+
+ @loader.import_all
+
+ @loader.environment.known_resource_types.hostclass("one::c").should be_nil
+ end
+
+ it "should load manifests from subdirectories" do
+ @module1 = mk_module(@modulebase1, "one")
+
+ mk_manifests(@modulebase1, @module1, "puppet", %w{a a/b a/b/c})
+
+ @loader.import_all
+
+ @loader.environment.known_resource_types.hostclass("one::a::b").should be_instance_of(Puppet::Resource::Type)
+ @loader.environment.known_resource_types.hostclass("one::a::b::c").should be_instance_of(Puppet::Resource::Type)
+ end
+ end
+
describe "when parsing a file" do
before do
@parser = Puppet::Parser::Parser.new(@loader.environment)
- @parser.stubs(:parse)
+ @parser.stubs(:parse).returns(Puppet::Parser::AST::Hostclass.new(''))
@parser.stubs(:file=)
Puppet::Parser::Parser.stubs(:new).with(@loader.environment).returns @parser
end
@@ -173,7 +205,7 @@ describe Puppet::Parser::TypeLoader do
it "should assign the parser its file and parse" do
@parser.expects(:file=).with("/my/file")
- @parser.expects(:parse)
+ @parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new(''))
@loader.parse_file("/my/file")
end
end
@@ -185,4 +217,15 @@ describe Puppet::Parser::TypeLoader do
@loader.known_resource_types.hostclass("foo").should be_instance_of(Puppet::Resource::Type)
end
+
+ describe "when deciding where to look for files" do
+ { 'foo' => ['foo'],
+ 'foo::bar' => ['foo/bar', 'foo'],
+ 'foo::bar::baz' => ['foo/bar/baz', 'foo/bar', 'foo']
+ }.each do |fqname, expected_paths|
+ it "should look for #{fqname.inspect} in #{expected_paths.inspect}" do
+ @loader.instance_eval { name2files(fqname) }.should == expected_paths
+ end
+ end
+ end
end