summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/parser/ast/leaf.rb4
-rw-r--r--lib/puppet/parser/ast/vardef.rb2
-rw-r--r--lib/puppet/parser/functions/extlookup.rb9
-rw-r--r--lib/puppet/parser/functions/fqdn_rand.rb2
-rw-r--r--lib/puppet/parser/resource.rb2
-rw-r--r--lib/puppet/parser/scope.rb132
-rw-r--r--lib/puppet/parser/templatewrapper.rb18
-rw-r--r--lib/puppet/resource/type.rb13
-rw-r--r--lib/puppet/util/logging.rb11
-rwxr-xr-xspec/unit/parser/ast/arithmetic_operator_spec.rb10
-rwxr-xr-xspec/unit/parser/ast/comparison_operator_spec.rb4
-rwxr-xr-xspec/unit/parser/ast/leaf_spec.rb37
-rwxr-xr-xspec/unit/parser/ast/vardef_spec.rb19
-rwxr-xr-xspec/unit/parser/compiler_spec.rb4
-rwxr-xr-xspec/unit/parser/functions/extlookup_spec.rb10
-rwxr-xr-xspec/unit/parser/functions/fqdn_rand_spec.rb20
-rwxr-xr-xspec/unit/parser/scope_spec.rb191
-rwxr-xr-xspec/unit/parser/templatewrapper_spec.rb40
-rwxr-xr-xspec/unit/resource/type_spec.rb36
-rwxr-xr-xspec/unit/util/logging_spec.rb25
-rwxr-xr-xtest/language/functions.rb10
-rwxr-xr-xtest/language/scope.rb23
22 files changed, 194 insertions, 428 deletions
diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb
index 77617e992..c8ebc9483 100644
--- a/lib/puppet/parser/ast/leaf.rb
+++ b/lib/puppet/parser/ast/leaf.rb
@@ -124,7 +124,7 @@ class Puppet::Parser::AST
# not include syntactical constructs, like '$' and '{}').
def evaluate(scope)
parsewrap do
- if (var = scope.lookupvar(@value, false)) == :undefined
+ if (var = scope.lookupvar(@value, :file => file, :line => line)) == :undefined
var = :undef
end
var
@@ -141,7 +141,7 @@ class Puppet::Parser::AST
def evaluate_container(scope)
container = variable.respond_to?(:evaluate) ? variable.safeevaluate(scope) : variable
- (container.is_a?(Hash) or container.is_a?(Array)) ? container : scope.lookupvar(container)
+ (container.is_a?(Hash) or container.is_a?(Array)) ? container : scope.lookupvar(container, :file => file, :line => line)
end
def evaluate_key(scope)
diff --git a/lib/puppet/parser/ast/vardef.rb b/lib/puppet/parser/ast/vardef.rb
index 6de1860c8..b766311dd 100644
--- a/lib/puppet/parser/ast/vardef.rb
+++ b/lib/puppet/parser/ast/vardef.rb
@@ -20,7 +20,7 @@ class Puppet::Parser::AST
name = @name.safeevaluate(scope)
parsewrap do
- scope.setvar(name,value, :file => @file, :line => @line, :append => @append)
+ scope.setvar(name,value, :file => file, :line => line, :append => @append)
end
end
end
diff --git a/lib/puppet/parser/functions/extlookup.rb b/lib/puppet/parser/functions/extlookup.rb
index bc55410b9..5fbf26cec 100644
--- a/lib/puppet/parser/functions/extlookup.rb
+++ b/lib/puppet/parser/functions/extlookup.rb
@@ -91,14 +91,9 @@ This is for back compatibility to interpolate variables with %. % interpolation
raise Puppet::ParseError, ("extlookup(): wrong number of arguments (#{args.length}; must be <= 3)") if args.length > 3
- extlookup_datadir = lookupvar('extlookup_datadir')
- extlookup_precedence = Array.new
+ extlookup_datadir = undef_as('',lookupvar('::extlookup_datadir'))
- extlookup_precedence = lookupvar('extlookup_precedence').collect do |var|
- var.gsub(/%\{(.+?)\}/) do |capture|
- lookupvar($1)
- end
- end
+ extlookup_precedence = undef_as([],lookupvar('::extlookup_precedence')).collect { |var| var.gsub(/%\{(.+?)\}/) { lookupvar("::#{$1}") } }
datafiles = Array.new
diff --git a/lib/puppet/parser/functions/fqdn_rand.rb b/lib/puppet/parser/functions/fqdn_rand.rb
index 91157a148..93ab98bcd 100644
--- a/lib/puppet/parser/functions/fqdn_rand.rb
+++ b/lib/puppet/parser/functions/fqdn_rand.rb
@@ -7,6 +7,6 @@ Puppet::Parser::Functions::newfunction(:fqdn_rand, :type => :rvalue, :doc =>
$random_number_seed = fqdn_rand(30,30)") do |args|
require 'digest/md5'
max = args.shift
- srand(Digest::MD5.hexdigest([lookupvar('fqdn'),args].join(':')).hex)
+ srand(Digest::MD5.hexdigest([lookupvar('::fqdn'),args].join(':')).hex)
rand(max).to_s
end
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index c007d4dbe..ace01bb4b 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -241,7 +241,7 @@ class Puppet::Parser::Resource < Puppet::Resource
def add_backward_compatible_relationship_param(name)
# Skip metaparams for which we get no value.
- return unless val = scope.lookupvar(name.to_s, false) and val != :undefined
+ return unless val = scope.lookupvar(name.to_s) and val != :undefined
# The default case: just set the value
set_parameter(name, val) and return unless @parameters[name]
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index 24f1d01f7..8de9d60b1 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -18,10 +18,10 @@ class Puppet::Parser::Scope
include Enumerable
include Puppet::Util::Errors
- attr_accessor :level, :source, :resource
+ attr_accessor :source, :resource
attr_accessor :base, :keyword
attr_accessor :top, :translated, :compiler
- attr_accessor :parent
+ attr_accessor :parent, :dynamic
attr_reader :namespaces
# thin wrapper around an ephemeral
@@ -104,11 +104,6 @@ class Puppet::Parser::Scope
compiler.environment
end
- # Are we the top scope?
- def topscope?
- @level == 1
- end
-
def find_hostclass(name)
known_resource_types.find_hostclass(namespaces, name)
end
@@ -215,45 +210,41 @@ class Puppet::Parser::Scope
find_definition(name) || find_hostclass(name)
end
- def lookup_qualified_var(name, usestring)
- parts = name.split(/::/)
- shortname = parts.pop
- klassname = parts.join("::")
- klass = find_hostclass(klassname)
- unless klass
- warning "Could not look up qualified variable '#{name}'; class #{klassname} could not be found"
- return usestring ? "" : :undefined
- end
- unless kscope = class_scope(klass)
- warning "Could not look up qualified variable '#{name}'; class #{klassname} has not been evaluated"
- return usestring ? "" : :undefined
- end
- kscope.lookupvar(shortname, usestring)
+ def undef_as(x,v)
+ (v == :undefined) ? x : (v == :undef) ? x : v
end
- private :lookup_qualified_var
+ def qualified_scope(classname)
+ raise "class #{classname} could not be found" unless klass = find_hostclass(classname)
+ raise "class #{classname} has not been evaluated" unless kscope = class_scope(klass)
+ kscope
+ end
+
+ private :qualified_scope
- # Look up a variable. The simplest value search we do. Default to returning
- # an empty string for missing values, but support returning a constant.
- def lookupvar(name, usestring = true)
+ # Look up a variable. The simplest value search we do.
+ def lookupvar(name, options = {})
table = ephemeral?(name) ? @ephemeral.last : @symtable
# If the variable is qualified, then find the specified scope and look the variable up there instead.
- if name =~ /::/
- return lookup_qualified_var(name, usestring)
- end
- # We can't use "if table[name]" here because the value might be false
- if ephemeral_include?(name) or table.include?(name)
- if usestring and table[name] == :undef
- return ""
- else
- return table[name]
+ if name =~ /^(.*)::(.+)$/
+ begin
+ qualified_scope($1).lookupvar($2,options)
+ rescue RuntimeError => e
+ location = (options[:file] && options[:line]) ? " at #{options[:file]}:#{options[:line]}" : ''
+ warning "Could not look up qualified variable '#{name}'; #{e.message}#{location}"
+ :undefined
end
- elsif self.parent
- return parent.lookupvar(name, usestring)
- elsif usestring
- return ""
+ elsif ephemeral_include?(name) or table.include?(name)
+ # We can't use "if table[name]" here because the value might be false
+ if options[:dynamic] and self != compiler.topscope
+ location = (options[:file] && options[:line]) ? " at #{options[:file]}:#{options[:line]}" : ''
+ Puppet.deprecation_warning "Dynamic lookup of $#{name}#{location} will not be supported in future versions. Use a fully-qualified variable name or parameterized classes."
+ end
+ table[name]
+ elsif parent
+ parent.lookupvar(name,options.merge(:dynamic => (dynamic || options[:dynamic])))
else
- return :undefined
+ :undefined
end
end
@@ -323,8 +314,6 @@ class Puppet::Parser::Scope
# to be reassigned.
def setvar(name,value, options = {})
table = options[:ephemeral] ? @ephemeral.last : @symtable
- #Puppet.debug "Setting %s to '%s' at level %s mode append %s" %
- # [name.inspect,value,self.level, append]
if table.include?(name)
unless options[:append]
error = Puppet::ParseError.new("Cannot reassign variable #{name}")
@@ -340,7 +329,7 @@ class Puppet::Parser::Scope
table[name] = value
else # append case
# lookup the value in the scope if it exists and insert the var
- table[name] = lookupvar(name)
+ table[name] = undef_as('',lookupvar(name))
# concatenate if string, append if array, nothing for other types
case value
when Array
@@ -354,65 +343,6 @@ class Puppet::Parser::Scope
end
end
- # Return an interpolated string.
- def strinterp(string, file = nil, line = nil)
- # Most strings won't have variables in them.
- ss = StringScanner.new(string)
- out = ""
- while not ss.eos?
- if ss.scan(/^\$\{((\w*::)*\w+|[0-9]+)\}|^\$([0-9])|^\$((\w*::)*\w+)/)
- # If it matches the backslash, then just retun the dollar sign.
- if ss.matched == '\\$'
- out << '$'
- else # look the variable up
- # make sure $0-$9 are lookupable only if ephemeral
- var = ss[1] || ss[3] || ss[4]
- if var and var =~ /^[0-9]+$/ and not ephemeral_include?(var)
- next
- end
- out << lookupvar(var).to_s || ""
- end
- elsif ss.scan(/^\\(.)/)
- # Puppet.debug("Got escape: pos:%d; m:%s" % [ss.pos, ss.matched])
- case ss[1]
- when 'n'
- out << "\n"
- when 't'
- out << "\t"
- when 's'
- out << " "
- when '\\'
- out << '\\'
- when '$'
- out << '$'
- else
- str = "Unrecognised escape sequence '#{ss.matched}'"
- str += " in file #{file}" if file
- str += " at line #{line}" if line
- Puppet.warning str
- out << ss.matched
- end
- elsif ss.scan(/^\$/)
- out << '$'
- elsif ss.scan(/^\\\n/) # an escaped carriage return
- next
- else
- tmp = ss.scan(/[^\\$]+/)
- # Puppet.debug("Got other: pos:%d; m:%s" % [ss.pos, tmp])
- unless tmp
- error = Puppet::ParseError.new("Could not parse string #{string.inspect}")
- {:file= => file, :line= => line}.each do |m,v|
- error.send(m, v) if v
- end
- raise error
- end
- out << tmp
- end
- end
-
- out
- end
-
# Return the tags associated with this scope. It's basically
# just our parents' tags, plus our type. We don't cache this value
# because our parent tags might change between calls.
diff --git a/lib/puppet/parser/templatewrapper.rb b/lib/puppet/parser/templatewrapper.rb
index 6864aa1a9..180a03dc9 100644
--- a/lib/puppet/parser/templatewrapper.rb
+++ b/lib/puppet/parser/templatewrapper.rb
@@ -18,13 +18,14 @@ class Puppet::Parser::TemplateWrapper
@__scope__
end
+ def script_line
+ # find which line in the template (if any) we were called from
+ caller.find { |l| l =~ /#{file}:/ }.first[/:(\d+):/,1]
+ end
+
# Should return true if a variable is defined, false if it is not
def has_variable?(name)
- if scope.lookupvar(name.to_s, false) != :undefined
- true
- else
- false
- end
+ scope.lookupvar(name.to_s, :file => file, :line => script_line) != :undefined
end
# Allow templates to access the defined classes
@@ -55,15 +56,13 @@ class Puppet::Parser::TemplateWrapper
# the missing_method definition here until we declare the syntax finally
# dead.
def method_missing(name, *args)
- # We have to tell lookupvar to return :undefined to us when
- # appropriate; otherwise it converts to "".
- value = scope.lookupvar(name.to_s, false)
+ value = scope.lookupvar(name.to_s,:file => file,:line => script_line)
if value != :undefined
return value
else
# Just throw an error immediately, instead of searching for
# other missingmethod things or whatever.
- raise Puppet::ParseError, "Could not find value for '#{name}'"
+ raise Puppet::ParseError.new("Could not find value for '#{name}'",@file,script_line)
end
end
@@ -103,6 +102,7 @@ class Puppet::Parser::TemplateWrapper
result = nil
benchmark(:debug, "Interpolated template #{template_source}") do
template = ERB.new(self.string, 0, "-")
+ template.filename = file
result = template.result(binding)
end
diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb
index 48d8c1f48..f8d820b77 100644
--- a/lib/puppet/resource/type.rb
+++ b/lib/puppet/resource/type.rb
@@ -62,13 +62,11 @@ class Puppet::Resource::Type
# Now evaluate the code associated with this class or definition.
def evaluate_code(resource)
- scope = resource.scope
- if tmp = evaluate_parent_type(resource)
- scope = tmp
- end
+ static_parent = evaluate_parent_type(resource)
+ scope = static_parent || resource.scope
- scope = subscope(scope, resource) unless resource.title == :main
+ scope = scope.newscope(:namespace => namespace, :source => self, :resource => resource, :dynamic => !static_parent) unless resource.title == :main
scope.compiler.add_class(name) unless definition?
set_resource_parameters(resource, scope)
@@ -263,11 +261,6 @@ class Puppet::Resource::Type
end
- # Create a new subscope in which to evaluate our code.
- def subscope(scope, resource)
- scope.newscope :resource => resource, :namespace => self.namespace, :source => self
- end
-
# Check whether a given argument is valid.
def valid_parameter?(param)
param = param.to_s
diff --git a/lib/puppet/util/logging.rb b/lib/puppet/util/logging.rb
index bc52b17f0..4e76ae414 100644
--- a/lib/puppet/util/logging.rb
+++ b/lib/puppet/util/logging.rb
@@ -15,6 +15,17 @@ module Puppet::Util::Logging
end
end
+ def deprecation_warning(message)
+ $deprecation_warnings ||= Hash.new(0)
+ if $deprecation_warnings.length < 100 and ($deprecation_warnings[message] += 1) == 1
+ warning message
+ end
+ end
+
+ def clear_deprecation_warnings
+ $deprecation_warnings.clear if $deprecation_warnings
+ end
+
private
def is_resource?
diff --git a/spec/unit/parser/ast/arithmetic_operator_spec.rb b/spec/unit/parser/ast/arithmetic_operator_spec.rb
index 6f57fd9b6..9b54f09d8 100755
--- a/spec/unit/parser/ast/arithmetic_operator_spec.rb
+++ b/spec/unit/parser/ast/arithmetic_operator_spec.rb
@@ -60,14 +60,4 @@ describe Puppet::Parser::AST::ArithmeticOperator do
operator.evaluate(@scope).should == 4.33
end
- it "should work for variables too" do
- @scope.expects(:lookupvar).with("one", false).returns(1)
- @scope.expects(:lookupvar).with("two", false).returns(2)
- one = ast::Variable.new( :value => "one" )
- two = ast::Variable.new( :value => "two" )
-
- operator = ast::ArithmeticOperator.new :lval => one, :operator => "+", :rval => two
- operator.evaluate(@scope).should == 3
- end
-
end
diff --git a/spec/unit/parser/ast/comparison_operator_spec.rb b/spec/unit/parser/ast/comparison_operator_spec.rb
index 169d92d0a..060827390 100755
--- a/spec/unit/parser/ast/comparison_operator_spec.rb
+++ b/spec/unit/parser/ast/comparison_operator_spec.rb
@@ -95,8 +95,8 @@ describe Puppet::Parser::AST::ComparisonOperator do
one = Puppet::Parser::AST::Variable.new( :value => "one" )
two = Puppet::Parser::AST::Variable.new( :value => "two" )
- @scope.expects(:lookupvar).with("one", false).returns(1)
- @scope.expects(:lookupvar).with("two", false).returns(2)
+ one.expects(:safeevaluate).with(@scope).returns(1)
+ two.expects(:safeevaluate).with(@scope).returns(2)
operator = Puppet::Parser::AST::ComparisonOperator.new :lval => one, :operator => "<", :rval => two
operator.evaluate(@scope).should == true
diff --git a/spec/unit/parser/ast/leaf_spec.rb b/spec/unit/parser/ast/leaf_spec.rb
index 3b8c14efa..cd09eaf94 100755
--- a/spec/unit/parser/ast/leaf_spec.rb
+++ b/spec/unit/parser/ast/leaf_spec.rb
@@ -107,7 +107,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do
describe "when evaluating" do
it "should evaluate the variable part if necessary" do
- @scope.stubs(:lookupvar).with("a").returns(["b"])
+ @scope.stubs(:lookupvar).with { |name,options| name == 'a'}.returns(["b"])
variable = stub 'variable', :evaluate => "a"
access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => variable, :key => 0 )
@@ -118,7 +118,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do
end
it "should evaluate the access key part if necessary" do
- @scope.stubs(:lookupvar).with("a").returns(["b"])
+ @scope.stubs(:lookupvar).with { |name,options| name == 'a'}.returns(["b"])
index = stub 'index', :evaluate => 0
access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => index )
@@ -129,7 +129,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do
end
it "should be able to return an array member" do
- @scope.stubs(:lookupvar).with("a").returns(["val1", "val2", "val3"])
+ @scope.stubs(:lookupvar).with { |name,options| name == 'a'}.returns(["val1", "val2", "val3"])
access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => 1 )
@@ -137,7 +137,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do
end
it "should be able to return an array member when index is a stringified number" do
- @scope.stubs(:lookupvar).with("a").returns(["val1", "val2", "val3"])
+ @scope.stubs(:lookupvar).with { |name,options| name == "a" }.returns(["val1", "val2", "val3"])
access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "1" )
@@ -145,7 +145,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do
end
it "should raise an error when accessing an array with a key" do
- @scope.stubs(:lookupvar).with("a").returns(["val1", "val2", "val3"])
+ @scope.stubs(:lookupvar).with { |name,options| name == "a"}.returns(["val1", "val2", "val3"])
access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "get_me_the_second_element_please" )
@@ -153,7 +153,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do
end
it "should be able to return an hash value" do
- @scope.stubs(:lookupvar).with("a").returns({ "key1" => "val1", "key2" => "val2", "key3" => "val3" })
+ @scope.stubs(:lookupvar).with { |name,options| name == 'a'}.returns({ "key1" => "val1", "key2" => "val2", "key3" => "val3" })
access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "key2" )
@@ -161,7 +161,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do
end
it "should be able to return an hash value with a numerical key" do
- @scope.stubs(:lookupvar).with("a").returns({ "key1" => "val1", "key2" => "val2", "45" => "45", "key3" => "val3" })
+ @scope.stubs(:lookupvar).with { |name,options| name == "a"}.returns({ "key1" => "val1", "key2" => "val2", "45" => "45", "key3" => "val3" })
access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "45" )
@@ -169,7 +169,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do
end
it "should raise an error if the variable lookup didn't return an hash or an array" do
- @scope.stubs(:lookupvar).with("a").returns("I'm a string")
+ @scope.stubs(:lookupvar).with { |name,options| name == "a"}.returns("I'm a string")
access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "key2" )
@@ -177,7 +177,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do
end
it "should raise an error if the variable wasn't in the scope" do
- @scope.stubs(:lookupvar).with("a").returns(nil)
+ @scope.stubs(:lookupvar).with { |name,options| name == 'a'}.returns(nil)
access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "key2" )
@@ -190,7 +190,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do
end
it "should work with recursive hash access" do
- @scope.stubs(:lookupvar).with("a").returns({ "key" => { "subkey" => "b" }})
+ @scope.stubs(:lookupvar).with { |name,options| name == 'a'}.returns({ "key" => { "subkey" => "b" }})
access1 = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "key")
access2 = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => access1, :key => "subkey")
@@ -199,7 +199,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do
end
it "should work with interleaved array and hash access" do
- @scope.stubs(:lookupvar).with("a").returns({ "key" => [ "a" , "b" ]})
+ @scope.stubs(:lookupvar).with { |name,options| name == 'a'}.returns({ "key" => [ "a" , "b" ]})
access1 = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "key")
access2 = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => access1, :key => 1)
@@ -220,7 +220,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do
end
it "should raise an error when assigning an array element with a key" do
- @scope.stubs(:lookupvar).with("a").returns([])
+ @scope.stubs(:lookupvar).with { |name,options| name == "a"}.returns([])
access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "get_me_the_second_element_please" )
@@ -238,7 +238,7 @@ describe Puppet::Parser::AST::HashOrArrayAccess do
end
it "should raise an error when trying to overwrite an hash value" do
- @scope.stubs(:lookupvar).with("a").returns({ "key" => [ "a" , "b" ]})
+ @scope.stubs(:lookupvar).with { |name,options| name == "a" }.returns({ "key" => [ "a" , "b" ]})
access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "key")
lambda { access.assign(@scope, "test") }.should raise_error
@@ -332,16 +332,21 @@ end
describe Puppet::Parser::AST::Variable do
before :each do
@scope = stub 'scope'
- @var = Puppet::Parser::AST::Variable.new(:value => "myvar")
+ @var = Puppet::Parser::AST::Variable.new(:value => "myvar", :file => 'my.pp', :line => 222)
end
it "should lookup the variable in scope" do
- @scope.expects(:lookupvar).with("myvar", false).returns(:myvalue)
+ @scope.expects(:lookupvar).with { |name,options| name == "myvar" }.returns(:myvalue)
+ @var.safeevaluate(@scope).should == :myvalue
+ end
+
+ it "should pass the source location to lookupvar" do
+ @scope.expects(:lookupvar).with { |name,options| name == "myvar" and options[:file] == 'my.pp' and options[:line] == 222 }.returns(:myvalue)
@var.safeevaluate(@scope).should == :myvalue
end
it "should return undef if the variable wasn't set" do
- @scope.expects(:lookupvar).with("myvar", false).returns(:undefined)
+ @scope.expects(:lookupvar).with { |name,options| name == "myvar" }.returns(:undefined)
@var.safeevaluate(@scope).should == :undef
end
diff --git a/spec/unit/parser/ast/vardef_spec.rb b/spec/unit/parser/ast/vardef_spec.rb
index a462e8ef5..5a851bb13 100755
--- a/spec/unit/parser/ast/vardef_spec.rb
+++ b/spec/unit/parser/ast/vardef_spec.rb
@@ -16,8 +16,7 @@ describe Puppet::Parser::AST::VarDef do
name.expects(:safeevaluate).with(@scope)
value.expects(:safeevaluate).with(@scope)
- vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil,
- :line => nil
+ vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil, :line => nil
vardef.evaluate(@scope)
end
@@ -27,8 +26,7 @@ describe Puppet::Parser::AST::VarDef do
@scope.expects(:setvar).with { |name,value,options| options[:append] == nil }
- vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil,
- :line => nil
+ vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil, :line => nil
vardef.evaluate(@scope)
end
@@ -38,8 +36,17 @@ describe Puppet::Parser::AST::VarDef do
@scope.expects(:setvar).with { |name,value,options| options[:append] == true }
- vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil,
- :line => nil, :append => true
+ vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil, :line => nil, :append => true
+ vardef.evaluate(@scope)
+ end
+
+ it "should call pass the source location to setvar" do
+ name = stub 'name', :safeevaluate => "var"
+ value = stub 'value', :safeevaluate => "1"
+
+ @scope.expects(:setvar).with { |name,value,options| options[:file] == 'setvar.pp' and options[:line] == 917 }
+
+ vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => 'setvar.pp', :line => 917
vardef.evaluate(@scope)
end
diff --git a/spec/unit/parser/compiler_spec.rb b/spec/unit/parser/compiler_spec.rb
index 0c896a4e3..de4bee3e9 100755
--- a/spec/unit/parser/compiler_spec.rb
+++ b/spec/unit/parser/compiler_spec.rb
@@ -131,10 +131,6 @@ describe Puppet::Parser::Compiler do
@compiler.newscope(@compiler.topscope).should be_instance_of(Puppet::Parser::Scope)
end
- it "should correctly set the level of newly created scopes" do
- @compiler.newscope(@compiler.topscope, :level => 5).level.should == 5
- end
-
it "should set the parent scope of the new scope to be the passed-in parent" do
scope = mock 'scope'
newscope = @compiler.newscope(scope)
diff --git a/spec/unit/parser/functions/extlookup_spec.rb b/spec/unit/parser/functions/extlookup_spec.rb
index f2560d3d9..ad89f6575 100755
--- a/spec/unit/parser/functions/extlookup_spec.rb
+++ b/spec/unit/parser/functions/extlookup_spec.rb
@@ -65,7 +65,7 @@ describe "the extlookup function" do
describe "should look in $extlookup_datadir for data files listed by $extlookup_precedence" do
before do
- @scope.stubs(:lookupvar).with('extlookup_datadir').returns("/tmp")
+ @scope.stubs(:lookupvar).with('::extlookup_datadir').returns("/tmp")
File.open("/tmp/one.csv","w"){|one| one.puts "key,value1" }
File.open("/tmp/two.csv","w") do |two|
two.puts "key,value2"
@@ -74,21 +74,21 @@ describe "the extlookup function" do
end
it "when the key is in the first file" do
- @scope.stubs(:lookupvar).with('extlookup_precedence').returns(["one","two"])
+ @scope.stubs(:lookupvar).with('::extlookup_precedence').returns(["one","two"])
result = @scope.function_extlookup([ "key" ])
result.should == "value1"
end
it "when the key is in the second file" do
- @scope.stubs(:lookupvar).with('extlookup_precedence').returns(["one","two"])
+ @scope.stubs(:lookupvar).with('::extlookup_precedence').returns(["one","two"])
result = @scope.function_extlookup([ "key2" ])
result.should == "value_two"
end
it "should not modify extlookup_precedence data" do
variable = '%{fqdn}'
- @scope.stubs(:lookupvar).with('extlookup_precedence').returns([variable,"one"])
- @scope.stubs(:lookupvar).with('fqdn').returns('myfqdn')
+ @scope.stubs(:lookupvar).with('::extlookup_precedence').returns([variable,"one"])
+ @scope.stubs(:lookupvar).with('::fqdn').returns('myfqdn')
result = @scope.function_extlookup([ "key" ])
variable.should == '%{fqdn}'
end
diff --git a/spec/unit/parser/functions/fqdn_rand_spec.rb b/spec/unit/parser/functions/fqdn_rand_spec.rb
index d810741c5..90792e182 100755
--- a/spec/unit/parser/functions/fqdn_rand_spec.rb
+++ b/spec/unit/parser/functions/fqdn_rand_spec.rb
@@ -16,49 +16,49 @@ describe "the fqdn_rand function" do
end
it "should handle 0 arguments" do
- @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
lambda { @scope.function_fqdn_rand([]) }.should_not raise_error(Puppet::ParseError)
end
it "should handle 1 argument'}" do
- @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
lambda { @scope.function_fqdn_rand([3]) }.should_not raise_error(Puppet::ParseError)
end
(1..10).each { |n|
it "should handle #{n} additional arguments" do
- @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
lambda { @scope.function_fqdn_rand([3,1,2,3,4,5,6,7,8,9,10][0..n]) }.should_not raise_error(Puppet::ParseError)
end
it "should handle #{n} additional string arguments" do
- @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
lambda { @scope.function_fqdn_rand([3,%w{ 1 2 3 4 5 6 7 8 9 10}].flatten[0..n]) }.should_not raise_error(Puppet::ParseError)
end
}
it "should return a value less than max" do
- @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
@scope.function_fqdn_rand([3]).should satisfy {|n| n.to_i < 3 }
end
it "should return the same values on subsequent invocations for the same host" do
- @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1").twice
+ @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1").twice
@scope.function_fqdn_rand([3,4]).should eql(@scope.function_fqdn_rand([3, 4]))
end
it "should return different sequences of value for different hosts" do
- @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
val1 = @scope.function_fqdn_rand([10000000,4])
- @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.2")
+ @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.2")
val2 = @scope.function_fqdn_rand([10000000,4])
val1.should_not eql(val2)
end
it "should return different values for the same hosts with different seeds" do
- @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
val1 = @scope.function_fqdn_rand([10000000,4])
- @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ @scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
val2 = @scope.function_fqdn_rand([10000000,42])
val1.should_not eql(val2)
end
diff --git a/spec/unit/parser/scope_spec.rb b/spec/unit/parser/scope_spec.rb
index 44e255956..8215535dd 100755
--- a/spec/unit/parser/scope_spec.rb
+++ b/spec/unit/parser/scope_spec.rb
@@ -73,19 +73,19 @@ describe Puppet::Parser::Scope do
Puppet::Parser::Scope.new.singleton_class.ancestors.should be_include(mod)
end
- end
- describe "when looking up a variable" do
- it "should default to an empty string" do
- @scope.lookupvar("var").should == ""
+ it "should remember if it is dynamic" do
+ (!!Puppet::Parser::Scope.new(:dynamic => true).dynamic).should == true
end
- it "should return an string when asked for a string" do
- @scope.lookupvar("var", true).should == ""
+ it "should assume it is not dynamic" do
+ (!Puppet::Parser::Scope.new.dynamic).should == true
end
+ end
- it "should return ':undefined' for unset variables when asked not to return a string" do
- @scope.lookupvar("var", false).should == :undefined
+ describe "when looking up a variable" do
+ it "should return ':undefined' for unset variables" do
+ @scope.lookupvar("var").should == :undefined
end
it "should be able to look up values" do
@@ -151,32 +151,32 @@ describe Puppet::Parser::Scope do
@scope.lookupvar("other::deep::klass::var").should == "otherval"
end
- it "should return an empty string for qualified variables that cannot be found in other classes" do
+ it "should return ':undefined' for qualified variables that cannot be found in other classes" do
other_scope = create_class_scope("other::deep::klass")
- @scope.lookupvar("other::deep::klass::var").should == ""
+ @scope.lookupvar("other::deep::klass::var").should == :undefined
end
- it "should warn and return an empty string for qualified variables whose classes have not been evaluated" do
+ it "should warn and return ':undefined' for qualified variables whose classes have not been evaluated" do
klass = newclass("other::deep::klass")
@scope.expects(:warning)
- @scope.lookupvar("other::deep::klass::var").should == ""
+ @scope.lookupvar("other::deep::klass::var").should == :undefined
end
- it "should warn and return an empty string for qualified variables whose classes do not exist" do
+ it "should warn and return ':undefined' for qualified variables whose classes do not exist" do
@scope.expects(:warning)
- @scope.lookupvar("other::deep::klass::var").should == ""
+ @scope.lookupvar("other::deep::klass::var").should == :undefined
end
it "should return ':undefined' when asked for a non-string qualified variable from a class that does not exist" do
@scope.stubs(:warning)
- @scope.lookupvar("other::deep::klass::var", false).should == :undefined
+ @scope.lookupvar("other::deep::klass::var").should == :undefined
end
it "should return ':undefined' when asked for a non-string qualified variable from a class that has not been evaluated" do
@scope.stubs(:warning)
klass = newclass("other::deep::klass")
- @scope.lookupvar("other::deep::klass::var", false).should == :undefined
+ @scope.lookupvar("other::deep::klass::var").should == :undefined
end
end
end
@@ -291,7 +291,7 @@ describe Puppet::Parser::Scope do
@scope.unset_ephemeral_var
- @scope.lookupvar("1", false).should == :undefined
+ @scope.lookupvar("1").should == :undefined
end
it "should not remove classic variables when unset_ephemeral_var is called" do
@@ -301,7 +301,7 @@ describe Puppet::Parser::Scope do
@scope.unset_ephemeral_var
- @scope.lookupvar("myvar", false).should == :value1
+ @scope.lookupvar("myvar").should == :value1
end
it "should raise an error when setting it again" do
@@ -322,7 +322,7 @@ describe Puppet::Parser::Scope do
@scope.setvar("0", :earliest, :ephemeral => true)
@scope.new_ephemeral
@scope.setvar("0", :latest, :ephemeral => true)
- @scope.lookupvar("0", false).should == :latest
+ @scope.lookupvar("0").should == :latest
end
it "should be able to report the current level" do
@@ -353,7 +353,7 @@ describe Puppet::Parser::Scope do
@scope.setvar("1", :value1, :ephemeral => true)
@scope.new_ephemeral
@scope.setvar("0", :value2, :ephemeral => true)
- @scope.lookupvar("1", false).should == :value1
+ @scope.lookupvar("1").should == :value1
end
describe "when calling unset_ephemeral_var without a level" do
@@ -364,7 +364,7 @@ describe Puppet::Parser::Scope do
@scope.unset_ephemeral_var
- @scope.lookupvar("1", false).should == :undefined
+ @scope.lookupvar("1").should == :undefined
end
end
@@ -378,152 +378,9 @@ describe Puppet::Parser::Scope do
@scope.unset_ephemeral_var(2)
- @scope.lookupvar("1", false).should == :value2
- end
- end
- end
- end
-
- describe "when interpolating string" do
- (0..9).each do |n|
- it "should allow $#{n} to match" do
- @scope.setvar(n.to_s, "value", :ephemeral => true)
-
- @scope.strinterp("$#{n}").should == "value"
- end
- end
-
- (0..9).each do |n|
- it "should not allow $#{n} to match if not ephemeral" do
- @scope.setvar(n.to_s, "value", :ephemeral => false)
-
- @scope.strinterp("$#{n}").should_not == "value"
- end
- end
-
- it "should not allow $10 to match" do
- @scope.setvar("10", "value", :ephemeral => true)
-
- @scope.strinterp('==$10==').should_not == "==value=="
- end
-
- it "should not allow ${10} to match" do
- @scope.setvar("10", "value", :ephemeral => true)
-
- @scope.strinterp('==${10}==').should == "==value=="
- end
-
- describe "with qualified variables" do
- before do
- @scopes = {}
- klass = @scope.known_resource_types.add(Puppet::Resource::Type.new(:hostclass, ""))
- Puppet::Parser::Resource.new("class", :main, :scope => @scope, :source => mock('source')).evaluate
- @scopes[""] = @scope.class_scope(klass)
- @scopes[""].setvar("test", "value")
-
- %w{one one::two one::two::three}.each do |name|
- klass = @scope.known_resource_types.add(Puppet::Resource::Type.new(:hostclass, name))
- Puppet::Parser::Resource.new("class", name, :scope => @scope, :source => mock('source')).evaluate
- @scopes[name] = @scope.class_scope(klass)
- @scopes[name].setvar("test", "value-#{name.sub(/.+::/,'')}")
+ @scope.lookupvar("1").should == :value2
end
end
- {
- "===${one::two::three::test}===" => "===value-three===",
- "===$one::two::three::test===" => "===value-three===",
- "===${one::two::test}===" => "===value-two===",
- "===$one::two::test===" => "===value-two===",
- "===${one::test}===" => "===value-one===",
- "===$one::test===" => "===value-one===",
- "===${::test}===" => "===value===",
- "===$::test===" => "===value==="
- }.each do |input, output|
- it "should parse '#{input}' correctly" do
- @scope.strinterp(input).should == output
- end
- end
- end
-
- tests = {
- "===${test}===" => "===value===",
- "===${test} ${test} ${test}===" => "===value value value===",
- "===$test ${test} $test===" => "===value value value===",
- "===\\$test===" => "===$test===",
- '===\\$test string===' => "===$test string===",
- '===$test string===' => "===value string===",
- '===a testing $===' => "===a testing $===",
- '===a testing \$===' => "===a testing $===",
- "===an escaped \\\n carriage return===" => "===an escaped carriage return===",
- '\$' => "$",
- '\s' => "\s",
- '\t' => "\t",
- '\n' => "\n"
- }
-
- tests.each do |input, output|
- it "should parse '#{input}' correctly" do
- @scope.setvar("test", "value")
- @scope.strinterp(input).should == output
- end
- end
-
- # #523
- %w{d f h l w z}.each do |l|
- it "should parse '#{l}' when escaped" do
- string = "\\#{l}"
- @scope.strinterp(string).should == string
- end
- end
- end
-
- def test_strinterp
- # Make and evaluate our classes so the qualified lookups work
- parser = mkparser
- klass = parser.newclass("")
- scope = mkscope(:parser => parser)
- Puppet::Parser::Resource.new(:type => "class", :title => :main, :scope => scope, :source => mock('source')).evaluate
-
- assert_nothing_raised {
- scope.setvar("test","value")
- }
-
- scopes = {"" => scope}
-
- %w{one one::two one::two::three}.each do |name|
- klass = parser.newclass(name)
- Puppet::Parser::Resource.new(:type => "class", :title => name, :scope => scope, :source => mock('source')).evaluate
- scopes[name] = scope.class_scope(klass)
- scopes[name].setvar("test", "value-#{name.sub(/.+::/,'')}")
- end
-
- assert_equal("value", scope.lookupvar("::test"), "did not look up qualified value correctly")
- tests.each do |input, output|
- assert_nothing_raised("Failed to scan #{input.inspect}") do
- assert_equal(output, scope.strinterp(input), 'did not parserret %s correctly' % input.inspect)
- end
- end
-
- logs = []
- Puppet::Util::Log.close
- Puppet::Util::Log.newdestination(logs)
-
- # #523
- %w{d f h l w z}.each do |l|
- string = "\\#{l}"
- assert_nothing_raised do
-
- assert_equal(
- string, scope.strinterp(string),
-
- 'did not parserret %s correctly' % string)
- end
-
-
- assert(
- logs.detect { |m| m.message =~ /Unrecognised escape/ },
-
- "Did not get warning about escape sequence with #{string}")
- logs.clear
end
end
@@ -563,13 +420,13 @@ describe Puppet::Parser::Scope do
it "should be able to unset normal variables" do
@scope.setvar("foo", "bar")
@scope.unsetvar("foo")
- @scope.lookupvar("foo").should == ""
+ @scope.lookupvar("foo").should == :undefined
end
it "should be able to unset ephemeral variables" do
@scope.setvar("0", "bar", :ephemeral => true)
@scope.unsetvar("0")
- @scope.lookupvar("0").should == ""
+ @scope.lookupvar("0").should == :undefined
end
it "should not unset ephemeral variables in previous ephemeral scope" do
diff --git a/spec/unit/parser/templatewrapper_spec.rb b/spec/unit/parser/templatewrapper_spec.rb
index afb0032fd..0c7199ba1 100755
--- a/spec/unit/parser/templatewrapper_spec.rb
+++ b/spec/unit/parser/templatewrapper_spec.rb
@@ -17,6 +17,12 @@ describe Puppet::Parser::TemplateWrapper do
@tw = Puppet::Parser::TemplateWrapper.new(@scope)
end
+ def mock_template(source=nil)
+ template_mock = mock("template", :result => "woot!")
+ ERB.expects(:new).with("template contents", 0, "-").returns(template_mock)
+ template_mock.expects(:filename=).with(source)
+ end
+
it "should create a new object TemplateWrapper from a scope" do
tw = Puppet::Parser::TemplateWrapper.new(@scope)
@@ -54,41 +60,38 @@ describe Puppet::Parser::TemplateWrapper do
end
it "should return the processed template contents with a call to result" do
- template_mock = mock("template", :result => "woot!")
+ mock_template("/tmp/fake_template")
File.expects(:read).with("/tmp/fake_template").returns("template contents")
- ERB.expects(:new).with("template contents", 0, "-").returns(template_mock)
@tw.file = @file
@tw.result.should eql("woot!")
end
it "should return the processed template contents with a call to result and a string" do
- template_mock = mock("template", :result => "woot!")
- ERB.expects(:new).with("template contents", 0, "-").returns(template_mock)
-
+ mock_template
@tw.result("template contents").should eql("woot!")
end
it "should return the contents of a variable if called via method_missing" do
- @scope.expects(:lookupvar).with("chicken", false).returns("is good")
+ @scope.expects(:lookupvar).with { |name,options| name == "chicken"}.returns("is good")
tw = Puppet::Parser::TemplateWrapper.new(@scope)
tw.chicken.should eql("is good")
end
it "should throw an exception if a variable is called via method_missing and it does not exist" do
- @scope.expects(:lookupvar).with("chicken", false).returns(:undefined)
+ @scope.expects(:lookupvar).with { |name,options| name == "chicken"}.returns(:undefined)
tw = Puppet::Parser::TemplateWrapper.new(@scope)
lambda { tw.chicken }.should raise_error(Puppet::ParseError)
end
it "should allow you to check whether a variable is defined with has_variable?" do
- @scope.expects(:lookupvar).with("chicken", false).returns("is good")
+ @scope.expects(:lookupvar).with { |name,options| name == "chicken"}.returns("is good")
tw = Puppet::Parser::TemplateWrapper.new(@scope)
tw.has_variable?("chicken").should eql(true)
end
it "should allow you to check whether a variable is not defined with has_variable?" do
- @scope.expects(:lookupvar).with("chicken", false).returns(:undefined)
+ @scope.expects(:lookupvar).with { |name,options| name == "chicken"}.returns(:undefined)
tw = Puppet::Parser::TemplateWrapper.new(@scope)
tw.has_variable?("chicken").should eql(false)
end
@@ -114,9 +117,7 @@ describe Puppet::Parser::TemplateWrapper do
end
it "should set all of the scope's variables as instance variables" do
- template_mock = mock("template", :result => "woot!")
- ERB.expects(:new).with("template contents", 0, "-").returns(template_mock)
-
+ mock_template
@scope.expects(:to_hash).returns("one" => "foo")
@tw.result("template contents")
@@ -124,8 +125,7 @@ describe Puppet::Parser::TemplateWrapper do
end
it "should not error out if one of the variables is a symbol" do
- template_mock = mock("template", :result => "woot!")
- ERB.expects(:new).with("template contents", 0, "-").returns(template_mock)
+ mock_template
@scope.expects(:to_hash).returns(:_timestamp => "1234")
@tw.result("template contents")
@@ -133,13 +133,11 @@ describe Puppet::Parser::TemplateWrapper do
%w{! . ; :}.each do |badchar|
it "should translate #{badchar} to _ when setting the instance variables" do
- template_mock = mock("template", :result => "woot!")
- ERB.expects(:new).with("template contents", 0, "-").returns(template_mock)
-
- @scope.expects(:to_hash).returns("one#{badchar}" => "foo")
- @tw.result("template contents")
+ mock_template
+ @scope.expects(:to_hash).returns("one#{badchar}" => "foo")
+ @tw.result("template contents")
- @tw.instance_variable_get("@one_").should == "foo"
- end
+ @tw.instance_variable_get("@one_").should == "foo"
+ end
end
end
diff --git a/spec/unit/resource/type_spec.rb b/spec/unit/resource/type_spec.rb
index b6a5f6982..45c880440 100755
--- a/spec/unit/resource/type_spec.rb
+++ b/spec/unit/resource/type_spec.rb
@@ -237,35 +237,6 @@ describe Puppet::Resource::Type do
end
end
- describe "when creating a subscope" do
- before do
- @scope = stub 'scope', :newscope => nil
- @resource = stub 'resource'
- @type = Puppet::Resource::Type.new(:hostclass, "foo")
- end
-
- it "should return a new scope created with the provided scope as the parent" do
- @scope.expects(:newscope).returns "foo"
- @type.subscope(@scope, @resource).should == "foo"
- end
-
- it "should set the source as itself" do
- @scope.expects(:newscope).with { |args| args[:source] == @type }
- @type.subscope(@scope, @resource)
- end
-
- it "should set the scope's namespace to its namespace" do
- @type.expects(:namespace).returns "yayness"
- @scope.expects(:newscope).with { |args| args[:namespace] == "yayness" }
- @type.subscope(@scope, @resource)
- end
-
- it "should set the scope's resource to the provided resource" do
- @scope.expects(:newscope).with { |args| args[:resource] == @resource }
- @type.subscope(@scope, @resource)
- end
- end
-
describe "when setting its parameters in the scope" do
before do
@scope = Puppet::Parser::Scope.new(:compiler => stub("compiler", :environment => Puppet::Node::Environment.new), :source => stub("source"))
@@ -465,7 +436,7 @@ describe Puppet::Resource::Type do
it "should set all of its parameters in a subscope" do
subscope = stub 'subscope', :compiler => @compiler
- @type.expects(:subscope).with(@scope, @resource).returns subscope
+ @scope.expects(:newscope).with(:source => @type, :dynamic => true, :namespace => 'foo', :resource => @resource).returns subscope
@type.expects(:set_resource_parameters).with(@resource, subscope)
@type.evaluate_code(@resource)
@@ -493,8 +464,9 @@ describe Puppet::Resource::Type do
it "should evaluate the AST code if any is provided" do
code = stub 'code'
@type.stubs(:code).returns code
- @type.stubs(:subscope).returns stub_everything("subscope", :compiler => @compiler)
- code.expects(:safeevaluate).with @type.subscope
+ subscope = stub_everything("subscope", :compiler => @compiler)
+ @scope.stubs(:newscope).returns subscope
+ code.expects(:safeevaluate).with subscope
@type.evaluate_code(@resource)
end
diff --git a/spec/unit/util/logging_spec.rb b/spec/unit/util/logging_spec.rb
index edc88f115..bc2eaff43 100755
--- a/spec/unit/util/logging_spec.rb
+++ b/spec/unit/util/logging_spec.rb
@@ -92,4 +92,29 @@ describe Puppet::Util::Logging do
end
end
end
+
+ describe "when sending a deprecation warning" do
+ before do
+ @logger.clear_deprecation_warnings
+ end
+
+ it "should the message with warn" do
+ @logger.expects(:warning).with('foo')
+ @logger.deprecation_warning 'foo'
+ end
+
+ it "should only log each unique message once" do
+ @logger.expects(:warning).with('foo').once
+ 5.times { @logger.deprecation_warning 'foo' }
+ end
+
+ it "should only log the first 100 messages" do
+ (1..100).each { |i|
+ @logger.expects(:warning).with(i).once
+ @logger.deprecation_warning i
+ }
+ @logger.expects(:warning).with(101).never
+ @logger.deprecation_warning 101
+ end
+ end
end
diff --git a/test/language/functions.rb b/test/language/functions.rb
index e882b68f3..84b1b3861 100755
--- a/test/language/functions.rb
+++ b/test/language/functions.rb
@@ -382,17 +382,15 @@ class TestLangFunctions < Test::Unit::TestCase
}.each do |string, value|
scope = mkscope
scope.setvar("yayness", string)
- assert_equal(string, scope.lookupvar("yayness", false))
+ assert_equal(string, scope.lookupvar("yayness"))
assert_nothing_raised("An empty string was not a valid variable value") do
ast.evaluate(scope)
end
-
- assert_equal(
- "template #{value}\n", scope.lookupvar("output"),
-
- "#{string.inspect} did not get evaluated correctly")
+ assert_equal(
+ "template #{value}\n", scope.lookupvar("output"),
+ "#{string.inspect} did not get evaluated correctly")
end
end
diff --git a/test/language/scope.rb b/test/language/scope.rb
index c4154dc27..ccc359651 100755
--- a/test/language/scope.rb
+++ b/test/language/scope.rb
@@ -42,22 +42,22 @@ class TestScope < Test::Unit::TestCase
# Set a variable in the top and make sure all three can get it
topscope.setvar("first", "topval")
scopes.each do |name, scope|
- assert_equal("topval", scope.lookupvar("first", false), "Could not find var in #{name}")
+ assert_equal("topval", scope.lookupvar("first"), "Could not find var in #{name}")
end
# Now set a var in the midscope and make sure the mid and bottom can see it but not the top
midscope.setvar("second", "midval")
- assert_equal(:undefined, scopes[:top].lookupvar("second", false), "Found child var in top scope")
+ assert_equal(:undefined, scopes[:top].lookupvar("second"), "Found child var in top scope")
[:mid, :bot].each do |name|
- assert_equal("midval", scopes[name].lookupvar("second", false), "Could not find var in #{name}")
+ assert_equal("midval", scopes[name].lookupvar("second"), "Could not find var in #{name}")
end
# And set something in the bottom, and make sure we only find it there.
botscope.setvar("third", "botval")
[:top, :mid].each do |name|
- assert_equal(:undefined, scopes[name].lookupvar("third", false), "Found child var in top scope")
+ assert_equal(:undefined, scopes[name].lookupvar("third"), "Found child var in top scope")
end
- assert_equal("botval", scopes[:bot].lookupvar("third", false), "Could not find var in bottom scope")
+ assert_equal("botval", scopes[:bot].lookupvar("third"), "Could not find var in bottom scope")
# Test that the scopes convert to hash structures correctly.
@@ -260,18 +260,7 @@ Host <<||>>"
scope = mkscope
scope.setvar("testing", :undef)
-
-
- assert_equal(
- :undef, scope.lookupvar("testing", false),
-
- "undef was not returned as :undef when not string")
-
-
- assert_equal(
- "", scope.lookupvar("testing", true),
-
- "undef was not returned as '' when string")
+ assert_equal(:undef, scope.lookupvar("testing"), "undef was not returned as :undef")
end
end