summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@puppetlabs.com>2012-07-15 14:09:36 -0700
committerDaniel Pittman <daniel@puppetlabs.com>2012-07-15 15:21:31 -0700
commit574b21921c528df8ba95af3a60a3632cbb9e00d1 (patch)
tree655b7d62e8d46178c9ded0883d1b91ec2d90c6f0
parentbea5c78e1a7d9797e1da42a65f1a971378fefa91 (diff)
downloadpuppet-574b21921c528df8ba95af3a60a3632cbb9e00d1.tar.gz
A scope always has a compiler.
The scope object contained some internal code to substitute an external environment when the compiler was not supplied. This was used only in testing, not in any production capacity. In light of that, we can eliminate the dynamic decision making inside the scope and simply demand that a compiler instance (or a fake equivalent) is always supplied. This reduces the complexity of the code and makes clearer the object relationships involved. (The small cost is a lot of testing that depended on this had to change to use a real compiler. Most of the change derives from that.) Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
-rw-r--r--lib/puppet/parser/compiler.rb3
-rw-r--r--lib/puppet/parser/scope.rb10
-rwxr-xr-xspec/unit/parser/ast/arithmetic_operator_spec.rb4
-rwxr-xr-xspec/unit/parser/ast/astarray_spec.rb4
-rwxr-xr-xspec/unit/parser/ast/asthash_spec.rb4
-rwxr-xr-xspec/unit/parser/ast/boolean_operator_spec.rb4
-rwxr-xr-xspec/unit/parser/ast/casestatement_spec.rb12
-rwxr-xr-xspec/unit/parser/ast/collexpr_spec.rb4
-rwxr-xr-xspec/unit/parser/ast/comparison_operator_spec.rb5
-rwxr-xr-xspec/unit/parser/ast/ifstatement_spec.rb4
-rwxr-xr-xspec/unit/parser/ast/in_operator_spec.rb4
-rwxr-xr-xspec/unit/parser/ast/leaf_spec.rb41
-rwxr-xr-xspec/unit/parser/ast/match_operator_spec.rb4
-rwxr-xr-xspec/unit/parser/ast/minus_spec.rb4
-rwxr-xr-xspec/unit/parser/ast/not_spec.rb4
-rwxr-xr-xspec/unit/parser/ast/resource_reference_spec.rb4
-rwxr-xr-xspec/unit/parser/ast/selector_spec.rb4
-rwxr-xr-xspec/unit/parser/ast/vardef_spec.rb4
-rwxr-xr-xspec/unit/parser/functions/create_resources_spec.rb6
-rwxr-xr-xspec/unit/parser/functions/extlookup_spec.rb5
-rwxr-xr-xspec/unit/parser/functions/fail_spec.rb4
-rwxr-xr-xspec/unit/parser/functions/file_spec.rb4
-rwxr-xr-xspec/unit/parser/functions/fqdn_rand_spec.rb4
-rwxr-xr-xspec/unit/parser/functions/generate_spec.rb4
-rwxr-xr-xspec/unit/parser/functions/inline_template_spec.rb4
-rwxr-xr-xspec/unit/parser/functions/realize_spec.rb6
-rwxr-xr-xspec/unit/parser/functions/regsubst_spec.rb4
-rwxr-xr-xspec/unit/parser/functions/require_spec.rb7
-rwxr-xr-xspec/unit/parser/functions/search_spec.rb4
-rwxr-xr-xspec/unit/parser/functions/shellquote_spec.rb4
-rwxr-xr-xspec/unit/parser/functions/split_spec.rb4
-rwxr-xr-xspec/unit/parser/functions/sprintf_spec.rb4
-rwxr-xr-xspec/unit/parser/functions/tag_spec.rb5
-rwxr-xr-xspec/unit/parser/functions/template_spec.rb5
-rwxr-xr-xspec/unit/parser/functions/versioncmp_spec.rb4
-rwxr-xr-xspec/unit/parser/scope_spec.rb20
-rwxr-xr-xspec/unit/resource/type_spec.rb2
-rwxr-xr-xspec/unit/resource_spec.rb6
38 files changed, 159 insertions, 70 deletions
diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb
index fe431df73..232412618 100644
--- a/lib/puppet/parser/compiler.rb
+++ b/lib/puppet/parser/compiler.rb
@@ -204,8 +204,7 @@ class Puppet::Parser::Compiler
# using the top scope.
def newscope(parent, options = {})
parent ||= topscope
- options[:compiler] = self
- scope = Puppet::Parser::Scope.new(options)
+ scope = Puppet::Parser::Scope.new(options.merge(:compiler => self))
scope.parent = parent
scope
end
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index 11f9aec8b..7e0a292e2 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -66,11 +66,11 @@ class Puppet::Parser::Scope
# Proxy accessors
def host
- @compiler.node.name
+ compiler.node.name
end
def facts
- @compiler.node.facts
+ compiler.node.facts
end
def include?(name)
@@ -115,7 +115,7 @@ class Puppet::Parser::Scope
end
def environment
- compiler ? compiler.environment : Puppet::Node::Environment.new
+ compiler.environment
end
def find_hostclass(name, options = {})
@@ -132,6 +132,10 @@ class Puppet::Parser::Scope
# Initialize our new scope. Defaults to having no parent.
def initialize(hash = {})
+ unless hash[:compiler]
+ raise Puppet::DevError, "you must pass a compiler instance to a new scope object"
+ end
+
if hash.include?(:namespace)
if n = hash[:namespace]
@namespaces = [n]
diff --git a/spec/unit/parser/ast/arithmetic_operator_spec.rb b/spec/unit/parser/ast/arithmetic_operator_spec.rb
index 57ec3007f..173a789f4 100755
--- a/spec/unit/parser/ast/arithmetic_operator_spec.rb
+++ b/spec/unit/parser/ast/arithmetic_operator_spec.rb
@@ -6,7 +6,9 @@ describe Puppet::Parser::AST::ArithmeticOperator do
ast = Puppet::Parser::AST
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
@one = stub 'lval', :safeevaluate => 1
@two = stub 'rval', :safeevaluate => 2
end
diff --git a/spec/unit/parser/ast/astarray_spec.rb b/spec/unit/parser/ast/astarray_spec.rb
index b5ea19d14..9a54cf9d6 100755
--- a/spec/unit/parser/ast/astarray_spec.rb
+++ b/spec/unit/parser/ast/astarray_spec.rb
@@ -3,7 +3,9 @@ require 'spec_helper'
describe Puppet::Parser::AST::ASTArray do
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
end
it "should have a [] accessor" do
diff --git a/spec/unit/parser/ast/asthash_spec.rb b/spec/unit/parser/ast/asthash_spec.rb
index 648d15fe9..e18d1f76f 100755
--- a/spec/unit/parser/ast/asthash_spec.rb
+++ b/spec/unit/parser/ast/asthash_spec.rb
@@ -3,7 +3,9 @@ require 'spec_helper'
describe Puppet::Parser::AST::ASTHash do
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
end
it "should have a merge functionality" do
diff --git a/spec/unit/parser/ast/boolean_operator_spec.rb b/spec/unit/parser/ast/boolean_operator_spec.rb
index 14151e421..4c8704d7c 100755
--- a/spec/unit/parser/ast/boolean_operator_spec.rb
+++ b/spec/unit/parser/ast/boolean_operator_spec.rb
@@ -6,7 +6,9 @@ describe Puppet::Parser::AST::BooleanOperator do
ast = Puppet::Parser::AST
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
@true_ast = ast::Boolean.new( :value => true)
@false_ast = ast::Boolean.new( :value => false)
end
diff --git a/spec/unit/parser/ast/casestatement_spec.rb b/spec/unit/parser/ast/casestatement_spec.rb
index b99479542..cec4a6856 100755
--- a/spec/unit/parser/ast/casestatement_spec.rb
+++ b/spec/unit/parser/ast/casestatement_spec.rb
@@ -3,7 +3,9 @@ require 'spec_helper'
describe Puppet::Parser::AST::CaseStatement do
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
end
describe "when evaluating" do
@@ -153,9 +155,11 @@ describe Puppet::Parser::AST::CaseStatement do
tests.each do |should, values|
values.each do |value|
- @scope = Puppet::Parser::Scope.new
- @scope['testparam'] = value
- result = ast.evaluate(@scope)
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ scope = Puppet::Parser::Scope.new(:compiler => compiler)
+ scope['testparam'] = value
+ result = ast.evaluate(scope)
result.should == should
end
diff --git a/spec/unit/parser/ast/collexpr_spec.rb b/spec/unit/parser/ast/collexpr_spec.rb
index 9fb5c530a..09e299ca6 100755
--- a/spec/unit/parser/ast/collexpr_spec.rb
+++ b/spec/unit/parser/ast/collexpr_spec.rb
@@ -6,7 +6,9 @@ describe Puppet::Parser::AST::CollExpr do
ast = Puppet::Parser::AST
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
end
describe "when evaluating with two operands" do
diff --git a/spec/unit/parser/ast/comparison_operator_spec.rb b/spec/unit/parser/ast/comparison_operator_spec.rb
index 70bb49067..fc8d098cd 100755
--- a/spec/unit/parser/ast/comparison_operator_spec.rb
+++ b/spec/unit/parser/ast/comparison_operator_spec.rb
@@ -3,7 +3,10 @@ require 'spec_helper'
describe Puppet::Parser::AST::ComparisonOperator do
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
+
@one = Puppet::Parser::AST::Leaf.new(:value => "1")
@two = Puppet::Parser::AST::Leaf.new(:value => "2")
diff --git a/spec/unit/parser/ast/ifstatement_spec.rb b/spec/unit/parser/ast/ifstatement_spec.rb
index a03c8209e..9afd0e7db 100755
--- a/spec/unit/parser/ast/ifstatement_spec.rb
+++ b/spec/unit/parser/ast/ifstatement_spec.rb
@@ -3,7 +3,9 @@ require 'spec_helper'
describe Puppet::Parser::AST::IfStatement do
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
end
describe "when evaluating" do
diff --git a/spec/unit/parser/ast/in_operator_spec.rb b/spec/unit/parser/ast/in_operator_spec.rb
index f158fd381..089c93729 100755
--- a/spec/unit/parser/ast/in_operator_spec.rb
+++ b/spec/unit/parser/ast/in_operator_spec.rb
@@ -5,7 +5,9 @@ require 'puppet/parser/ast/in_operator'
describe Puppet::Parser::AST::InOperator do
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
@lval = stub 'lval'
@lval.stubs(:safeevaluate).with(@scope).returns("left")
diff --git a/spec/unit/parser/ast/leaf_spec.rb b/spec/unit/parser/ast/leaf_spec.rb
index a77cda0b1..abc2d886a 100755
--- a/spec/unit/parser/ast/leaf_spec.rb
+++ b/spec/unit/parser/ast/leaf_spec.rb
@@ -3,7 +3,9 @@ require 'spec_helper'
describe Puppet::Parser::AST::Leaf do
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
@value = stub 'value'
@leaf = Puppet::Parser::AST::Leaf.new(:value => @value)
end
@@ -56,8 +58,11 @@ end
describe Puppet::Parser::AST::Concat do
describe "when evaluating" do
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
end
+
it "should interpolate variables and concatenate their values" do
one = Puppet::Parser::AST::String.new(:value => "one")
one.stubs(:evaluate).returns("one ")
@@ -86,8 +91,10 @@ end
describe Puppet::Parser::AST::Undef do
before :each do
- @scope = Puppet::Parser::Scope.new
- @undef = Puppet::Parser::AST::Undef.new(:value => :undef)
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
+ @undef = Puppet::Parser::AST::Undef.new(:value => :undef)
end
it "should match undef with undef" do
@@ -101,7 +108,9 @@ end
describe Puppet::Parser::AST::HashOrArrayAccess do
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
end
describe "when evaluating" do
@@ -223,7 +232,10 @@ describe Puppet::Parser::AST::HashOrArrayAccess do
describe "when assigning" do
it "should add a new key and value" do
- scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ scope = Puppet::Parser::Scope.new(:compiler => compiler)
+
scope['a'] = { 'a' => 'b' }
access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "b")
@@ -241,7 +253,10 @@ describe Puppet::Parser::AST::HashOrArrayAccess do
end
it "should be able to return an array member when index is a stringified number" do
- scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ scope = Puppet::Parser::Scope.new(:compiler => compiler)
+
scope['a'] = []
access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "0" )
@@ -261,7 +276,9 @@ end
describe Puppet::Parser::AST::Regex do
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
end
describe "when initializing" do
@@ -359,7 +376,9 @@ end
describe Puppet::Parser::AST::Variable do
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
@var = Puppet::Parser::AST::Variable.new(:value => "myvar", :file => 'my.pp', :line => 222)
end
@@ -387,7 +406,9 @@ end
describe Puppet::Parser::AST::HostName do
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
@value = stub 'value', :=~ => false
@value.stubs(:to_s).returns(@value)
@value.stubs(:downcase).returns(@value)
diff --git a/spec/unit/parser/ast/match_operator_spec.rb b/spec/unit/parser/ast/match_operator_spec.rb
index 33e3b9516..7644a3411 100755
--- a/spec/unit/parser/ast/match_operator_spec.rb
+++ b/spec/unit/parser/ast/match_operator_spec.rb
@@ -3,7 +3,9 @@ require 'spec_helper'
describe Puppet::Parser::AST::MatchOperator do
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
@lval = stub 'lval'
@lval.stubs(:safeevaluate).with(@scope).returns("this is a string")
diff --git a/spec/unit/parser/ast/minus_spec.rb b/spec/unit/parser/ast/minus_spec.rb
index 9b2f7f74e..d844cd3fa 100755
--- a/spec/unit/parser/ast/minus_spec.rb
+++ b/spec/unit/parser/ast/minus_spec.rb
@@ -3,7 +3,9 @@ require 'spec_helper'
describe Puppet::Parser::AST::Minus do
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
end
it "should evaluate its argument" do
diff --git a/spec/unit/parser/ast/not_spec.rb b/spec/unit/parser/ast/not_spec.rb
index 7f26d3bb2..3d8607cda 100755
--- a/spec/unit/parser/ast/not_spec.rb
+++ b/spec/unit/parser/ast/not_spec.rb
@@ -3,7 +3,9 @@ require 'spec_helper'
describe Puppet::Parser::AST::Not do
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
@true_ast = Puppet::Parser::AST::Boolean.new( :value => true)
@false_ast = Puppet::Parser::AST::Boolean.new( :value => false)
end
diff --git a/spec/unit/parser/ast/resource_reference_spec.rb b/spec/unit/parser/ast/resource_reference_spec.rb
index d7f4ba503..174c8aef5 100755
--- a/spec/unit/parser/ast/resource_reference_spec.rb
+++ b/spec/unit/parser/ast/resource_reference_spec.rb
@@ -6,7 +6,9 @@ describe Puppet::Parser::AST::ResourceReference do
ast = Puppet::Parser::AST
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
end
def ast_name(value)
diff --git a/spec/unit/parser/ast/selector_spec.rb b/spec/unit/parser/ast/selector_spec.rb
index 0a4921fd2..e9213c159 100755
--- a/spec/unit/parser/ast/selector_spec.rb
+++ b/spec/unit/parser/ast/selector_spec.rb
@@ -2,7 +2,9 @@
require 'spec_helper'
describe Puppet::Parser::AST::Selector do
- let :scope do Puppet::Parser::Scope.new end
+ let :node do Puppet::Node.new('localhost') end
+ let :compiler do Puppet::Parser::Compiler.new(node) end
+ let :scope do Puppet::Parser::Scope.new(:compiler => compiler) end
# Take a code expression containing a selector, and return that portion of
# the AST. This does the magic required to make that legal and all.
diff --git a/spec/unit/parser/ast/vardef_spec.rb b/spec/unit/parser/ast/vardef_spec.rb
index 4a1dcc3ed..ee1010f03 100755
--- a/spec/unit/parser/ast/vardef_spec.rb
+++ b/spec/unit/parser/ast/vardef_spec.rb
@@ -3,7 +3,9 @@ require 'spec_helper'
describe Puppet::Parser::AST::VarDef do
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
end
describe "when evaluating" do
diff --git a/spec/unit/parser/functions/create_resources_spec.rb b/spec/unit/parser/functions/create_resources_spec.rb
index 043236fd8..90548f86f 100755
--- a/spec/unit/parser/functions/create_resources_spec.rb
+++ b/spec/unit/parser/functions/create_resources_spec.rb
@@ -6,10 +6,10 @@ describe 'function for dynamically creating resources' do
include PuppetSpec::Compiler
before :each do
- @scope = Puppet::Parser::Scope.new
- @scope.compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("floppy", :environment => 'production'))
+ node = Puppet::Node.new("floppy", :environment => 'production')
+ @compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => @compiler)
@topscope = @scope.compiler.topscope
- @compiler = @scope.compiler
@scope.parent = @topscope
Puppet::Parser::Functions.function(:create_resources)
end
diff --git a/spec/unit/parser/functions/extlookup_spec.rb b/spec/unit/parser/functions/extlookup_spec.rb
index eadf51662..e1d56f4a9 100755
--- a/spec/unit/parser/functions/extlookup_spec.rb
+++ b/spec/unit/parser/functions/extlookup_spec.rb
@@ -10,8 +10,9 @@ describe "the extlookup function" do
end
before :each do
- @scope = Puppet::Parser::Scope.new
- @scope.stubs(:environment).returns(Puppet::Node::Environment.new('production'))
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
end
it "should exist" do
diff --git a/spec/unit/parser/functions/fail_spec.rb b/spec/unit/parser/functions/fail_spec.rb
index 48e0e0bde..0000ad736 100755
--- a/spec/unit/parser/functions/fail_spec.rb
+++ b/spec/unit/parser/functions/fail_spec.rb
@@ -7,7 +7,9 @@ describe "the 'fail' parser function" do
end
let :scope do
- scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ scope = Puppet::Parser::Scope.new(:compiler => compiler)
scope.stubs(:environment).returns(nil)
scope
end
diff --git a/spec/unit/parser/functions/file_spec.rb b/spec/unit/parser/functions/file_spec.rb
index 37e12b194..a69d5234a 100755
--- a/spec/unit/parser/functions/file_spec.rb
+++ b/spec/unit/parser/functions/file_spec.rb
@@ -9,7 +9,9 @@ describe "the 'file' function" do
Puppet::Parser::Functions.autoloader.loadall
end
- let :scope do Puppet::Parser::Scope.new end
+ let :node do Puppet::Node.new('localhost') end
+ let :compiler do Puppet::Parser::Compiler.new(node) end
+ let :scope do Puppet::Parser::Scope.new(:compiler => compiler) end
it "should exist" do
Puppet::Parser::Functions.function("file").should == "function_file"
diff --git a/spec/unit/parser/functions/fqdn_rand_spec.rb b/spec/unit/parser/functions/fqdn_rand_spec.rb
index a6b0d6b29..d7e8bd106 100755
--- a/spec/unit/parser/functions/fqdn_rand_spec.rb
+++ b/spec/unit/parser/functions/fqdn_rand_spec.rb
@@ -7,7 +7,9 @@ describe "the fqdn_rand function" do
end
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
@scope[:fqdn] = "127.0.0.1"
end
diff --git a/spec/unit/parser/functions/generate_spec.rb b/spec/unit/parser/functions/generate_spec.rb
index 8d3dd01fb..62d4ec5f9 100755
--- a/spec/unit/parser/functions/generate_spec.rb
+++ b/spec/unit/parser/functions/generate_spec.rb
@@ -8,7 +8,9 @@ describe "the generate function" do
Puppet::Parser::Functions.autoloader.loadall
end
- let(:scope) { Puppet::Parser::Scope.new }
+ let :node do Puppet::Node.new('localhost') end
+ let :compiler do Puppet::Parser::Compiler.new(node) end
+ let :scope do Puppet::Parser::Scope.new(:compiler => compiler) end
it "should exist" do
Puppet::Parser::Functions.function("generate").should == "function_generate"
diff --git a/spec/unit/parser/functions/inline_template_spec.rb b/spec/unit/parser/functions/inline_template_spec.rb
index d32eb2eab..389c0dc7d 100755
--- a/spec/unit/parser/functions/inline_template_spec.rb
+++ b/spec/unit/parser/functions/inline_template_spec.rb
@@ -7,7 +7,9 @@ describe "the inline_template function" do
end
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
end
it "should exist" do
diff --git a/spec/unit/parser/functions/realize_spec.rb b/spec/unit/parser/functions/realize_spec.rb
index efff4ff30..808c0f125 100755
--- a/spec/unit/parser/functions/realize_spec.rb
+++ b/spec/unit/parser/functions/realize_spec.rb
@@ -8,10 +8,10 @@ describe "the realize function" do
before :each do
@collector = stub_everything 'collector'
- @scope = Puppet::Parser::Scope.new
- @compiler = stub 'compiler'
+ node = Puppet::Node.new('localhost')
+ @compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => @compiler)
@compiler.stubs(:add_collection).with(@collector)
- @scope.stubs(:compiler).returns(@compiler)
end
it "should exist" do
diff --git a/spec/unit/parser/functions/regsubst_spec.rb b/spec/unit/parser/functions/regsubst_spec.rb
index 25101e53a..196b9a114 100755
--- a/spec/unit/parser/functions/regsubst_spec.rb
+++ b/spec/unit/parser/functions/regsubst_spec.rb
@@ -7,7 +7,9 @@ describe "the regsubst function" do
end
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
end
it "should exist" do
diff --git a/spec/unit/parser/functions/require_spec.rb b/spec/unit/parser/functions/require_spec.rb
index 9d1e4710a..578696255 100755
--- a/spec/unit/parser/functions/require_spec.rb
+++ b/spec/unit/parser/functions/require_spec.rb
@@ -8,11 +8,12 @@ describe "the require function" do
before :each do
@catalog = stub 'catalog'
- @compiler = stub 'compiler', :catalog => @catalog, :environment => nil
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
+
@scope.stubs(:findresource)
- @scope.stubs(:compiler).returns(@compiler)
@klass = stub 'class', :name => "myclass"
@scope.stubs(:find_hostclass).returns(@klass)
diff --git a/spec/unit/parser/functions/search_spec.rb b/spec/unit/parser/functions/search_spec.rb
index 81b774470..0d6d31bad 100755
--- a/spec/unit/parser/functions/search_spec.rb
+++ b/spec/unit/parser/functions/search_spec.rb
@@ -6,7 +6,9 @@ describe "the 'search' function" do
Puppet::Parser::Functions.autoloader.loadall
end
- let :scope do Puppet::Parser::Scope.new end
+ let :node do Puppet::Node.new('localhost') end
+ let :compiler do Puppet::Parser::Compiler.new(node) end
+ let :scope do Puppet::Parser::Scope.new(:compiler => compiler) end
it "should exist" do
Puppet::Parser::Functions.function("search").should == "function_search"
diff --git a/spec/unit/parser/functions/shellquote_spec.rb b/spec/unit/parser/functions/shellquote_spec.rb
index 862ac1182..6d92cc805 100755
--- a/spec/unit/parser/functions/shellquote_spec.rb
+++ b/spec/unit/parser/functions/shellquote_spec.rb
@@ -6,7 +6,9 @@ describe "the shellquote function" do
Puppet::Parser::Functions.autoloader.loadall
end
- let :scope do Puppet::Parser::Scope.new end
+ let :node do Puppet::Node.new('localhost') end
+ let :compiler do Puppet::Parser::Compiler.new(node) end
+ let :scope do Puppet::Parser::Scope.new(:compiler => compiler) end
it "should exist" do
Puppet::Parser::Functions.function("shellquote").should == "function_shellquote"
diff --git a/spec/unit/parser/functions/split_spec.rb b/spec/unit/parser/functions/split_spec.rb
index 8b7052927..1ec69f6b6 100755
--- a/spec/unit/parser/functions/split_spec.rb
+++ b/spec/unit/parser/functions/split_spec.rb
@@ -7,7 +7,9 @@ describe "the split function" do
end
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
end
it "should exist" do
diff --git a/spec/unit/parser/functions/sprintf_spec.rb b/spec/unit/parser/functions/sprintf_spec.rb
index 5cc8d2d55..bbb585956 100755
--- a/spec/unit/parser/functions/sprintf_spec.rb
+++ b/spec/unit/parser/functions/sprintf_spec.rb
@@ -7,7 +7,9 @@ describe "the sprintf function" do
end
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
end
it "should exist" do
diff --git a/spec/unit/parser/functions/tag_spec.rb b/spec/unit/parser/functions/tag_spec.rb
index 3210ccbc1..89dda5300 100755
--- a/spec/unit/parser/functions/tag_spec.rb
+++ b/spec/unit/parser/functions/tag_spec.rb
@@ -7,8 +7,9 @@ describe "the 'tag' function" do
end
before :each do
- @scope = Puppet::Parser::Scope.new
- @scope.stubs(:environment).returns(nil)
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
end
it "should exist" do
diff --git a/spec/unit/parser/functions/template_spec.rb b/spec/unit/parser/functions/template_spec.rb
index 28b039529..0a1dbc5b4 100755
--- a/spec/unit/parser/functions/template_spec.rb
+++ b/spec/unit/parser/functions/template_spec.rb
@@ -6,7 +6,9 @@ describe "the template function" do
Puppet::Parser::Functions.autoloader.loadall
end
- let :scope do Puppet::Parser::Scope.new end
+ let :node do Puppet::Node.new('localhost') end
+ let :compiler do Puppet::Parser::Compiler.new(node) end
+ let :scope do Puppet::Parser::Scope.new(:compiler => compiler) end
it "should exist" do
Puppet::Parser::Functions.function("template").should == "function_template"
@@ -62,7 +64,6 @@ describe "the template function" do
def eval_template(content, *rest)
File.stubs(:read).with("template").returns(content)
Puppet::Parser::Files.stubs(:find_template).returns("template")
- scope.compiler.stubs(:environment).returns("production")
scope.function_template(['template'] + rest)
end
diff --git a/spec/unit/parser/functions/versioncmp_spec.rb b/spec/unit/parser/functions/versioncmp_spec.rb
index 34534570c..6b7bc093e 100755
--- a/spec/unit/parser/functions/versioncmp_spec.rb
+++ b/spec/unit/parser/functions/versioncmp_spec.rb
@@ -7,7 +7,9 @@ describe "the versioncmp function" do
end
before :each do
- @scope = Puppet::Parser::Scope.new
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ @scope = Puppet::Parser::Scope.new(:compiler => compiler)
end
it "should exist" do
diff --git a/spec/unit/parser/scope_spec.rb b/spec/unit/parser/scope_spec.rb
index cce894be7..acdaea3d0 100755
--- a/spec/unit/parser/scope_spec.rb
+++ b/spec/unit/parser/scope_spec.rb
@@ -4,8 +4,9 @@ require 'puppet_spec/compiler'
describe Puppet::Parser::Scope do
before :each do
- @scope = Puppet::Parser::Scope.new
- @scope.compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foo"))
+ @scope = Puppet::Parser::Scope.new(
+ :compiler => Puppet::Parser::Compiler.new(Puppet::Node.new("foo"))
+ )
@scope.source = Puppet::Resource::Type.new(:node, :foo)
@topscope = @scope.compiler.topscope
@scope.parent = @topscope
@@ -44,8 +45,8 @@ describe Puppet::Parser::Scope do
scope.environment.should equal(env)
end
- it "should use the default environment if none is available" do
- Puppet::Parser::Scope.new.environment.should equal(Puppet::Node::Environment.new)
+ it "should fail if no compiler is supplied" do
+ expect { Puppet::Parser::Scope.new }.to raise_error Puppet::DevError
end
it "should use the resource type collection helper to find its known resource types" do
@@ -84,8 +85,10 @@ describe Puppet::Parser::Scope do
end
it "should extend itself with the default Functions module if its environment is the default" do
- root = Puppet::Node::Environment.root
- scope = Puppet::Parser::Scope.new
+ root = Puppet::Node::Environment.root
+ node = Puppet::Node.new('localhost')
+ compiler = Puppet::Parser::Compiler.new(node)
+ scope = Puppet::Parser::Scope.new(:compiler => compiler)
scope.singleton_class.ancestors.should be_include(Puppet::Parser::Functions.environment_module(root))
end
end
@@ -150,6 +153,9 @@ describe Puppet::Parser::Scope do
describe "and the variable is qualified" do
before :each do
@known_resource_types = @scope.known_resource_types
+
+ node = Puppet::Node.new('localhost')
+ @compiler = Puppet::Parser::Compiler.new(node)
end
def newclass(name)
@@ -160,7 +166,7 @@ describe Puppet::Parser::Scope do
klass = newclass(name)
catalog = Puppet::Resource::Catalog.new
- catalog.add_resource(Puppet::Parser::Resource.new("stage", :main, :scope => Puppet::Parser::Scope.new))
+ catalog.add_resource(Puppet::Parser::Resource.new("stage", :main, :scope => Puppet::Parser::Scope.new(:compiler => @compiler)))
Puppet::Parser::Resource.new("class", name, :scope => @scope, :source => mock('source'), :catalog => catalog).evaluate
diff --git a/spec/unit/resource/type_spec.rb b/spec/unit/resource/type_spec.rb
index 6887c1d24..976823bca 100755
--- a/spec/unit/resource/type_spec.rb
+++ b/spec/unit/resource/type_spec.rb
@@ -351,7 +351,7 @@ describe Puppet::Resource::Type do
@child = Puppet::Resource::Type.new(:hostclass, "foo", :parent => "bar")
@krt.add @child
- @scope = Puppet::Parser::Scope.new
+ @scope = Puppet::Parser::Scope.new(:compiler => Puppet::Parser::Compiler.new(Puppet::Node.new("foo")))
end
it "should be able to define a parent" do
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index 632cded8f..ca30e13e4 100755
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -284,7 +284,7 @@ describe Puppet::Resource do
Puppet::Node::Environment.new.known_resource_types.add(
Puppet::Resource::Type.new(:definition, "default_param", :arguments => {"a" => Puppet::Parser::AST::String.new(:value => "a_default_value")})
)
- resource = Puppet::Parser::Resource.new("default_param", "name", :scope => Puppet::Parser::Scope.new)
+ resource = Puppet::Parser::Resource.new("default_param", "name", :scope => Puppet::Parser::Scope.new(:compiler => Puppet::Parser::Compiler.new(Puppet::Node.new("foo"))))
resource.set_default_parameters(@scope)
resource["a"].should == "a_default_value"
end
@@ -293,7 +293,7 @@ describe Puppet::Resource do
Puppet::Node::Environment.new.known_resource_types.add(
Puppet::Resource::Type.new(:definition, "no_default_param", :arguments => {"a" => Puppet::Parser::AST::String.new(:value => "a_default_value")})
)
- resource = Puppet::Parser::Resource.new("no_default_param", "name", :scope => Puppet::Parser::Scope.new)
+ resource = Puppet::Parser::Resource.new("no_default_param", "name", :scope => Puppet::Parser::Scope.new(:compiler => Puppet::Parser::Compiler.new(Puppet::Node.new("foo"))))
lambda { resource.set_default_parameters(@scope) }.should_not raise_error
end
@@ -301,7 +301,7 @@ describe Puppet::Resource do
Puppet::Node::Environment.new.known_resource_types.add(
Puppet::Resource::Type.new(:definition, "default_param", :arguments => {"a" => Puppet::Parser::AST::String.new(:value => "a_default_value")})
)
- resource = Puppet::Parser::Resource.new("default_param", "name", :scope => Puppet::Parser::Scope.new)
+ resource = Puppet::Parser::Resource.new("default_param", "name", :scope => Puppet::Parser::Scope.new(:compiler => Puppet::Parser::Compiler.new(Puppet::Node.new("foo"))))
resource.set_default_parameters(@scope).should == [:a]
end