summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-09-27 21:30:49 +0200
committerLuke Kanies <luke@madstop.com>2008-09-27 21:30:49 +0200
commitb96bdc6a63f7be6b724c2aa7ad0ea007cba81718 (patch)
tree6d334ea12e1468b34160fa36da29dd7d78ac31ea /spec/unit/parser
parente20f02af4a93478c5b08b7681caa12cd72b4a3a6 (diff)
parent3749267093923692d6e7bc0c9ce83b43a487b19e (diff)
downloadpuppet-b96bdc6a63f7be6b724c2aa7ad0ea007cba81718.tar.gz
puppet-b96bdc6a63f7be6b724c2aa7ad0ea007cba81718.tar.xz
puppet-b96bdc6a63f7be6b724c2aa7ad0ea007cba81718.zip
Merge branch '0.24.x' of git://github.com/jamtur01/puppet into 0.24.x
Diffstat (limited to 'spec/unit/parser')
-rwxr-xr-xspec/unit/parser/ast/vardef.rb47
-rwxr-xr-xspec/unit/parser/collector.rb10
-rwxr-xr-xspec/unit/parser/lexer.rb3
-rwxr-xr-xspec/unit/parser/parser.rb34
-rwxr-xr-xspec/unit/parser/resource.rb10
-rwxr-xr-xspec/unit/parser/scope.rb37
6 files changed, 135 insertions, 6 deletions
diff --git a/spec/unit/parser/ast/vardef.rb b/spec/unit/parser/ast/vardef.rb
new file mode 100755
index 000000000..6bd355c89
--- /dev/null
+++ b/spec/unit/parser/ast/vardef.rb
@@ -0,0 +1,47 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe Puppet::Parser::AST::VarDef do
+ before :each do
+ @scope = Puppet::Parser::Scope.new()
+ end
+
+ describe "when evaluating" do
+
+ it "should evaluate arguments" do
+ name = mock 'name'
+ value = mock 'value'
+
+ 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.evaluate(@scope)
+ end
+
+ it "should be in append=false mode if called without append" do
+ name = stub 'name', :safeevaluate => "var"
+ value = stub 'value', :safeevaluate => "1"
+
+ @scope.expects(:setvar).with { |name,value,file,line,append| append == nil }
+
+ vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil,
+ :line => nil
+ vardef.evaluate(@scope)
+ end
+
+ it "should call scope in append mode if append is true" do
+ name = stub 'name', :safeevaluate => "var"
+ value = stub 'value', :safeevaluate => "1"
+
+ @scope.expects(:setvar).with { |name,value,file,line,append| append == true }
+
+ vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil,
+ :line => nil, :append => true
+ vardef.evaluate(@scope)
+ end
+
+ end
+end
diff --git a/spec/unit/parser/collector.rb b/spec/unit/parser/collector.rb
index 2dfae6786..ede583b96 100755
--- a/spec/unit/parser/collector.rb
+++ b/spec/unit/parser/collector.rb
@@ -234,16 +234,16 @@ describe Puppet::Parser::Collector, "when collecting exported resources" do
@collector.evaluate
end
- it "should return all matching resources from the current compile" do
+ it "should return all matching resources from the current compile and mark them non-virtual and non-exported" do
stub_rails(true)
one = stub 'one', :type => "Mytype", :virtual? => true, :exported? => true
two = stub 'two', :type => "Mytype", :virtual? => true, :exported? => true
- one.stubs(:exported=)
- one.stubs(:virtual=)
- two.stubs(:exported=)
- two.stubs(:virtual=)
+ one.expects(:exported=).with(false)
+ one.expects(:virtual=).with(false)
+ two.expects(:exported=).with(false)
+ two.expects(:virtual=).with(false)
@compiler.expects(:resources).returns([one, two])
diff --git a/spec/unit/parser/lexer.rb b/spec/unit/parser/lexer.rb
index fb666054d..fed1ade7d 100755
--- a/spec/unit/parser/lexer.rb
+++ b/spec/unit/parser/lexer.rb
@@ -135,7 +135,8 @@ describe Puppet::Parser::Lexer::TOKENS do
:QMARK => '?',
:BACKSLASH => '\\',
:FARROW => '=>',
- :PARROW => '+>'
+ :PARROW => '+>',
+ :APPENDS => '+='
}.each do |name, string|
it "should have a token named #{name.to_s}" do
Puppet::Parser::Lexer::TOKENS[name].should_not be_nil
diff --git a/spec/unit/parser/parser.rb b/spec/unit/parser/parser.rb
new file mode 100755
index 000000000..94b19be40
--- /dev/null
+++ b/spec/unit/parser/parser.rb
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe Puppet::Parser do
+
+ AST = Puppet::Parser::AST
+
+ before :each do
+ @parser = Puppet::Parser::Parser.new :environment => "development"
+ end
+
+ describe "when parsing append operator" do
+
+ it "should not raise syntax errors" do
+ lambda { @parser.parse("$var += something") }.should_not raise_error
+ end
+
+ it "shouldraise syntax error on incomplete syntax " 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")
+ end
+
+ it "should work with arrays too" do
+ AST::VarDef.expects(:new).with { |h| h[:append] == true }
+ @parser.parse("$var += ['test']")
+ end
+
+ end
+end
diff --git a/spec/unit/parser/resource.rb b/spec/unit/parser/resource.rb
index 6b2021916..63cfbc2ed 100755
--- a/spec/unit/parser/resource.rb
+++ b/spec/unit/parser/resource.rb
@@ -176,6 +176,16 @@ describe Puppet::Parser::Resource do
@resource["noop"].should == "false"
end
+ it "should copy all metaparams that it finds" do
+ @scope.setvar("require", "container")
+ @scope.setvar("notify", "container")
+
+ @resource.class.publicize_methods(:add_metaparams) { @resource.add_metaparams }
+
+ @resource["require"].should == "container"
+ @resource["notify"].should == "container"
+ end
+
it "should stack relationship metaparams from its container if it already has them" do
@resource.set_parameter("require", "resource")
@scope.setvar("require", "container")
diff --git a/spec/unit/parser/scope.rb b/spec/unit/parser/scope.rb
new file mode 100755
index 000000000..ec8ab6d7d
--- /dev/null
+++ b/spec/unit/parser/scope.rb
@@ -0,0 +1,37 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe Puppet::Parser::Scope do
+ before :each do
+ @scope = Puppet::Parser::Scope.new()
+ @topscope = Puppet::Parser::Scope.new()
+ @scope.stubs(:parent).returns(@topscope)
+ end
+
+ describe Puppet::Parser::Scope, "when setvar is called with append=true" do
+
+ it "should raise error if the variable is already defined in this scope" do
+ @scope.setvar("var","1",nil,nil,false)
+ lambda { @scope.setvar("var","1",nil,nil,true) }.should raise_error(Puppet::ParseError)
+ end
+
+ it "it should lookup current variable value" do
+ @scope.expects(:lookupvar).with("var").returns("2")
+ @scope.setvar("var","1",nil,nil,true)
+ end
+
+ it "it should store the concatenated string '42'" do
+ @topscope.setvar("var","4",nil,nil,false)
+ @scope.setvar("var","2",nil,nil,true)
+ @scope.lookupvar("var").should == "42"
+ end
+
+ it "it should store the concatenated array [4,2]" do
+ @topscope.setvar("var",[4],nil,nil,false)
+ @scope.setvar("var",[2],nil,nil,true)
+ @scope.lookupvar("var").should == [4,2]
+ end
+
+ end
+end