diff options
| author | Stig Sandbeck Mathisen <ssm@debian.org> | 2013-02-05 10:44:00 +0100 |
|---|---|---|
| committer | Stig Sandbeck Mathisen <ssm@debian.org> | 2013-02-05 10:44:00 +0100 |
| commit | 107e8d1a41d447403883a6f6faa1cc40fb904720 (patch) | |
| tree | aaaeca9cb6289b3db94a105e6cb1b1270292337c /spec/unit/parser | |
| parent | 7a3cd3a80c8d57462509c7e193dfcc11fc61a191 (diff) | |
| parent | 480379d1f61d88e732bd10d6773845a788351ed3 (diff) | |
| download | puppet-upstream/3.1.0.tar.gz | |
Imported Upstream version 3.1.0upstream/3.1.0
Diffstat (limited to 'spec/unit/parser')
| -rwxr-xr-x | spec/unit/parser/collector_spec.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/parser/functions/create_resources_spec.rb | 13 | ||||
| -rwxr-xr-x | spec/unit/parser/functions/extlookup_spec.rb | 8 | ||||
| -rw-r--r-- | spec/unit/parser/functions/hiera_array_spec.rb | 2 | ||||
| -rw-r--r-- | spec/unit/parser/functions/hiera_hash_spec.rb | 2 | ||||
| -rw-r--r-- | spec/unit/parser/functions/hiera_include_spec.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/parser/functions/hiera_spec.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/parser/functions/regsubst_spec.rb | 8 | ||||
| -rwxr-xr-x | spec/unit/parser/functions/split_spec.rb | 8 | ||||
| -rwxr-xr-x | spec/unit/parser/functions/sprintf_spec.rb | 4 | ||||
| -rwxr-xr-x | spec/unit/parser/functions/versioncmp_spec.rb | 8 | ||||
| -rwxr-xr-x | spec/unit/parser/functions_spec.rb | 52 | ||||
| -rwxr-xr-x | spec/unit/parser/type_loader_spec.rb | 3 |
13 files changed, 89 insertions, 25 deletions
diff --git a/spec/unit/parser/collector_spec.rb b/spec/unit/parser/collector_spec.rb index 32e7a1c15..132bddbc5 100755 --- a/spec/unit/parser/collector_spec.rb +++ b/spec/unit/parser/collector_spec.rb @@ -34,7 +34,7 @@ describe Puppet::Parser::Collector, "when initializing" do @collector.equery.should equal(@equery) end - it "should canonize the type name" do + it "should canonicalize the type name" do @collector = Puppet::Parser::Collector.new(@scope, "resource::type", @equery, @vquery, @form) @collector.type.should == "Resource::Type" end diff --git a/spec/unit/parser/functions/create_resources_spec.rb b/spec/unit/parser/functions/create_resources_spec.rb index a7a6e0074..b16f9111b 100755 --- a/spec/unit/parser/functions/create_resources_spec.rb +++ b/spec/unit/parser/functions/create_resources_spec.rb @@ -19,7 +19,7 @@ describe 'function for dynamically creating resources' do end it 'should require two or three arguments' do - expect { @scope.function_create_resources(['foo']) }.to raise_error(ArgumentError, 'create_resources(): wrong number of arguments (1; must be 2 or 3)') + expect { @scope.function_create_resources(['foo']) }.to raise_error(ArgumentError, 'create_resources(): Wrong number of arguments given (1 for minimum 2)') expect { @scope.function_create_resources(['foo', 'bar', 'blah', 'baz']) }.to raise_error(ArgumentError, 'create_resources(): wrong number of arguments (4; must be 2 or 3)') end @@ -50,6 +50,17 @@ describe 'function for dynamically creating resources' do catalog.resource(:file, "/etc/foo")['ensure'].should == 'present' end + it 'should be able to add virtual resources' do + catalog = compile_to_catalog("create_resources('@file', {'/etc/foo'=>{'ensure'=>'present'}})\nrealize(File['/etc/foo'])") + catalog.resource(:file, "/etc/foo")['ensure'].should == 'present' + end + + it 'should be able to add exported resources' do + catalog = compile_to_catalog("create_resources('@@file', {'/etc/foo'=>{'ensure'=>'present'}})") + catalog.resource(:file, "/etc/foo")['ensure'].should == 'present' + catalog.resource(:file, "/etc/foo").exported.should == true + end + it 'should accept multiple types' do catalog = compile_to_catalog("create_resources('notify', {'foo'=>{'message'=>'one'}, 'bar'=>{'message'=>'two'}})") catalog.resource(:notify, "foo")['message'].should == 'one' diff --git a/spec/unit/parser/functions/extlookup_spec.rb b/spec/unit/parser/functions/extlookup_spec.rb index 4bc2702b7..fae32fa97 100755 --- a/spec/unit/parser/functions/extlookup_spec.rb +++ b/spec/unit/parser/functions/extlookup_spec.rb @@ -19,12 +19,12 @@ describe "the extlookup function" do Puppet::Parser::Functions.function("extlookup").should == "function_extlookup" end - it "should raise a ParseError if there is less than 1 arguments" do - lambda { @scope.function_extlookup([]) }.should( raise_error(Puppet::ParseError)) + it "should raise a ArgumentError if there is less than 1 arguments" do + lambda { @scope.function_extlookup([]) }.should( raise_error(ArgumentError)) end - it "should raise a ParseError if there is more than 3 arguments" do - lambda { @scope.function_extlookup(["foo", "bar", "baz", "gazonk"]) }.should( raise_error(Puppet::ParseError)) + it "should raise a ArgumentError if there is more than 3 arguments" do + lambda { @scope.function_extlookup(["foo", "bar", "baz", "gazonk"]) }.should( raise_error(ArgumentError)) end it "should return the default" do diff --git a/spec/unit/parser/functions/hiera_array_spec.rb b/spec/unit/parser/functions/hiera_array_spec.rb index d9e25cef0..e8efb727f 100644 --- a/spec/unit/parser/functions/hiera_array_spec.rb +++ b/spec/unit/parser/functions/hiera_array_spec.rb @@ -8,7 +8,7 @@ describe 'Puppet::Parser::Functions#hiera_array' do let :scope do Puppet::Parser::Scope.new_for_test_harness('foo') end it 'should require a key argument' do - expect { scope.function_hiera_array([]) }.to raise_error(Puppet::ParseError) + expect { scope.function_hiera_array([]) }.to raise_error(ArgumentError) end it 'should raise a useful error when nil is returned' do diff --git a/spec/unit/parser/functions/hiera_hash_spec.rb b/spec/unit/parser/functions/hiera_hash_spec.rb index c7c9d4432..a345a6c7f 100644 --- a/spec/unit/parser/functions/hiera_hash_spec.rb +++ b/spec/unit/parser/functions/hiera_hash_spec.rb @@ -4,7 +4,7 @@ describe 'Puppet::Parser::Functions#hiera_hash' do let :scope do Puppet::Parser::Scope.new_for_test_harness('foo') end it 'should require a key argument' do - expect { scope.function_hiera_hash([]) }.to raise_error(Puppet::ParseError) + expect { scope.function_hiera_hash([]) }.to raise_error(ArgumentError) end it 'should raise a useful error when nil is returned' do diff --git a/spec/unit/parser/functions/hiera_include_spec.rb b/spec/unit/parser/functions/hiera_include_spec.rb index 3fd7b7740..f06d8c69c 100644 --- a/spec/unit/parser/functions/hiera_include_spec.rb +++ b/spec/unit/parser/functions/hiera_include_spec.rb @@ -10,7 +10,7 @@ describe 'Puppet::Parser::Functions#hiera_include' do end it 'should require a key argument' do - expect { scope.function_hiera_include([]) }.to raise_error(Puppet::ParseError) + expect { scope.function_hiera_include([]) }.to raise_error(ArgumentError) end it 'should raise a useful error when nil is returned' do diff --git a/spec/unit/parser/functions/hiera_spec.rb b/spec/unit/parser/functions/hiera_spec.rb index 657d4f6fb..0abcb1b28 100755 --- a/spec/unit/parser/functions/hiera_spec.rb +++ b/spec/unit/parser/functions/hiera_spec.rb @@ -6,7 +6,7 @@ describe 'Puppet::Parser::Functions#hiera' do let :scope do Puppet::Parser::Scope.new_for_test_harness('foo') end it 'should require a key argument' do - expect { scope.function_hiera([]) }.to raise_error(Puppet::ParseError) + expect { scope.function_hiera([]) }.to raise_error(ArgumentError) end it 'should raise a useful error when nil is returned' do diff --git a/spec/unit/parser/functions/regsubst_spec.rb b/spec/unit/parser/functions/regsubst_spec.rb index 439c16270..c75b16c0e 100755 --- a/spec/unit/parser/functions/regsubst_spec.rb +++ b/spec/unit/parser/functions/regsubst_spec.rb @@ -16,12 +16,12 @@ describe "the regsubst function" do Puppet::Parser::Functions.function("regsubst").should == "function_regsubst" end - it "should raise a ParseError if there is less than 3 arguments" do - lambda { @scope.function_regsubst(["foo", "bar"]) }.should( raise_error(Puppet::ParseError)) + it "should raise a ArgumentError if there is less than 3 arguments" do + lambda { @scope.function_regsubst(["foo", "bar"]) }.should( raise_error(ArgumentError)) end - it "should raise a ParseError if there is more than 5 arguments" do - lambda { @scope.function_regsubst(["foo", "bar", "gazonk", "del", "x", "y"]) }.should( raise_error(Puppet::ParseError)) + it "should raise a ArgumentError if there is more than 5 arguments" do + lambda { @scope.function_regsubst(["foo", "bar", "gazonk", "del", "x", "y"]) }.should( raise_error(ArgumentError)) end diff --git a/spec/unit/parser/functions/split_spec.rb b/spec/unit/parser/functions/split_spec.rb index 20a6f4204..5ddbe8d44 100755 --- a/spec/unit/parser/functions/split_spec.rb +++ b/spec/unit/parser/functions/split_spec.rb @@ -16,12 +16,12 @@ describe "the split function" do Puppet::Parser::Functions.function("split").should == "function_split" end - it "should raise a ParseError if there is less than 2 arguments" do - lambda { @scope.function_split(["foo"]) }.should( raise_error(Puppet::ParseError)) + it "should raise a ArgumentError if there is less than 2 arguments" do + lambda { @scope.function_split(["foo"]) }.should( raise_error(ArgumentError)) end - it "should raise a ParseError if there is more than 2 arguments" do - lambda { @scope.function_split(["foo", "bar", "gazonk"]) }.should( raise_error(Puppet::ParseError)) + it "should raise a ArgumentError if there is more than 2 arguments" do + lambda { @scope.function_split(["foo", "bar", "gazonk"]) }.should( raise_error(ArgumentError)) end it "should raise a RegexpError if the regexp is malformed" do diff --git a/spec/unit/parser/functions/sprintf_spec.rb b/spec/unit/parser/functions/sprintf_spec.rb index e1d738e66..36c0ae1b7 100755 --- a/spec/unit/parser/functions/sprintf_spec.rb +++ b/spec/unit/parser/functions/sprintf_spec.rb @@ -16,8 +16,8 @@ describe "the sprintf function" do Puppet::Parser::Functions.function("sprintf").should == "function_sprintf" end - it "should raise a ParseError if there is less than 1 argument" do - lambda { @scope.function_sprintf([]) }.should( raise_error(Puppet::ParseError)) + it "should raise a ArgumentError if there is less than 1 argument" do + lambda { @scope.function_sprintf([]) }.should( raise_error(ArgumentError)) end it "should format integers" do diff --git a/spec/unit/parser/functions/versioncmp_spec.rb b/spec/unit/parser/functions/versioncmp_spec.rb index 5a6668678..760a286c5 100755 --- a/spec/unit/parser/functions/versioncmp_spec.rb +++ b/spec/unit/parser/functions/versioncmp_spec.rb @@ -16,12 +16,12 @@ describe "the versioncmp function" do Puppet::Parser::Functions.function("versioncmp").should == "function_versioncmp" end - it "should raise a ParseError if there is less than 2 arguments" do - lambda { @scope.function_versioncmp(["1.2"]) }.should raise_error(Puppet::ParseError) + it "should raise a ArgumentError if there is less than 2 arguments" do + lambda { @scope.function_versioncmp(["1.2"]) }.should raise_error(ArgumentError) end - it "should raise a ParseError if there is more than 2 arguments" do - lambda { @scope.function_versioncmp(["1.2", "2.4.5", "3.5.6"]) }.should raise_error(Puppet::ParseError) + it "should raise a ArgumentError if there is more than 2 arguments" do + lambda { @scope.function_versioncmp(["1.2", "2.4.5", "3.5.6"]) }.should raise_error(ArgumentError) end it "should call Puppet::Util::Package.versioncmp (included in scope)" do diff --git a/spec/unit/parser/functions_spec.rb b/spec/unit/parser/functions_spec.rb index ef50447da..1430ff26f 100755 --- a/spec/unit/parser/functions_spec.rb +++ b/spec/unit/parser/functions_spec.rb @@ -39,7 +39,7 @@ describe Puppet::Parser::Functions do end end - describe "when calling function to test function existance" do + describe "when calling function to test function existence" do before do @module = Module.new Puppet::Parser::Functions.stubs(:environment_module).returns @module @@ -64,6 +64,56 @@ describe Puppet::Parser::Functions do end end + describe "when calling function to test arity" do + before :each do + Puppet::Node::Environment.stubs(:current).returns(nil) + @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foo")) + @scope = Puppet::Parser::Scope.new(@compiler) + end + + it "should raise an error if the function is called with too many arguments" do + Puppet::Parser::Functions.newfunction("name", :arity => 2) { |args| } + lambda { @scope.function_name([1,2,3]) }.should raise_error ArgumentError + end + + it "should raise an error if the function is called with too few arguments" do + Puppet::Parser::Functions.newfunction("name", :arity => 2) { |args| } + lambda { @scope.function_name([1]) }.should raise_error ArgumentError + end + + it "should not raise an error if the function is called with correct number of arguments" do + Puppet::Parser::Functions.newfunction("name", :arity => 2) { |args| } + lambda { @scope.function_name([1,2]) }.should_not raise_error ArgumentError + end + + it "should raise an error if the variable arg function is called with too few arguments" do + Puppet::Parser::Functions.newfunction("name", :arity => -3) { |args| } + lambda { @scope.function_name([1]) }.should raise_error ArgumentError + end + + it "should not raise an error if the variable arg function is called with correct number of arguments" do + Puppet::Parser::Functions.newfunction("name", :arity => -3) { |args| } + lambda { @scope.function_name([1,2]) }.should_not raise_error ArgumentError + end + + it "should not raise an error if the variable arg function is called with more number of arguments" do + Puppet::Parser::Functions.newfunction("name", :arity => -3) { |args| } + lambda { @scope.function_name([1,2,3]) }.should_not raise_error ArgumentError + end + end + + describe "::arity" do + it "returns the given arity of a function" do + Puppet::Parser::Functions.newfunction("name", :arity => 4) { |args| } + Puppet::Parser::Functions.arity(:name).should == 4 + end + + it "returns -1 if no arity is given" do + Puppet::Parser::Functions.newfunction("name") { |args| } + Puppet::Parser::Functions.arity(:name).should == -1 + end + end + describe "::get_function" do it "can retrieve a function defined on the *root* environment" do Thread.current[:environment] = nil diff --git a/spec/unit/parser/type_loader_spec.rb b/spec/unit/parser/type_loader_spec.rb index 918770c71..e15c05fea 100755 --- a/spec/unit/parser/type_loader_spec.rb +++ b/spec/unit/parser/type_loader_spec.rb @@ -11,6 +11,7 @@ describe Puppet::Parser::TypeLoader do before do @loader = Puppet::Parser::TypeLoader.new(:myenv) + Puppet.expects(:deprecation_warning).never end it "should support an environment" do @@ -146,6 +147,8 @@ describe Puppet::Parser::TypeLoader do end it "should load all ruby manifests from all modules in the specified environment" do + Puppet.expects(:deprecation_warning).at_least(1) + @module1 = mk_module(@modulebase1, "one") @module2 = mk_module(@modulebase2, "two") |
