diff --git a/spec/unit/parser/functions/fail_spec.rb b/spec/unit/parser/functions/fail_spec.rb new file mode 100755 index 000000000..bd685ae7a --- /dev/null +++ b/spec/unit/parser/functions/fail_spec.rb @@ -0,0 +1,26 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the 'fail' parser function" do + before :all do + Puppet::Parser::Functions.autoloader.loadall + end + + let :scope do + scope = Puppet::Parser::Scope.new + scope.stubs(:environment).returns(nil) + scope + end + + it "should exist" do + Puppet::Parser::Functions.function(:fail).should == "function_fail" + end + + it "should raise a parse error if invoked" do + expect { scope.function_fail([]) }.to raise_error Puppet::ParseError + end + + it "should join arguments into a string in the error" do + expect { scope.function_fail(["hello", "world"]) }.to raise_error /hello world/ + end +end diff --git a/spec/unit/parser/functions/file_spec.rb b/spec/unit/parser/functions/file_spec.rb new file mode 100755 index 000000000..901b75019 --- /dev/null +++ b/spec/unit/parser/functions/file_spec.rb @@ -0,0 +1,51 @@ +#!/usr/bin/env rspec +require 'spec_helper' +require 'puppet_spec/files' + +describe "the 'file' function" do + include PuppetSpec::Files + + before :all do + Puppet::Parser::Functions.autoloader.loadall + end + + let :scope do Puppet::Parser::Scope.new end + + it "should exist" do + Puppet::Parser::Functions.function("file").should == "function_file" + end + + def with_file_content(content) + path = tmpfile('file-function') + file = File.new(path, 'w') + file.sync = true + file.print content + yield path + end + + it "should read a file" do + with_file_content('file content') do |name| + scope.function_file([name]).should == "file content" + end + end + + it "should return the first file if given two files" do + with_file_content('one') do |one| + with_file_content('two') do |two| + scope.function_file([one, two]).should == "one" + end + end + end + + it "should not fail when some files are absent" do + expect { + with_file_content('one') do |one| + scope.function_file(["/this-should-not-exist", one]).should == 'one' + end + }.should_not raise_error + end + + it "should fail when all files are absent" do + expect { scope.function_file(['one']) }.to raise_error Puppet::ParseError + end +end diff --git a/spec/unit/parser/functions/generate_spec.rb b/spec/unit/parser/functions/generate_spec.rb index e50805393..42cf988ff 100755 --- a/spec/unit/parser/functions/generate_spec.rb +++ b/spec/unit/parser/functions/generate_spec.rb @@ -1,85 +1,122 @@ #!/usr/bin/env rspec require 'spec_helper' describe "the generate function" do + include PuppetSpec::Files + before :all do Puppet::Parser::Functions.autoloader.loadall end let(:scope) { Puppet::Parser::Scope.new } it "should exist" do Puppet::Parser::Functions.function("generate").should == "function_generate" end - it " accept a fully-qualified path as a command" do + it "accept a fully-qualified path as a command" do command = File.expand_path('/command/foo') Dir.expects(:chdir).with(File.dirname(command)).returns("yay") scope.function_generate([command]).should == "yay" end it "should not accept a relative path as a command" do lambda { scope.function_generate(["command"]) }.should raise_error(Puppet::ParseError) end it "should not accept a command containing illegal characters" do lambda { scope.function_generate([File.expand_path('/##/command')]) }.should raise_error(Puppet::ParseError) end it "should not accept a command containing spaces" do lambda { scope.function_generate([File.expand_path('/com mand')]) }.should raise_error(Puppet::ParseError) end it "should not accept a command containing '..'" do command = File.expand_path("/command/../") lambda { scope.function_generate([command]) }.should raise_error(Puppet::ParseError) end it "should execute the generate script with the correct working directory" do command = File.expand_path("/command") Dir.expects(:chdir).with(File.dirname(command)).returns("yay") scope.function_generate([command]).should == 'yay' end describe "on Windows" do before :each do Puppet.features.stubs(:microsoft_windows?).returns(true) end it "should accept lower-case drive letters" do command = 'd:/command/foo' Dir.expects(:chdir).with(File.dirname(command)).returns("yay") scope.function_generate([command]).should == 'yay' end it "should accept upper-case drive letters" do command = 'D:/command/foo' Dir.expects(:chdir).with(File.dirname(command)).returns("yay") scope.function_generate([command]).should == 'yay' end it "should accept forward and backslashes in the path" do command = 'D:\command/foo\bar' Dir.expects(:chdir).with(File.dirname(command)).returns("yay") scope.function_generate([command]).should == 'yay' end it "should reject colons when not part of the drive letter" do lambda { scope.function_generate(['C:/com:mand']) }.should raise_error(Puppet::ParseError) end it "should reject root drives" do lambda { scope.function_generate(['C:/']) }.should raise_error(Puppet::ParseError) end end describe "on non-Windows" do before :each do Puppet.features.stubs(:microsoft_windows?).returns(false) end it "should reject backslashes" do lambda { scope.function_generate(['/com\\mand']) }.should raise_error(Puppet::ParseError) end end + + let :command do + cmd = tmpfile('function_generate') + + if Puppet.features.microsoft_windows? + cmd += '.bat' + text = '@echo off' + "\n" + 'echo a-%1 b-%2' + else + text = '#!/bin/sh' + "\n" + 'echo a-$1 b-$2' + end + + File.open(cmd, 'w') {|fh| fh.puts text } + File.chmod 0700, cmd + cmd + end + + it "should call generator with no arguments" do + scope.function_generate([command]).should == "a- b-\n" + end + + it "should call generator with one argument" do + scope.function_generate([command, 'one']).should == "a-one b-\n" + end + + it "should call generator with wo arguments" do + scope.function_generate([command, 'one', 'two']).should == "a-one b-two\n" + end + + it "should fail if generator is not absolute" do + expect { scope.function_generate(['boo']) }.to raise_error Puppet::ParseError + end + + it "should fail if generator fails" do + expect { scope.function_generate(['/boo']) }.to raise_error Puppet::ParseError + end end diff --git a/spec/unit/parser/functions/include_spec.rb b/spec/unit/parser/functions/include_spec.rb index 15206cd7c..5f86049a8 100755 --- a/spec/unit/parser/functions/include_spec.rb +++ b/spec/unit/parser/functions/include_spec.rb @@ -1,35 +1,40 @@ #!/usr/bin/env rspec require 'spec_helper' describe "the 'include' function" do before :all do Puppet::Parser::Functions.autoloader.loadall end before :each do Puppet::Node::Environment.stubs(:current).returns(nil) @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foo")) @scope = Puppet::Parser::Scope.new(:compiler => @compiler) end it "should exist" do Puppet::Parser::Functions.function("include").should == "function_include" end it "should include a single class" do inc = "foo" @compiler.expects(:evaluate_classes).with {|klasses,parser,lazy| klasses == [inc]}.returns([inc]) @scope.function_include("foo") end it "should include multiple classes" do inc = ["foo","bar"] @compiler.expects(:evaluate_classes).with {|klasses,parser,lazy| klasses == inc}.returns(inc) @scope.function_include(["foo","bar"]) end it "should not lazily evaluate the included class" do @compiler.expects(:evaluate_classes).with {|klasses,parser,lazy| lazy == false}.returns("foo") @scope.function_include("foo") end + + it "should raise if the class is not found" do + @scope.stubs(:source).returns(true) + expect { @scope.function_include("nosuchclass") }.to raise_error Puppet::Error + end end diff --git a/spec/unit/parser/functions/search_spec.rb b/spec/unit/parser/functions/search_spec.rb new file mode 100755 index 000000000..fefb71425 --- /dev/null +++ b/spec/unit/parser/functions/search_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the 'search' function" do + before :all do + Puppet::Parser::Functions.autoloader.loadall + end + + let :scope do Puppet::Parser::Scope.new end + + it "should exist" do + Puppet::Parser::Functions.function("search").should == "function_search" + end + + it "should invoke #add_namespace on the scope for all inputs" do + scope.expects(:add_namespace).with("where") + scope.expects(:add_namespace).with("what") + scope.expects(:add_namespace).with("who") + scope.function_search(["where", "what", "who"]) + end +end diff --git a/spec/unit/parser/functions/template_spec.rb b/spec/unit/parser/functions/template_spec.rb index 07d42dac6..0c8ebbd00 100755 --- a/spec/unit/parser/functions/template_spec.rb +++ b/spec/unit/parser/functions/template_spec.rb @@ -1,62 +1,97 @@ #!/usr/bin/env rspec require 'spec_helper' describe "the template function" do before :all do Puppet::Parser::Functions.autoloader.loadall end let :scope do Puppet::Parser::Scope.new end it "should exist" do Puppet::Parser::Functions.function("template").should == "function_template" end it "should create a TemplateWrapper when called" do tw = stub_everything 'template_wrapper' Puppet::Parser::TemplateWrapper.expects(:new).returns(tw) scope.function_template(["test"]) end it "should give the template filename to the TemplateWrapper" do tw = stub_everything 'template_wrapper' Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw) tw.expects(:file=).with("test") scope.function_template(["test"]) end it "should return what TemplateWrapper.result returns" do tw = stub_everything 'template_wrapper' Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw) tw.stubs(:file=).with("test") tw.expects(:result).returns("template contents evaluated") scope.function_template(["test"]).should == "template contents evaluated" end it "should concatenate template wrapper outputs for multiple templates" do tw1 = stub_everything "template_wrapper1" tw2 = stub_everything "template_wrapper2" Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw1,tw2) tw1.stubs(:file=).with("1") tw2.stubs(:file=).with("2") tw1.stubs(:result).returns("result1") tw2.stubs(:result).returns("result2") scope.function_template(["1","2"]).should == "result1result2" end it "should raise an error if the template raises an error" do tw = stub_everything 'template_wrapper' Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw) tw.stubs(:result).raises expect { scope.function_template(["1"]) }.should raise_error(Puppet::ParseError) end + 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 + + it "should handle legacy template variable access correctly" do + expect { eval_template("template <%= deprecated %>") }. + to raise_error Puppet::ParseError + end + + it "should get values from the scope correctly" do + scope["deprecated"] = "deprecated value" + eval_template("template <%= deprecated %>").should == "template deprecated value" + end + + it "should handle kernel shadows without raising" do + expect { eval_template("<%= binding %>") }.should_not raise_error + end + + it "should not see scopes" do + scope['myvar'] = 'this is yayness' + expect { eval_template("<%= lookupvar('myvar') %>") }. + to raise_error Puppet::ParseError + end + + { "" => "", false => "false", true => "true" }.each do |input, output| + it "should support defined variables (#{input.inspect} => #{output.inspect})" do + scope['yayness'] = input + expect { + eval_template("<%= @yayness %>").should == output + }.should_not raise_error + end + end end diff --git a/spec/unit/parser/parser_spec.rb b/spec/unit/parser/parser_spec.rb index 805e287af..ad232d26a 100755 --- a/spec/unit/parser/parser_spec.rb +++ b/spec/unit/parser/parser_spec.rb @@ -1,452 +1,520 @@ #!/usr/bin/env rspec require 'spec_helper' describe Puppet::Parser do Puppet::Parser::AST before :each do @known_resource_types = Puppet::Resource::TypeCollection.new("development") @parser = Puppet::Parser::Parser.new "development" @parser.stubs(:known_resource_types).returns @known_resource_types @true_ast = Puppet::Parser::AST::Boolean.new :value => true end it "should require an environment at initialization" do - lambda { Puppet::Parser::Parser.new }.should raise_error(ArgumentError) + expect { Puppet::Parser::Parser.new }.should raise_error(ArgumentError) end it "should set the environment" do env = Puppet::Node::Environment.new Puppet::Parser::Parser.new(env).environment.should == env end it "should convert the environment into an environment instance if a string is provided" do env = Puppet::Node::Environment.new("testing") Puppet::Parser::Parser.new("testing").environment.should == env end it "should be able to look up the environment-specific resource type collection" do rtc = Puppet::Node::Environment.new("development").known_resource_types parser = Puppet::Parser::Parser.new "development" parser.known_resource_types.should equal(rtc) end - it "should delegate importing to the known resource type loader" do - parser = Puppet::Parser::Parser.new "development" - parser.known_resource_types.loader.expects(:import).with("newfile", "current_file") - parser.lexer.expects(:file).returns "current_file" - parser.import("newfile") + context "when importing" do + it "should delegate importing to the known resource type loader" do + parser = Puppet::Parser::Parser.new "development" + parser.known_resource_types.loader.expects(:import).with("newfile", "current_file") + parser.lexer.expects(:file).returns "current_file" + parser.import("newfile") + end + + it "should import multiple files on one line" do + @parser.known_resource_types.loader.expects(:import).with('one', nil) + @parser.known_resource_types.loader.expects(:import).with('two', nil) + @parser.parse("import 'one', 'two'") + end end describe "when parsing files" do before do FileTest.stubs(:exist?).returns true File.stubs(:read).returns "" @parser.stubs(:watch_file) end it "should treat files ending in 'rb' as ruby files" do @parser.expects(:parse_ruby_file) @parser.file = "/my/file.rb" @parser.parse end end describe "when parsing append operator" do it "should not raise syntax errors" do - lambda { @parser.parse("$var += something") }.should_not raise_error + expect { @parser.parse("$var += something") }.should_not raise_error end it "shouldraise syntax error on incomplete syntax " do - lambda { @parser.parse("$var += ") }.should raise_error + expect { @parser.parse("$var += ") }.should raise_error end it "should create ast::VarDef with append=true" do vardef = @parser.parse("$var += 2").code[0] vardef.should be_a(Puppet::Parser::AST::VarDef) vardef.append.should == true end it "should work with arrays too" do vardef = @parser.parse("$var += ['test']").code[0] vardef.should be_a(Puppet::Parser::AST::VarDef) vardef.append.should == true end end describe "when parsing selector" do it "should support hash access on the left hand side" do - lambda { @parser.parse("$h = { 'a' => 'b' } $a = $h['a'] ? { 'b' => 'd', default => undef }") }.should_not raise_error + expect { @parser.parse("$h = { 'a' => 'b' } $a = $h['a'] ? { 'b' => 'd', default => undef }") }.should_not raise_error end end describe "parsing 'unless'" do it "should create the correct ast objects" do Puppet::Parser::AST::Not.expects(:new).with { |h| h[:value].is_a?(Puppet::Parser::AST::Boolean) } @parser.parse("unless false { $var = 1 }") end it "should not raise an error with empty statements" do - lambda { @parser.parse("unless false { }") }.should_not raise_error + expect { @parser.parse("unless false { }") }.should_not raise_error end #test for bug #13296 it "should not override 'unless' as a parameter inside resources" do lambda { @parser.parse("exec {'/bin/echo foo': unless => '/usr/bin/false',}") }.should_not raise_error end end describe "when parsing parameter names" do Puppet::Parser::Lexer::KEYWORDS.sort_tokens.each do |keyword| it "should allow #{keyword} as a keyword" do lambda { @parser.parse("exec {'/bin/echo foo': #{keyword} => '/usr/bin/false',}") }.should_not raise_error end end end describe "when parsing 'if'" do it "not, it should create the correct ast objects" do Puppet::Parser::AST::Not.expects(:new).with { |h| h[:value].is_a?(Puppet::Parser::AST::Boolean) } @parser.parse("if ! true { $var = 1 }") end it "boolean operation, it should create the correct ast objects" do Puppet::Parser::AST::BooleanOperator.expects(:new).with { |h| h[:rval].is_a?(Puppet::Parser::AST::Boolean) and h[:lval].is_a?(Puppet::Parser::AST::Boolean) and h[:operator]=="or" } @parser.parse("if true or true { $var = 1 }") end it "comparison operation, it should create the correct ast objects" do Puppet::Parser::AST::ComparisonOperator.expects(:new).with { |h| h[:lval].is_a?(Puppet::Parser::AST::Name) and h[:rval].is_a?(Puppet::Parser::AST::Name) and h[:operator]=="<" } @parser.parse("if 1 < 2 { $var = 1 }") end end describe "when parsing if complex expressions" do it "should create a correct ast tree" do aststub = stub_everything 'ast' Puppet::Parser::AST::ComparisonOperator.expects(:new).with { |h| h[:rval].is_a?(Puppet::Parser::AST::Name) and h[:lval].is_a?(Puppet::Parser::AST::Name) and h[:operator]==">" }.returns(aststub) Puppet::Parser::AST::ComparisonOperator.expects(:new).with { |h| h[:rval].is_a?(Puppet::Parser::AST::Name) and h[:lval].is_a?(Puppet::Parser::AST::Name) and h[:operator]=="==" }.returns(aststub) Puppet::Parser::AST::BooleanOperator.expects(:new).with { |h| h[:rval]==aststub and h[:lval]==aststub and h[:operator]=="and" } @parser.parse("if (1 > 2) and (1 == 2) { $var = 1 }") end it "should raise an error on incorrect expression" do - lambda { @parser.parse("if (1 > 2 > ) or (1 == 2) { $var = 1 }") }.should raise_error + expect { @parser.parse("if (1 > 2 > ) or (1 == 2) { $var = 1 }") }.should raise_error end end describe "when parsing resource references" do it "should not raise syntax errors" do - lambda { @parser.parse('exec { test: param => File["a"] }') }.should_not raise_error + expect { @parser.parse('exec { test: param => File["a"] }') }.should_not raise_error end it "should not raise syntax errors with multiple references" do - lambda { @parser.parse('exec { test: param => File["a","b"] }') }.should_not raise_error + expect { @parser.parse('exec { test: param => File["a","b"] }') }.should_not raise_error end it "should create an ast::ResourceReference" do Puppet::Parser::AST::ResourceReference.expects(:new).with { |arg| arg[:line]==1 and arg[:type]=="File" and arg[:title].is_a?(Puppet::Parser::AST::ASTArray) } @parser.parse('exec { test: command => File["a","b"] }') end end describe "when parsing resource overrides" do it "should not raise syntax errors" do - lambda { @parser.parse('Resource["title"] { param => value }') }.should_not raise_error + expect { @parser.parse('Resource["title"] { param => value }') }.should_not raise_error end it "should not raise syntax errors with multiple overrides" do - lambda { @parser.parse('Resource["title1","title2"] { param => value }') }.should_not raise_error + expect { @parser.parse('Resource["title1","title2"] { param => value }') }.should_not raise_error end it "should create an ast::ResourceOverride" do #Puppet::Parser::AST::ResourceOverride.expects(:new).with { |arg| # arg[:line]==1 and arg[:object].is_a?(Puppet::Parser::AST::ResourceReference) and arg[:parameters].is_a?(Puppet::Parser::AST::ResourceParam) #} ro = @parser.parse('Resource["title1","title2"] { param => value }').code[0] ro.should be_a(Puppet::Parser::AST::ResourceOverride) ro.line.should == 1 ro.object.should be_a(Puppet::Parser::AST::ResourceReference) ro.parameters[0].should be_a(Puppet::Parser::AST::ResourceParam) end end describe "when parsing if statements" do it "should not raise errors with empty if" do - lambda { @parser.parse("if true { }") }.should_not raise_error + expect { @parser.parse("if true { }") }.should_not raise_error end it "should not raise errors with empty else" do - lambda { @parser.parse("if false { notice('if') } else { }") }.should_not raise_error + expect { @parser.parse("if false { notice('if') } else { }") }.should_not raise_error end it "should not raise errors with empty if and else" do - lambda { @parser.parse("if false { } else { }") }.should_not raise_error + expect { @parser.parse("if false { } else { }") }.should_not raise_error end it "should create a nop node for empty branch" do Puppet::Parser::AST::Nop.expects(:new) @parser.parse("if true { }") end it "should create a nop node for empty else branch" do Puppet::Parser::AST::Nop.expects(:new) @parser.parse("if true { notice('test') } else { }") end it "should build a chain of 'ifs' if there's an 'elsif'" do - lambda { @parser.parse(<<-PP) }.should_not raise_error + expect { @parser.parse(<<-PP) }.should_not raise_error if true { notice('test') } elsif true {} else { } PP end end describe "when parsing function calls" do - it "should not raise errors with no arguments" do - lambda { @parser.parse("tag()") }.should_not raise_error + expect { @parser.parse("tag()") }.should_not raise_error end it "should not raise errors with rvalue function with no args" do - lambda { @parser.parse("$a = template()") }.should_not raise_error + expect { @parser.parse("$a = template()") }.should_not raise_error end it "should not raise errors with arguments" do - lambda { @parser.parse("notice(1)") }.should_not raise_error + expect { @parser.parse("notice(1)") }.should_not raise_error end it "should not raise errors with multiple arguments" do - lambda { @parser.parse("notice(1,2)") }.should_not raise_error + expect { @parser.parse("notice(1,2)") }.should_not raise_error end it "should not raise errors with multiple arguments and a trailing comma" do - lambda { @parser.parse("notice(1,2,)") }.should_not raise_error + expect { @parser.parse("notice(1,2,)") }.should_not raise_error end end - describe "when parsing arrays with trailing comma" do + describe "when parsing arrays" do + it "should parse an array" do + expect { @parser.parse("$a = [1,2]") }.should_not raise_error + end it "should not raise errors with a trailing comma" do - lambda { @parser.parse("$a = [1,2,]") }.should_not raise_error + expect { @parser.parse("$a = [1,2,]") }.should_not raise_error + end + + it "should accept an empty array" do + expect { @parser.parse("$var = []\n") }.should_not raise_error end end describe "when providing AST context" do before do @lexer = stub 'lexer', :line => 50, :file => "/foo/bar", :getcomment => "whev" @parser.stubs(:lexer).returns @lexer end it "should include the lexer's line" do @parser.ast_context[:line].should == 50 end it "should include the lexer's file" do @parser.ast_context[:file].should == "/foo/bar" end it "should include the docs if directed to do so" do @parser.ast_context(true)[:doc].should == "whev" end it "should not include the docs when told not to" do @parser.ast_context(false)[:doc].should be_nil end it "should not include the docs by default" do @parser.ast_context[:doc].should be_nil end end describe "when building ast nodes" do before do @lexer = stub 'lexer', :line => 50, :file => "/foo/bar", :getcomment => "whev" @parser.stubs(:lexer).returns @lexer @class = Puppet::Resource::Type.new(:hostclass, "myclass", :use_docs => false) end it "should return a new instance of the provided class created with the provided options" do @class.expects(:new).with { |opts| opts[:foo] == "bar" } @parser.ast(@class, :foo => "bar") end it "should merge the ast context into the provided options" do @class.expects(:new).with { |opts| opts[:file] == "/foo" } @parser.expects(:ast_context).returns :file => "/foo" @parser.ast(@class, :foo => "bar") end it "should prefer provided options over AST context" do @class.expects(:new).with { |opts| opts[:file] == "/bar" } @lexer.expects(:file).returns "/foo" @parser.ast(@class, :file => "/bar") end it "should include docs when the AST class uses them" do @class.expects(:use_docs).returns true @class.stubs(:new) @parser.expects(:ast_context).with{ |docs, line| docs == true }.returns({}) @parser.ast(@class, :file => "/bar") end it "should get docs from lexer using the correct AST line number" do @class.expects(:use_docs).returns true @class.stubs(:new).with{ |a| a[:doc] == "doc" } @lexer.expects(:getcomment).with(12).returns "doc" @parser.ast(@class, :file => "/bar", :line => 12) end end describe "when retrieving a specific node" do it "should delegate to the known_resource_types node" do @known_resource_types.expects(:node).with("node") @parser.node("node") end end describe "when retrieving a specific class" do it "should delegate to the loaded code" do @known_resource_types.expects(:hostclass).with("class") @parser.hostclass("class") end end describe "when retrieving a specific definitions" do it "should delegate to the loaded code" do @known_resource_types.expects(:definition).with("define") @parser.definition("define") end end describe "when determining the configuration version" do it "should determine it from the resource type collection" do @parser.known_resource_types.expects(:version).returns "foo" @parser.version.should == "foo" end end describe "when looking up definitions" do it "should use the known resource types to check for them by name" do @parser.known_resource_types.stubs(:find_or_load).with("namespace","name",:definition).returns(:this_value) @parser.find_definition("namespace","name").should == :this_value end end describe "when looking up hostclasses" do it "should use the known resource types to check for them by name" do @parser.known_resource_types.stubs(:find_or_load).with("namespace","name",:hostclass).returns(:this_value) @parser.find_hostclass("namespace","name").should == :this_value end end describe "when parsing classes" do before :each do @krt = Puppet::Resource::TypeCollection.new("development") @parser = Puppet::Parser::Parser.new "development" @parser.stubs(:known_resource_types).returns @krt end it "should not create new classes" do @parser.parse("class foobar {}").code[0].should be_a(Puppet::Parser::AST::Hostclass) @krt.hostclass("foobar").should be_nil end it "should correctly set the parent class when one is provided" do @parser.parse("class foobar inherits yayness {}").code[0].instantiate('')[0].parent.should == "yayness" end it "should correctly set the parent class for multiple classes at a time" do statements = @parser.parse("class foobar inherits yayness {}\nclass boo inherits bar {}").code statements[0].instantiate('')[0].parent.should == "yayness" statements[1].instantiate('')[0].parent.should == "bar" end it "should define the code when some is provided" do @parser.parse("class foobar { $var = val }").code[0].code.should_not be_nil end + it "should accept parameters with trailing comma" do + @parser.parse("file { '/example': ensure => file, }").should be + end + it "should accept parametrized classes with trailing comma" do @parser.parse("class foobar ($var1 = 0,) { $var = val }").code[0].code.should_not be_nil end it "should define parameters when provided" do foobar = @parser.parse("class foobar($biz,$baz) {}").code[0].instantiate('')[0] foobar.arguments.should == {"biz" => nil, "baz" => nil} end end describe "when parsing resources" do before :each do @krt = Puppet::Resource::TypeCollection.new("development") @parser = Puppet::Parser::Parser.new "development" @parser.stubs(:known_resource_types).returns @krt end it "should be able to parse class resources" do @krt.add(Puppet::Resource::Type.new(:hostclass, "foobar", :arguments => {"biz" => nil})) - lambda { @parser.parse("class { foobar: biz => stuff }") }.should_not raise_error + expect { @parser.parse("class { foobar: biz => stuff }") }.should_not raise_error end it "should correctly mark exported resources as exported" do @parser.parse("@@file { '/file': }").code[0].exported.should be_true end it "should correctly mark virtual resources as virtual" do @parser.parse("@file { '/file': }").code[0].virtual.should be_true end end describe "when parsing nodes" do it "should be able to parse a node with a single name" do node = @parser.parse("node foo { }").code[0] node.should be_a Puppet::Parser::AST::Node node.names.length.should == 1 node.names[0].value.should == "foo" end it "should be able to parse a node with two names" do node = @parser.parse("node foo, bar { }").code[0] node.should be_a Puppet::Parser::AST::Node node.names.length.should == 2 node.names[0].value.should == "foo" node.names[1].value.should == "bar" end it "should be able to parse a node with three names" do node = @parser.parse("node foo, bar, baz { }").code[0] node.should be_a Puppet::Parser::AST::Node node.names.length.should == 3 node.names[0].value.should == "foo" node.names[1].value.should == "bar" node.names[2].value.should == "baz" end end + + it "should fail if trying to collect defaults" do + expect { @parser.parse("@Port { protocols => tcp }") }. + to raise_error Puppet::ParseError + end + + context "when parsing collections" do + it "should parse basic collections" do + @parser.parse("Port <| |>").code. + should be_all {|x| x.is_a? Puppet::Parser::AST::Collection } + end + + it "should parse fully qualified collections" do + @parser.parse("Port::Range <| |>").code. + should be_all {|x| x.is_a? Puppet::Parser::AST::Collection } + end + end + + it "should not assign to a fully qualified variable" do + expect { @parser.parse("$one::two = yay") }.to raise_error Puppet::ParseError + end + + it "should parse assignment of undef" do + tree = @parser.parse("$var = undef") + tree.code.children[0].should be_an_instance_of Puppet::Parser::AST::VarDef + tree.code.children[0].value.should be_an_instance_of Puppet::Parser::AST::Undef + end + + context "#namesplit" do + { "base::sub" => %w{base sub}, + "main" => ["", "main"], + "one::two::three::four" => ["one::two::three", "four"], + }.each do |input, output| + it "should split #{input.inspect} to #{output.inspect}" do + @parser.namesplit(input).should == output + end + end + end + + it "should treat classes as case insensitive" do + @parser.known_resource_types.import_ast(@parser.parse("class yayness {}"), '') + @parser.known_resource_types.hostclass('yayness'). + should == @parser.find_hostclass("", "YayNess") + end + + it "should treat defines as case insensitive" do + @parser.known_resource_types.import_ast(@parser.parse("define funtest {}"), '') + @parser.known_resource_types.hostclass('funtest'). + should == @parser.find_hostclass("", "fUntEst") + end end diff --git a/spec/unit/parser/scope_spec.rb b/spec/unit/parser/scope_spec.rb index 11146fa72..ba37ec398 100755 --- a/spec/unit/parser/scope_spec.rb +++ b/spec/unit/parser/scope_spec.rb @@ -1,534 +1,548 @@ #!/usr/bin/env rspec require 'spec_helper' describe Puppet::Parser::Scope do before :each do @topscope = Puppet::Parser::Scope.new # This is necessary so we don't try to use the compiler to discover our parent. @topscope.parent = nil @scope = Puppet::Parser::Scope.new @scope.compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foo")) @scope.parent = @topscope end it "should be able to store references to class scopes" do lambda { @scope.class_set "myname", "myscope" }.should_not raise_error end it "should be able to retrieve class scopes by name" do @scope.class_set "myname", "myscope" @scope.class_scope("myname").should == "myscope" end it "should be able to retrieve class scopes by object" do klass = mock 'ast_class' klass.expects(:name).returns("myname") @scope.class_set "myname", "myscope" @scope.class_scope(klass).should == "myscope" end it "should be able to retrieve its parent module name from the source of its parent type" do @topscope.source = Puppet::Resource::Type.new(:hostclass, :foo, :module_name => "foo") @scope.parent_module_name.should == "foo" end it "should return a nil parent module name if it has no parent" do @topscope.parent_module_name.should be_nil end it "should return a nil parent module name if its parent has no source" do @scope.parent_module_name.should be_nil end it "should get its environment from its compiler" do env = Puppet::Node::Environment.new compiler = stub 'compiler', :environment => env scope = Puppet::Parser::Scope.new :compiler => compiler 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) end it "should use the resource type collection helper to find its known resource types" do Puppet::Parser::Scope.ancestors.should include(Puppet::Resource::TypeCollectionHelper) end describe "when missing methods are called" do before :each do @env = Puppet::Node::Environment.new('testing') @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new('foo', :environment => @env)) @scope = Puppet::Parser::Scope.new(:compiler => @compiler) end it "should load and call the method if it looks like a function and it exists" do @scope.function_sprintf(["%b", 123]).should == "1111011" end it "should raise NoMethodError if the method doesn't look like a function" do expect { @scope.sprintf(["%b", 123]) }.should raise_error(NoMethodError) end it "should raise NoMethodError if the method looks like a function but doesn't exist" do expect { @scope.function_fake_bs(['cows']) }.should raise_error(NoMethodError) end end describe "when initializing" do it "should extend itself with its environment's Functions module as well as the default" do env = Puppet::Node::Environment.new("myenv") root = Puppet::Node::Environment.root compiler = stub 'compiler', :environment => env scope = Puppet::Parser::Scope.new(:compiler => compiler) scope.singleton_class.ancestors.should be_include(Puppet::Parser::Functions.environment_module(env)) scope.singleton_class.ancestors.should be_include(Puppet::Parser::Functions.environment_module(root)) 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 scope.singleton_class.ancestors.should be_include(Puppet::Parser::Functions.environment_module(root)) end it "should remember if it is dynamic" do (!!Puppet::Parser::Scope.new(:dynamic => true).dynamic).should == true end it "should assume it is not dynamic" do (!Puppet::Parser::Scope.new.dynamic).should == true end end describe "when looking up a variable" do it "should support :lookupvar and :setvar for backward compatibility" do @scope.setvar("var", "yep") @scope.lookupvar("var").should == "yep" end it "should return nil for unset variables" do @scope["var"].should be_nil end it "should be able to look up values" do @scope["var"] = "yep" @scope["var"].should == "yep" end it "should be able to look up hashes" do @scope["var"] = {"a" => "b"} @scope["var"].should == {"a" => "b"} end it "should be able to look up variables in parent scopes" do @topscope["var"] = "parentval" @scope["var"].should == "parentval" end it "should prefer its own values to parent values" do @topscope["var"] = "parentval" @scope["var"] = "childval" @scope["var"].should == "childval" end it "should be able to detect when variables are set" do @scope["var"] = "childval" @scope.should be_include("var") end it "should be able to detect when variables are not set" do @scope.should_not be_include("var") end it "should support iteration over its variables" do @scope["one"] = "two" @scope["three"] = "four" hash = {} @scope.each { |name, value| hash[name] = value } hash.should == {"one" => "two", "three" => "four" } end it "should include Enumerable" do @scope.singleton_class.ancestors.should be_include(Enumerable) end describe "and the variable is qualified" do before do @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foonode")) @scope.compiler = @compiler @known_resource_types = @scope.known_resource_types end def newclass(name) @known_resource_types.add Puppet::Resource::Type.new(:hostclass, name) end def create_class_scope(name) klass = newclass(name) catalog = Puppet::Resource::Catalog.new catalog.add_resource(Puppet::Parser::Resource.new("stage", :main, :scope => Puppet::Parser::Scope.new)) Puppet::Parser::Resource.new("class", name, :scope => @scope, :source => mock('source'), :catalog => catalog).evaluate @scope.class_scope(klass) end it "should be able to look up explicitly fully qualified variables from main" do other_scope = create_class_scope("") other_scope["othervar"] = "otherval" @scope["::othervar"].should == "otherval" end it "should be able to look up explicitly fully qualified variables from other scopes" do other_scope = create_class_scope("other") other_scope["var"] = "otherval" @scope["::other::var"].should == "otherval" end it "should be able to look up deeply qualified variables" do other_scope = create_class_scope("other::deep::klass") other_scope["var"] = "otherval" @scope["other::deep::klass::var"].should == "otherval" end it "should return nil for qualified variables that cannot be found in other classes" do other_scope = create_class_scope("other::deep::klass") @scope["other::deep::klass::var"].should be_nil end it "should warn and return nil for qualified variables whose classes have not been evaluated" do klass = newclass("other::deep::klass") @scope.expects(:warning) @scope["other::deep::klass::var"].should be_nil end it "should warn and return nil for qualified variables whose classes do not exist" do @scope.expects(:warning) @scope["other::deep::klass::var"].should be_nil end it "should return nil when asked for a non-string qualified variable from a class that does not exist" do @scope.stubs(:warning) @scope["other::deep::klass::var"].should be_nil end it "should return nil 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["other::deep::klass::var"].should be_nil end end end describe "when variables are set with append=true" do it "should raise an error if the variable is already defined in this scope" do @scope.setvar("var","1", :append => false) lambda { @scope.setvar("var","1", :append => true) }.should raise_error(Puppet::ParseError) end it "should lookup current variable value" do @scope.expects(:[]).with("var").returns("2") @scope.setvar("var","1", :append => true) end it "should store the concatenated string '42'" do @topscope.setvar("var","4", :append => false) @scope.setvar("var","2", :append => true) @scope["var"].should == "42" end it "should store the concatenated array [4,2]" do @topscope.setvar("var",[4], :append => false) @scope.setvar("var",[2], :append => true) @scope["var"].should == [4,2] end it "should store the merged hash {a => b, c => d}" do @topscope.setvar("var",{"a" => "b"}, :append => false) @scope.setvar("var",{"c" => "d"}, :append => true) @scope["var"].should == {"a" => "b", "c" => "d"} end it "should raise an error when appending a hash with something other than another hash" do @topscope.setvar("var",{"a" => "b"}, :append => false) lambda { @scope.setvar("var","not a hash", :append => true) }.should raise_error end end describe "when calling number?" do it "should return nil if called with anything not a number" do Puppet::Parser::Scope.number?([2]).should be_nil end it "should return a Fixnum for a Fixnum" do Puppet::Parser::Scope.number?(2).should be_an_instance_of(Fixnum) end it "should return a Float for a Float" do Puppet::Parser::Scope.number?(2.34).should be_an_instance_of(Float) end it "should return 234 for '234'" do Puppet::Parser::Scope.number?("234").should == 234 end it "should return nil for 'not a number'" do Puppet::Parser::Scope.number?("not a number").should be_nil end it "should return 23.4 for '23.4'" do Puppet::Parser::Scope.number?("23.4").should == 23.4 end it "should return 23.4e13 for '23.4e13'" do Puppet::Parser::Scope.number?("23.4e13").should == 23.4e13 end it "should understand negative numbers" do Puppet::Parser::Scope.number?("-234").should == -234 end it "should know how to convert exponential float numbers ala '23e13'" do Puppet::Parser::Scope.number?("23e13").should == 23e13 end it "should understand hexadecimal numbers" do Puppet::Parser::Scope.number?("0x234").should == 0x234 end it "should understand octal numbers" do Puppet::Parser::Scope.number?("0755").should == 0755 end it "should return nil on malformed integers" do Puppet::Parser::Scope.number?("0.24.5").should be_nil end it "should convert strings with leading 0 to integer if they are not octal" do Puppet::Parser::Scope.number?("0788").should == 788 end it "should convert strings of negative integers" do Puppet::Parser::Scope.number?("-0788").should == -788 end it "should return nil on malformed hexadecimal numbers" do Puppet::Parser::Scope.number?("0x89g").should be_nil end end describe "when using ephemeral variables" do it "should store the variable value" do @scope.setvar("1", :value, :ephemeral => true) @scope["1"].should == :value end it "should remove the variable value when unset_ephemeral_var is called" do @scope.setvar("1", :value, :ephemeral => true) @scope.stubs(:parent).returns(nil) @scope.unset_ephemeral_var @scope["1"].should be_nil end it "should not remove classic variables when unset_ephemeral_var is called" do @scope['myvar'] = :value1 @scope.setvar("1", :value2, :ephemeral => true) @scope.stubs(:parent).returns(nil) @scope.unset_ephemeral_var @scope["myvar"].should == :value1 end it "should raise an error when setting it again" do @scope.setvar("1", :value2, :ephemeral => true) lambda { @scope.setvar("1", :value3, :ephemeral => true) }.should raise_error end it "should declare ephemeral number only variable names" do @scope.ephemeral?("0").should be_true end it "should not declare ephemeral other variable names" do @scope.ephemeral?("abc0").should be_nil end describe "with more than one level" do it "should prefer latest ephemeral scopes" do @scope.setvar("0", :earliest, :ephemeral => true) @scope.new_ephemeral @scope.setvar("0", :latest, :ephemeral => true) @scope["0"].should == :latest end it "should be able to report the current level" do @scope.ephemeral_level.should == 1 @scope.new_ephemeral @scope.ephemeral_level.should == 2 end it "should check presence of an ephemeral variable accross multiple levels" do @scope.new_ephemeral @scope.setvar("1", :value1, :ephemeral => true) @scope.new_ephemeral @scope.setvar("0", :value2, :ephemeral => true) @scope.new_ephemeral @scope.ephemeral_include?("1").should be_true end it "should return false when an ephemeral variable doesn't exist in any ephemeral scope" do @scope.new_ephemeral @scope.setvar("1", :value1, :ephemeral => true) @scope.new_ephemeral @scope.setvar("0", :value2, :ephemeral => true) @scope.new_ephemeral @scope.ephemeral_include?("2").should be_false end it "should get ephemeral values from earlier scope when not in later" do @scope.setvar("1", :value1, :ephemeral => true) @scope.new_ephemeral @scope.setvar("0", :value2, :ephemeral => true) @scope["1"].should == :value1 end describe "when calling unset_ephemeral_var without a level" do it "should remove all the variables values" do @scope.setvar("1", :value1, :ephemeral => true) @scope.new_ephemeral @scope.setvar("1", :value2, :ephemeral => true) @scope.unset_ephemeral_var @scope["1"].should be_nil end end describe "when calling unset_ephemeral_var with a level" do it "should remove ephemeral scopes up to this level" do @scope.setvar("1", :value1, :ephemeral => true) @scope.new_ephemeral @scope.setvar("1", :value2, :ephemeral => true) @scope.new_ephemeral @scope.setvar("1", :value3, :ephemeral => true) @scope.unset_ephemeral_var(2) @scope["1"].should == :value2 end end end end describe "when setting ephemeral vars from matches" do before :each do @match = stub 'match', :is_a? => true @match.stubs(:[]).with(0).returns("this is a string") @match.stubs(:captures).returns([]) @scope.stubs(:setvar) end it "should accept only MatchData" do lambda { @scope.ephemeral_from("match") }.should raise_error end it "should set $0 with the full match" do @scope.expects(:setvar).with { |*arg| arg[0] == "0" and arg[1] == "this is a string" and arg[2][:ephemeral] } @scope.ephemeral_from(@match) end it "should set every capture as ephemeral var" do @match.stubs(:captures).returns([:capture1,:capture2]) @scope.expects(:setvar).with { |*arg| arg[0] == "1" and arg[1] == :capture1 and arg[2][:ephemeral] } @scope.expects(:setvar).with { |*arg| arg[0] == "2" and arg[1] == :capture2 and arg[2][:ephemeral] } @scope.ephemeral_from(@match) end it "should create a new ephemeral level" do @scope.expects(:new_ephemeral) @scope.ephemeral_from(@match) end end describe "when unsetting variables" do it "should be able to unset normal variables" do @scope["foo"] = "bar" @scope.unsetvar("foo") @scope["foo"].should be_nil end it "should be able to unset ephemeral variables" do @scope.setvar("0", "bar", :ephemeral => true) @scope.unsetvar("0") @scope["0"].should be_nil end it "should not unset ephemeral variables in previous ephemeral scope" do @scope.setvar("0", "bar", :ephemeral => true) @scope.new_ephemeral @scope.unsetvar("0") @scope["0"].should == "bar" end end it "should use its namespaces to find hostclasses" do klass = @scope.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "a::b::c") @scope.add_namespace "a::b" @scope.find_hostclass("c").should equal(klass) end it "should use its namespaces to find definitions" do define = @scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "a::b::c") @scope.add_namespace "a::b" @scope.find_definition("c").should equal(define) end describe "when managing defaults" do it "should be able to set and lookup defaults" do param = Puppet::Parser::Resource::Param.new(:name => :myparam, :value => "myvalue", :source => stub("source")) @scope.define_settings(:mytype, param) @scope.lookupdefaults(:mytype).should == {:myparam => param} end it "should fail if a default is already defined and a new default is being defined" do param = Puppet::Parser::Resource::Param.new(:name => :myparam, :value => "myvalue", :source => stub("source")) @scope.define_settings(:mytype, param) lambda { @scope.define_settings(:mytype, param) }.should raise_error(Puppet::ParseError) end it "should return multiple defaults at once" do param1 = Puppet::Parser::Resource::Param.new(:name => :myparam, :value => "myvalue", :source => stub("source")) @scope.define_settings(:mytype, param1) param2 = Puppet::Parser::Resource::Param.new(:name => :other, :value => "myvalue", :source => stub("source")) @scope.define_settings(:mytype, param2) @scope.lookupdefaults(:mytype).should == {:myparam => param1, :other => param2} end it "should look up defaults defined in parent scopes" do param1 = Puppet::Parser::Resource::Param.new(:name => :myparam, :value => "myvalue", :source => stub("source")) @scope.define_settings(:mytype, param1) child_scope = @scope.newscope param2 = Puppet::Parser::Resource::Param.new(:name => :other, :value => "myvalue", :source => stub("source")) child_scope.define_settings(:mytype, param2) child_scope.lookupdefaults(:mytype).should == {:myparam => param1, :other => param2} end end + + context "#true?" do + { "a string" => true, + "true" => true, + "false" => true, + true => true, + "" => false, + :undef => false + }.each do |input, output| + it "should treat #{input.inspect} as #{output}" do + Puppet::Parser::Scope.true?(input).should == output + end + end + end end diff --git a/test/data/failers/badclassnoparam b/test/data/failers/badclassnoparam deleted file mode 100644 index a0397aacc..000000000 --- a/test/data/failers/badclassnoparam +++ /dev/null @@ -1,10 +0,0 @@ -class comp() { - file { "/etc/passwd": - mode => 644 - } -} - -# this argument is invalid, thus we should get a falure -comp { - fakearg => "yay" -} diff --git a/test/data/failers/badclassparam b/test/data/failers/badclassparam deleted file mode 100644 index 4c9ff6199..000000000 --- a/test/data/failers/badclassparam +++ /dev/null @@ -1,10 +0,0 @@ -class comp(arg1) { - file { "/etc/passwd": - mode => 644 - } -} - -# i've specified an arg but it's an invalid one -comp { - fakearg => "yay" -} diff --git a/test/data/failers/badcompnoparam b/test/data/failers/badcompnoparam deleted file mode 100644 index fd25c9445..000000000 --- a/test/data/failers/badcompnoparam +++ /dev/null @@ -1,9 +0,0 @@ -define comp() { - file { "/etc/passwd": - mode => 644 - } -} - -comp { - fakearg => "yay" -} diff --git a/test/data/failers/badcompparam b/test/data/failers/badcompparam deleted file mode 100644 index 346e64b25..000000000 --- a/test/data/failers/badcompparam +++ /dev/null @@ -1,9 +0,0 @@ -define comp($arg1) { - file { "/etc/passwd": - mode => 644 - } -} - -comp { - fakearg => "yay" -} diff --git a/test/data/failers/badtypeparam b/test/data/failers/badtypeparam deleted file mode 100644 index 4634f2052..000000000 --- a/test/data/failers/badtypeparam +++ /dev/null @@ -1,3 +0,0 @@ -file { "/etc/passwd": - fakeparam => 644 -} diff --git a/test/data/failers/noobjectrvalue b/test/data/failers/noobjectrvalue deleted file mode 100644 index ef6064740..000000000 --- a/test/data/failers/noobjectrvalue +++ /dev/null @@ -1 +0,0 @@ -$variable = file { "/etc/passwd": owner => root } diff --git a/test/data/snippets/aliastest.pp b/test/data/snippets/aliastest.pp deleted file mode 100644 index f2b61592e..000000000 --- a/test/data/snippets/aliastest.pp +++ /dev/null @@ -1,16 +0,0 @@ -file { "a file": - path => "/tmp/aliastest", - ensure => file -} - -file { "another": - path => "/tmp/aliastest2", - ensure => file, - require => File["a file"] -} - -file { "a third": - path => "/tmp/aliastest3", - ensure => file, - require => File["/tmp/aliastest"] -} diff --git a/test/data/snippets/append.pp b/test/data/snippets/append.pp deleted file mode 100644 index 20cbda662..000000000 --- a/test/data/snippets/append.pp +++ /dev/null @@ -1,11 +0,0 @@ -$var=['/tmp/file1','/tmp/file2'] - -class arraytest { - $var += ['/tmp/file3', '/tmp/file4'] - file { - $var: - content => "test" - } -} - -include arraytest diff --git a/test/data/snippets/argumentdefaults b/test/data/snippets/argumentdefaults deleted file mode 100644 index eac9dd757..000000000 --- a/test/data/snippets/argumentdefaults +++ /dev/null @@ -1,14 +0,0 @@ -# $Id$ - -define testargs($file, $mode = 755) { - file { $file: ensure => file, mode => $mode } -} - -testargs { "testingname": - file => "/tmp/argumenttest1" -} - -testargs { "testingother": - file => "/tmp/argumenttest2", - mode => 644 -} diff --git a/test/data/snippets/arithmetic_expression.pp b/test/data/snippets/arithmetic_expression.pp deleted file mode 100644 index aae98a4db..000000000 --- a/test/data/snippets/arithmetic_expression.pp +++ /dev/null @@ -1,8 +0,0 @@ - -$one = 1.30 -$two = 2.034e-2 - -$result = ((( $two + 2) / $one) + 4 * 5.45) - (6 << 7) + (0x800 + -9) - - -notice("result is $result == 1295.87692307692") \ No newline at end of file diff --git a/test/data/snippets/arraytrailingcomma.pp b/test/data/snippets/arraytrailingcomma.pp deleted file mode 100644 index a410f9553..000000000 --- a/test/data/snippets/arraytrailingcomma.pp +++ /dev/null @@ -1,3 +0,0 @@ -file { - ["/tmp/arraytrailingcomma1","/tmp/arraytrailingcomma2", ]: content => "tmp" -} diff --git a/test/data/snippets/casestatement.pp b/test/data/snippets/casestatement.pp deleted file mode 100644 index 66ecd72b9..000000000 --- a/test/data/snippets/casestatement.pp +++ /dev/null @@ -1,65 +0,0 @@ -# $Id$ - -$var = "value" - -case $var { - "nope": { - file { "/tmp/fakefile": mode => 644, ensure => file } - } - "value": { - file { "/tmp/existsfile": mode => 755, ensure => file } - } -} - -$ovar = "yayness" - -case $ovar { - "fooness": { - file { "/tmp/nostillexistsfile": mode => 644, ensure => file } - } - "booness", "yayness": { - case $var { - "nep": { - file { "/tmp/noexistsfile": mode => 644, ensure => file } - } - "value": { - file { "/tmp/existsfile2": mode => 755, ensure => file } - } - } - } -} - -case $ovar { - "fooness": { - file { "/tmp/nostillexistsfile": mode => 644, ensure => file } - } - default: { - file { "/tmp/existsfile3": mode => 755, ensure => file } - } -} - -$bool = true - -case $bool { - true: { - file { "/tmp/existsfile4": mode => 755, ensure => file } - } -} - -$yay = yay -$a = yay -$b = boo - -case $yay { - $a: { file { "/tmp/existsfile5": mode => 755, ensure => file } } - $b: { file { "/tmp/existsfile5": mode => 644, ensure => file } } - default: { file { "/tmp/existsfile5": mode => 711, ensure => file } } - -} - -$regexvar = "exists regex" -case $regexvar { - "no match": { file { "/tmp/existsfile6": mode => 644, ensure => file } } - /(.*) regex$/: { file { "/tmp/${1}file6": mode => 755, ensure => file } } - default: { file { "/tmp/existsfile6": mode => 711, ensure => file } } -} diff --git a/test/data/snippets/classheirarchy.pp b/test/data/snippets/classheirarchy.pp deleted file mode 100644 index 36619d8b9..000000000 --- a/test/data/snippets/classheirarchy.pp +++ /dev/null @@ -1,15 +0,0 @@ -# $Id$ - -class base { - file { "/tmp/classheir1": ensure => file, mode => 755 } -} - -class sub1 inherits base { - file { "/tmp/classheir2": ensure => file, mode => 755 } -} - -class sub2 inherits base { - file { "/tmp/classheir3": ensure => file, mode => 755 } -} - -include sub1, sub2 diff --git a/test/data/snippets/classincludes.pp b/test/data/snippets/classincludes.pp deleted file mode 100644 index bd5b44ed7..000000000 --- a/test/data/snippets/classincludes.pp +++ /dev/null @@ -1,17 +0,0 @@ -# $Id$ - -class base { - file { "/tmp/classincludes1": ensure => file, mode => 755 } -} - -class sub1 inherits base { - file { "/tmp/classincludes2": ensure => file, mode => 755 } -} - -class sub2 inherits base { - file { "/tmp/classincludes3": ensure => file, mode => 755 } -} - -$sub = "sub2" - -include sub1, $sub diff --git a/test/data/snippets/classpathtest b/test/data/snippets/classpathtest deleted file mode 100644 index 580333369..000000000 --- a/test/data/snippets/classpathtest +++ /dev/null @@ -1,11 +0,0 @@ -# $Id$ - -define mytype { - file { "/tmp/classtest": ensure => file, mode => 755 } -} - -class testing { - mytype { "componentname": } -} - -include testing diff --git a/test/data/snippets/collection.pp b/test/data/snippets/collection.pp deleted file mode 100644 index bc29510a9..000000000 --- a/test/data/snippets/collection.pp +++ /dev/null @@ -1,10 +0,0 @@ -class one { - @file { "/tmp/colltest1": content => "one" } - @file { "/tmp/colltest2": content => "two" } -} - -class two { - File <| content == "one" |> -} - -include one, two diff --git a/test/data/snippets/collection_override.pp b/test/data/snippets/collection_override.pp deleted file mode 100644 index b1b39ab16..000000000 --- a/test/data/snippets/collection_override.pp +++ /dev/null @@ -1,8 +0,0 @@ -@file { - "/tmp/collection": - content => "whatever" -} - -File<| |> { - mode => 0600 -} diff --git a/test/data/snippets/collection_within_virtual_definitions.pp b/test/data/snippets/collection_within_virtual_definitions.pp deleted file mode 100644 index 3c21468b0..000000000 --- a/test/data/snippets/collection_within_virtual_definitions.pp +++ /dev/null @@ -1,20 +0,0 @@ -define test($name) { - file {"/tmp/collection_within_virtual_definitions1_$name.txt": - content => "File name $name\n" - } - Test2 <||> -} - -define test2() { - file {"/tmp/collection_within_virtual_definitions2_$name.txt": - content => "This is a test\n" - } -} - -node default { - @test {"foo": - name => "foo" - } - @test2 {"foo2": } - Test <||> -} diff --git a/test/data/snippets/componentmetaparams.pp b/test/data/snippets/componentmetaparams.pp deleted file mode 100644 index 7d9f0c2c1..000000000 --- a/test/data/snippets/componentmetaparams.pp +++ /dev/null @@ -1,11 +0,0 @@ -file { "/tmp/component1": - ensure => file -} - -define thing { - file { $name: ensure => file } -} - -thing { "/tmp/component2": - require => File["/tmp/component1"] -} diff --git a/test/data/snippets/componentrequire.pp b/test/data/snippets/componentrequire.pp deleted file mode 100644 index a61d2050c..000000000 --- a/test/data/snippets/componentrequire.pp +++ /dev/null @@ -1,8 +0,0 @@ -define testfile($mode) { - file { $name: mode => $mode, ensure => present } -} - -testfile { "/tmp/testing_component_requires2": mode => 755 } - -file { "/tmp/testing_component_requires1": mode => 755, ensure => present, - require => Testfile["/tmp/testing_component_requires2"] } diff --git a/test/data/snippets/deepclassheirarchy.pp b/test/data/snippets/deepclassheirarchy.pp deleted file mode 100644 index 249e6334d..000000000 --- a/test/data/snippets/deepclassheirarchy.pp +++ /dev/null @@ -1,23 +0,0 @@ -# $Id$ - -class base { - file { "/tmp/deepclassheir1": ensure => file, mode => 755 } -} - -class sub1 inherits base { - file { "/tmp/deepclassheir2": ensure => file, mode => 755 } -} - -class sub2 inherits sub1 { - file { "/tmp/deepclassheir3": ensure => file, mode => 755 } -} - -class sub3 inherits sub2 { - file { "/tmp/deepclassheir4": ensure => file, mode => 755 } -} - -class sub4 inherits sub3 { - file { "/tmp/deepclassheir5": ensure => file, mode => 755 } -} - -include sub4 diff --git a/test/data/snippets/defineoverrides.pp b/test/data/snippets/defineoverrides.pp deleted file mode 100644 index c68b139e3..000000000 --- a/test/data/snippets/defineoverrides.pp +++ /dev/null @@ -1,17 +0,0 @@ -# $Id$ - -$file = "/tmp/defineoverrides1" - -define myfile($mode) { - file { $name: ensure => file, mode => $mode } -} - -class base { - myfile { $file: mode => 644 } -} - -class sub inherits base { - Myfile[$file] { mode => 755, } # test the end-comma -} - -include sub diff --git a/test/data/snippets/emptyclass.pp b/test/data/snippets/emptyclass.pp deleted file mode 100644 index 48047e748..000000000 --- a/test/data/snippets/emptyclass.pp +++ /dev/null @@ -1,9 +0,0 @@ -# $Id$ - -define component { -} - -class testing { -} - -include testing diff --git a/test/data/snippets/emptyexec.pp b/test/data/snippets/emptyexec.pp deleted file mode 100644 index 847a30d18..000000000 --- a/test/data/snippets/emptyexec.pp +++ /dev/null @@ -1,3 +0,0 @@ -exec { "touch /tmp/emptyexectest": - path => "/usr/bin:/bin" -} diff --git a/test/data/snippets/emptyifelse.pp b/test/data/snippets/emptyifelse.pp deleted file mode 100644 index 598b486ac..000000000 --- a/test/data/snippets/emptyifelse.pp +++ /dev/null @@ -1,9 +0,0 @@ - -if false { -} else { - # nothing here -} - -if true { - # still nothing -} diff --git a/test/data/snippets/falsevalues.pp b/test/data/snippets/falsevalues.pp deleted file mode 100644 index 2143b79a7..000000000 --- a/test/data/snippets/falsevalues.pp +++ /dev/null @@ -1,3 +0,0 @@ -$value = false - -file { "/tmp/falsevalues$value": ensure => file } diff --git a/test/data/snippets/filecreate b/test/data/snippets/filecreate deleted file mode 100644 index d7972c234..000000000 --- a/test/data/snippets/filecreate +++ /dev/null @@ -1,11 +0,0 @@ -# $Id$ - -file { - "/tmp/createatest": ensure => file, mode => 755; - "/tmp/createbtest": ensure => file, mode => 755 -} - -file { - "/tmp/createctest": ensure => file; - "/tmp/createdtest": ensure => file; -} diff --git a/test/data/snippets/fqdefinition.pp b/test/data/snippets/fqdefinition.pp deleted file mode 100644 index ddb0675a9..000000000 --- a/test/data/snippets/fqdefinition.pp +++ /dev/null @@ -1,5 +0,0 @@ -define one::two($ensure) { - file { "/tmp/fqdefinition": ensure => $ensure } -} - -one::two { "/tmp/fqdefinition": ensure => file } diff --git a/test/data/snippets/fqparents.pp b/test/data/snippets/fqparents.pp deleted file mode 100644 index ee2f65423..000000000 --- a/test/data/snippets/fqparents.pp +++ /dev/null @@ -1,11 +0,0 @@ -class base { - class one { - file { "/tmp/fqparent1": ensure => file } - } -} - -class two::three inherits base::one { - file { "/tmp/fqparent2": ensure => file } -} - -include two::three diff --git a/test/data/snippets/funccomma.pp b/test/data/snippets/funccomma.pp deleted file mode 100644 index 32e34f92e..000000000 --- a/test/data/snippets/funccomma.pp +++ /dev/null @@ -1,5 +0,0 @@ -@file { - ["/tmp/funccomma1","/tmp/funccomma2"]: content => "1" -} - -realize( File["/tmp/funccomma1"], File["/tmp/funccomma2"] , ) diff --git a/test/data/snippets/hash.pp b/test/data/snippets/hash.pp deleted file mode 100644 index d33249872..000000000 --- a/test/data/snippets/hash.pp +++ /dev/null @@ -1,33 +0,0 @@ - -$hash = { "file" => "/tmp/myhashfile1" } - -file { - $hash["file"]: - ensure => file, content => "content"; -} - -$hash2 = { "a" => { key => "/tmp/myhashfile2" }} - -file { - $hash2["a"][key]: - ensure => file, content => "content"; -} - -define test($a = { "b" => "c" }) { - file { - $a["b"]: - ensure => file, content => "content" - } -} - -test { - "test": - a => { "b" => "/tmp/myhashfile3" } -} - -$hash3 = { mykey => "/tmp/myhashfile4" } -$key = "mykey" - -file { - $hash3[$key]: ensure => file, content => "content" -} diff --git a/test/data/snippets/ifexpression.pp b/test/data/snippets/ifexpression.pp deleted file mode 100644 index 29a637291..000000000 --- a/test/data/snippets/ifexpression.pp +++ /dev/null @@ -1,12 +0,0 @@ -$one = 1 -$two = 2 - -if ($one < $two) and (($two < 3) or ($two == 2)) { - notice("True!") -} - -if "test regex" =~ /(.*) regex/ { - file { - "/tmp/${1}iftest": ensure => file, mode => 0755 - } -} diff --git a/test/data/snippets/implicititeration b/test/data/snippets/implicititeration deleted file mode 100644 index 6f34cb29c..000000000 --- a/test/data/snippets/implicititeration +++ /dev/null @@ -1,15 +0,0 @@ -# $Id$ - -$files = ["/tmp/iterationatest", "/tmp/iterationbtest"] - -file { $files: ensure => file, mode => 755 } - -file { ["/tmp/iterationctest", "/tmp/iterationdtest"]: - ensure => file, - mode => 755 -} - -file { - ["/tmp/iterationetest", "/tmp/iterationftest"]: ensure => file, mode => 755; - ["/tmp/iterationgtest", "/tmp/iterationhtest"]: ensure => file, mode => 755; -} diff --git a/test/data/snippets/multilinecomments.pp b/test/data/snippets/multilinecomments.pp deleted file mode 100644 index f9819c020..000000000 --- a/test/data/snippets/multilinecomments.pp +++ /dev/null @@ -1,10 +0,0 @@ - -/* -file { - "/tmp/multilinecomments": content => "pouet" -} -*/ - -/* and another one for #2333, the whitespace after the -end comment is here on purpose */ - diff --git a/test/data/snippets/multipleclass.pp b/test/data/snippets/multipleclass.pp deleted file mode 100644 index ae02edc38..000000000 --- a/test/data/snippets/multipleclass.pp +++ /dev/null @@ -1,9 +0,0 @@ -class one { - file { "/tmp/multipleclassone": content => "one" } -} - -class one { - file { "/tmp/multipleclasstwo": content => "two" } -} - -include one diff --git a/test/data/snippets/multipleinstances b/test/data/snippets/multipleinstances deleted file mode 100644 index 2f9b3c2e8..000000000 --- a/test/data/snippets/multipleinstances +++ /dev/null @@ -1,7 +0,0 @@ -# $Id$ - -file { - "/tmp/multipleinstancesa": ensure => file, mode => 755; - "/tmp/multipleinstancesb": ensure => file, mode => 755; - "/tmp/multipleinstancesc": ensure => file, mode => 755; -} diff --git a/test/data/snippets/multisubs.pp b/test/data/snippets/multisubs.pp deleted file mode 100644 index bcec69e2a..000000000 --- a/test/data/snippets/multisubs.pp +++ /dev/null @@ -1,13 +0,0 @@ -class base { - file { "/tmp/multisubtest": content => "base", mode => 644 } -} - -class sub1 inherits base { - File["/tmp/multisubtest"] { mode => 755 } -} - -class sub2 inherits base { - File["/tmp/multisubtest"] { content => sub2 } -} - -include sub1, sub2 diff --git a/test/data/snippets/namevartest b/test/data/snippets/namevartest deleted file mode 100644 index dbee1c356..000000000 --- a/test/data/snippets/namevartest +++ /dev/null @@ -1,9 +0,0 @@ -define filetest($mode, $ensure = file) { - file { $name: - mode => $mode, - ensure => $ensure - } -} - -filetest { "/tmp/testfiletest": mode => 644} -filetest { "/tmp/testdirtest": mode => 755, ensure => directory} diff --git a/test/data/snippets/scopetest b/test/data/snippets/scopetest deleted file mode 100644 index 331491766..000000000 --- a/test/data/snippets/scopetest +++ /dev/null @@ -1,13 +0,0 @@ - -$mode = 640 - -define thing { - file { "/tmp/$name": ensure => file, mode => $mode } -} - -class testing { - $mode = 755 - thing {scopetest: } -} - -include testing diff --git a/test/data/snippets/selectorvalues.pp b/test/data/snippets/selectorvalues.pp deleted file mode 100644 index d80d26c36..000000000 --- a/test/data/snippets/selectorvalues.pp +++ /dev/null @@ -1,49 +0,0 @@ -$value1 = "" -$value2 = true -$value3 = false -$value4 = yay - -$test = "yay" - -$mode1 = $value1 ? { - "" => 755, - default => 644 -} - -$mode2 = $value2 ? { - true => 755, - default => 644 -} - -$mode3 = $value3 ? { - false => 755, - default => 644 -} - -$mode4 = $value4 ? { - $test => 755, - default => 644 -} - -$mode5 = yay ? { - $test => 755, - default => 644 -} - -$mode6 = $mode5 ? { - 755 => 755 -} - -$mode7 = "test regex" ? { - /regex$/ => 755, - default => 644 -} - - -file { "/tmp/selectorvalues1": ensure => file, mode => $mode1 } -file { "/tmp/selectorvalues2": ensure => file, mode => $mode2 } -file { "/tmp/selectorvalues3": ensure => file, mode => $mode3 } -file { "/tmp/selectorvalues4": ensure => file, mode => $mode4 } -file { "/tmp/selectorvalues5": ensure => file, mode => $mode5 } -file { "/tmp/selectorvalues6": ensure => file, mode => $mode6 } -file { "/tmp/selectorvalues7": ensure => file, mode => $mode7 } diff --git a/test/data/snippets/simpledefaults b/test/data/snippets/simpledefaults deleted file mode 100644 index 63d199a68..000000000 --- a/test/data/snippets/simpledefaults +++ /dev/null @@ -1,5 +0,0 @@ -# $Id$ - -File { mode => 755 } - -file { "/tmp/defaulttest": ensure => file } diff --git a/test/data/snippets/simpleselector b/test/data/snippets/simpleselector deleted file mode 100644 index 8b9bc7292..000000000 --- a/test/data/snippets/simpleselector +++ /dev/null @@ -1,38 +0,0 @@ -# $Id$ - -$var = "value" - -file { "/tmp/snippetselectatest": - ensure => file, - mode => $var ? { - nottrue => 641, - value => 755 - } -} - -file { "/tmp/snippetselectbtest": - ensure => file, - mode => $var ? { - nottrue => 644, - default => 755 - } -} - -$othervar = "complex value" - -file { "/tmp/snippetselectctest": - ensure => file, - mode => $othervar ? { - "complex value" => 755, - default => 644 - } -} -$anothervar = Yayness - -file { "/tmp/snippetselectdtest": - ensure => file, - mode => $anothervar ? { - Yayness => 755, - default => 644 - } -} diff --git a/test/data/snippets/singleary.pp b/test/data/snippets/singleary.pp deleted file mode 100644 index 9ce56dd89..000000000 --- a/test/data/snippets/singleary.pp +++ /dev/null @@ -1,19 +0,0 @@ -# $Id$ - -file { "/tmp/singleary1": - ensure => file -} - -file { "/tmp/singleary2": - ensure => file -} - -file { "/tmp/singleary3": - ensure => file, - require => [File["/tmp/singleary1"], File["/tmp/singleary2"]] -} - -file { "/tmp/singleary4": - ensure => file, - require => [File["/tmp/singleary1"]] -} diff --git a/test/data/snippets/singlequote.pp b/test/data/snippets/singlequote.pp deleted file mode 100644 index dc876a2f8..000000000 --- a/test/data/snippets/singlequote.pp +++ /dev/null @@ -1,11 +0,0 @@ -# $Id$ - -file { "/tmp/singlequote1": - ensure => file, - content => 'a $quote' -} - -file { "/tmp/singlequote2": - ensure => file, - content => 'some "\yayness\"' -} diff --git a/test/data/snippets/singleselector.pp b/test/data/snippets/singleselector.pp deleted file mode 100644 index 520a14017..000000000 --- a/test/data/snippets/singleselector.pp +++ /dev/null @@ -1,22 +0,0 @@ -$value1 = "" -$value2 = true -$value3 = false -$value4 = yay - -$test = "yay" - -$mode1 = $value1 ? { - "" => 755 -} - -$mode2 = $value2 ? { - true => 755 -} - -$mode3 = $value3 ? { - default => 755 -} - -file { "/tmp/singleselector1": ensure => file, mode => $mode1 } -file { "/tmp/singleselector2": ensure => file, mode => $mode2 } -file { "/tmp/singleselector3": ensure => file, mode => $mode3 } diff --git a/test/data/snippets/subclass_name_duplication.pp b/test/data/snippets/subclass_name_duplication.pp deleted file mode 100755 index 10f1d75ed..000000000 --- a/test/data/snippets/subclass_name_duplication.pp +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env puppet - -class one::fake { - file { "/tmp/subclass_name_duplication1": ensure => present } -} - -class two::fake { - file { "/tmp/subclass_name_duplication2": ensure => present } -} - -include one::fake, two::fake diff --git a/test/data/snippets/tag.pp b/test/data/snippets/tag.pp deleted file mode 100644 index e6e770dd9..000000000 --- a/test/data/snippets/tag.pp +++ /dev/null @@ -1,9 +0,0 @@ -# $Id$ - -$variable = value - -tag yayness, rahness - -tag booness, $variable - -file { "/tmp/settestingness": ensure => file } diff --git a/test/data/snippets/tagged.pp b/test/data/snippets/tagged.pp deleted file mode 100644 index 7bf90a645..000000000 --- a/test/data/snippets/tagged.pp +++ /dev/null @@ -1,35 +0,0 @@ -# $Id$ - -tag testing -tag(funtest) - -class tagdefine { - $path = tagged(tagdefine) ? { - true => "true", false => "false" - } - - file { "/tmp/taggeddefine$path": ensure => file } -} - -include tagdefine - -$yayness = tagged(yayness) ? { - true => "true", false => "false" -} - -$funtest = tagged(testing) ? { - true => "true", false => "false" -} - -$both = tagged(testing, yayness) ? { - true => "true", false => "false" -} - -$bothtrue = tagged(testing, testing) ? { - true => "true", false => "false" -} - -file { "/tmp/taggedyayness$yayness": ensure => file } -file { "/tmp/taggedtesting$funtest": ensure => file } -file { "/tmp/taggedboth$both": ensure => file } -file { "/tmp/taggedbothtrue$bothtrue": ensure => file } diff --git a/test/data/snippets/virtualresources.pp b/test/data/snippets/virtualresources.pp deleted file mode 100644 index a29406b84..000000000 --- a/test/data/snippets/virtualresources.pp +++ /dev/null @@ -1,14 +0,0 @@ -class one { - @file { "/tmp/virtualtest1": content => "one" } - @file { "/tmp/virtualtest2": content => "two" } - @file { "/tmp/virtualtest3": content => "three" } - @file { "/tmp/virtualtest4": content => "four" } -} - -class two { - File <| content == "one" |> - realize File["/tmp/virtualtest2"] - realize(File["/tmp/virtualtest3"], File["/tmp/virtualtest4"]) -} - -include one, two diff --git a/test/language/ast.rb b/test/language/ast.rb deleted file mode 100755 index ec20cdb99..000000000 --- a/test/language/ast.rb +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../lib/puppettest') - -require 'puppettest' -require 'puppet/parser/parser' -require 'puppettest/resourcetesting' -require 'puppettest/parsertesting' - -class TestAST < Test::Unit::TestCase - include PuppetTest::ParserTesting - include PuppetTest::ResourceTesting - - def test_if - scope = mkscope - astif = nil - astelse = nil - fakeelse = FakeAST.new(:else) - faketest = FakeAST.new(true) - fakeif = FakeAST.new(:if) - - assert_nothing_raised { - astelse = AST::Else.new(:statements => fakeelse) - } - assert_nothing_raised { - - astif = AST::IfStatement.new( - - :test => faketest, - :statements => fakeif, - - :else => astelse - ) - } - - # We initialized it to true, so we should get that first - ret = nil - assert_nothing_raised { - ret = astif.evaluate(scope) - } - assert_equal(:if, ret) - - # Now set it to false and check that - faketest.evaluate = false - assert_nothing_raised { - ret = astif.evaluate(scope) - } - assert_equal(:else, ret) - end - - # Make sure our override object behaves "correctly" - def test_override - scope = mkscope - - ref = nil - assert_nothing_raised do - ref = resourceoverride("file", "/yayness", "owner" => "blah", "group" => "boo") - end - - scope.compiler.expects(:add_override).with { |res| res.is_a?(Puppet::Parser::Resource) } - ret = nil - assert_nothing_raised do - ret = ref.evaluate scope - end - - assert_instance_of(Puppet::Parser::Resource, ret, "Did not return override") - end - - def test_collection - scope = mkscope - - coll = nil - assert_nothing_raised do - coll = AST::Collection.new(:type => "file", :form => :virtual) - end - - assert_instance_of(AST::Collection, coll) - - ret = nil - assert_nothing_raised do - ret = coll.evaluate scope - end - - assert_instance_of(Puppet::Parser::Collector, ret) - - # Now make sure we get it back from the scope - colls = scope.compiler.instance_variable_get("@collections") - assert_equal([ret], colls, "Did not store collector in config's collection list") - end -end diff --git a/test/language/functions.rb b/test/language/functions.rb deleted file mode 100755 index 2810b123a..000000000 --- a/test/language/functions.rb +++ /dev/null @@ -1,540 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../lib/puppettest') - -require 'puppet' -require 'puppet/parser/parser' -require 'puppettest' -require 'puppettest/resourcetesting' - -class TestLangFunctions < Test::Unit::TestCase - include PuppetTest::ParserTesting - include PuppetTest::ResourceTesting - def test_functions - Puppet::Node::Environment.stubs(:current).returns nil - assert_nothing_raised do - - Puppet::Parser::AST::Function.new( - - :name => "fakefunction", - - :arguments => AST::ASTArray.new( - :children => [nameobj("avalue")] - ) - ) - end - - assert_raise(Puppet::ParseError) do - - func = Puppet::Parser::AST::Function.new( - - :name => "fakefunction", - - :arguments => AST::ASTArray.new( - :children => [nameobj("avalue")] - ) - ) - func.evaluate(mkscope) - end - - assert_nothing_raised do - Puppet::Parser::Functions.newfunction(:fakefunction, :type => :rvalue) do |input| - return "output #{input[0]}" - end - end - - func = nil - assert_nothing_raised do - - func = Puppet::Parser::AST::Function.new( - - :name => "fakefunction", - :ftype => :rvalue, - - :arguments => AST::ASTArray.new( - :children => [nameobj("avalue")] - ) - ) - end - - scope = mkscope - val = nil - assert_nothing_raised do - val = func.evaluate(scope) - end - - assert_equal("output avalue", val) - end - - def test_taggedfunction - scope = mkscope - scope.resource.tag("yayness") - - # Make sure the ast stuff does what it's supposed to - {"yayness" => true, "booness" => false}.each do |tag, retval| - func = taggedobj(tag, :rvalue) - - val = nil - assert_nothing_raised do - val = func.evaluate(scope) - end - - assert_equal(retval, val, "'tagged' returned #{val} for #{tag}") - end - - # Now make sure we correctly get tags. - scope.resource.tag("resourcetag") - assert(scope.function_tagged("resourcetag"), "tagged function did not catch resource tags") - scope.compiler.catalog.tag("configtag") - assert(scope.function_tagged("configtag"), "tagged function did not catch catalog tags") - end - - def test_failfunction - func = nil - assert_nothing_raised do - - func = Puppet::Parser::AST::Function.new( - - :name => "fail", - :ftype => :statement, - - :arguments => AST::ASTArray.new( - :children => [stringobj("this is a failure"), stringobj("and another")] - ) - ) - end - - scope = mkscope - val = nil - assert_raise(Puppet::ParseError) do - val = func.evaluate(scope) - end - end - - def test_multipletemplates - Dir.mkdir(Puppet[:templatedir]) - onep = File.join(Puppet[:templatedir], "one") - twop = File.join(Puppet[:templatedir], "two") - - File.open(onep, "w") do |f| - f.puts "<%- if @one.nil? then raise '@one undefined' end -%>template <%= @one %>" - end - - File.open(twop, "w") do |f| - f.puts "template <%= @two %>" - end - func = nil - assert_nothing_raised do - - func = Puppet::Parser::AST::Function.new( - - :name => "template", - :ftype => :rvalue, - - :arguments => AST::ASTArray.new( - :children => [stringobj("one"), stringobj("two")] - ) - ) - end - ast = varobj("output", func) - - scope = mkscope - - # Test that our manual exception throw fails the parse - assert_raise(Puppet::ParseError) do - ast.evaluate(scope) - end - - # Test that our use of an undefined instance variable does not throw - # an exception, but only safely continues. - scope['one'] = "One" - assert_nothing_raised do - ast.evaluate(scope) - end - - # Ensure that we got the output we expected from that evaluation. - assert_equal("template One\ntemplate \n", scope['output'], "Undefined template variables do not raise exceptions") - - # Now, fill in the last variable and make sure the whole thing - # evaluates correctly. - scope['two'] = "Two" - scope.unsetvar("output") - assert_nothing_raised do - ast.evaluate(scope) - end - - - assert_equal( - "template One\ntemplate Two\n", scope['output'], - - "Templates were not handled correctly") - end - - # Now make sure we can fully qualify files, and specify just one - def test_singletemplates - template = tempfile - - File.open(template, "w") do |f| - f.puts "template <%= @yay.nil?() ? raise('yay undefined') : @yay %>" - end - - func = nil - assert_nothing_raised do - - func = Puppet::Parser::AST::Function.new( - - :name => "template", - :ftype => :rvalue, - - :arguments => AST::ASTArray.new( - :children => [stringobj(template)] - ) - ) - end - ast = varobj("output", func) - - scope = mkscope - assert_raise(Puppet::ParseError) do - ast.evaluate(scope) - end - - scope['yay'] = "this is yay" - - assert_nothing_raised do - ast.evaluate(scope) - end - - - assert_equal( - "template this is yay\n", scope['output'], - - "Templates were not handled correctly") - - end - - # Make sure that legacy template variable access works as expected. - def test_legacyvariables - template = tempfile - - File.open(template, "w") do |f| - f.puts "template <%= deprecated %>" - end - - func = nil - assert_nothing_raised do - - func = Puppet::Parser::AST::Function.new( - - :name => "template", - :ftype => :rvalue, - - :arguments => AST::ASTArray.new( - :children => [stringobj(template)] - ) - ) - end - ast = varobj("output", func) - - # Verify that we get an exception using old-style accessors. - scope = mkscope - assert_raise(Puppet::ParseError) do - ast.evaluate(scope) - end - - # Verify that we evaluate and return their value correctly. - scope["deprecated"] = "deprecated value" - assert_nothing_raised do - ast.evaluate(scope) - end - - - assert_equal( - "template deprecated value\n", scope['output'], - - "Deprecated template variables were not handled correctly") - end - - # Make sure that problems with kernel method visibility still exist. - def test_kernel_module_shadows_deprecated_var_lookup - template = tempfile - File.open(template, "w").puts("<%= binding %>") - - func = nil - assert_nothing_raised do - - func = Puppet::Parser::AST::Function.new( - - :name => "template", - :ftype => :rvalue, - - :arguments => AST::ASTArray.new( - :children => [stringobj(template)] - ) - ) - end - ast = varobj("output", func) - - # Verify that Kernel methods still shadow deprecated variable lookups. - scope = mkscope - assert_nothing_raised("No exception for Kernel shadowed variable names") do - ast.evaluate(scope) - end - end - - def test_tempatefunction_cannot_see_scopes - template = tempfile - - File.open(template, "w") do |f| - f.puts "<%= lookupvar('myvar') %>" - end - - func = nil - assert_nothing_raised do - - func = Puppet::Parser::AST::Function.new( - - :name => "template", - :ftype => :rvalue, - - :arguments => AST::ASTArray.new( - :children => [stringobj(template)] - ) - ) - end - ast = varobj("output", func) - - scope = mkscope - scope['myvar'] = "this is yayness" - assert_raise(Puppet::ParseError) do - ast.evaluate(scope) - end - end - - def test_template_reparses - template = tempfile - - File.open(template, "w") do |f| - f.puts "original text" - end - - file = tempfile - - Puppet[:code] = %{file { "#{file}": content => template("#{template}") }} - Puppet[:environment] = "yay" - node = mknode - node.stubs(:environment).returns Puppet::Node::Environment.new - - Puppet[:environment] = "yay" - - catalog = Puppet::Parser::Compiler.new(node).compile - - version = catalog.version - - fileobj = catalog.vertices.find { |r| r.title == file } - assert(fileobj, "File was not in catalog") - - - assert_equal( - "original text\n", fileobj["content"], - - "Template did not work") - - Puppet[:filetimeout] = -5 - # Have to sleep because one second is the fs's time granularity. - sleep(1) - - # Now modify the template - File.open(template, "w") do |f| - f.puts "new text" - end - - newversion = Puppet::Parser::Compiler.new(node).compile.version - - assert(version != newversion, "Parse date did not change") - end - - def test_template_defined_vars - template = tempfile - - File.open(template, "w") do |f| - f.puts "template <%= @yayness %>" - end - - func = nil - assert_nothing_raised do - - func = Puppet::Parser::AST::Function.new( - - :name => "template", - :ftype => :rvalue, - - :arguments => AST::ASTArray.new( - :children => [stringobj(template)] - ) - ) - end - ast = varobj("output", func) - - { - "" => "", - false => "false", - }.each do |string, value| - scope = mkscope - scope['yayness'] = string - assert_equal(scope['yayness'], string, "did not correctly evaluate '#{string}'") - - assert_nothing_raised("An empty string was not a valid variable value") do - ast.evaluate(scope) - end - - assert_equal( - "template #{value}\n", scope['output'], - "#{string.inspect} did not get evaluated correctly") - end - end - - def test_autoloading_functions - #assert_equal(false, Puppet::Parser::Functions.function(:autofunc), - # "Got told autofunc already exists") - - dir = tempfile - $LOAD_PATH << dir - newpath = File.join(dir, "puppet", "parser", "functions") - FileUtils.mkdir_p(newpath) - - File.open(File.join(newpath, "autofunc.rb"), "w") { |f| - f.puts %{ - Puppet::Parser::Functions.newfunction(:autofunc, :type => :rvalue) do |vals| - Puppet.wanring vals.inspect - end - } - } - Puppet::Node::Environment.stubs(:current).returns nil - obj = nil - assert_nothing_raised { - obj = Puppet::Parser::Functions.function(:autofunc) - } - - assert(obj, "Did not autoload function") - assert(Puppet::Parser::Functions.environment_module.method_defined?(:function_autofunc), "Did not set function correctly") - end - - def test_search - scope = mkscope - - fun = scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "yay::ness") - foo = scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "foo::bar") - - search = Puppet::Parser::Functions.function(:search) - scope.function_search(["foo", "yay"]) - - ffun = ffoo = nil - assert_nothing_raised("Search path change did not work") do - ffun = scope.find_definition("ness") - ffoo = scope.find_definition('bar') - end - - assert(ffun, "Could not find definition in 'fun' namespace") - assert(ffoo, "Could not find definition in 'foo' namespace") - end - - def test_include - scope = mkscope - parser = mkparser - - include = Puppet::Parser::Functions.function(:include) - - assert_raise(Puppet::Error, "did not throw error on missing class") do - scope.function_include("nosuchclass") - end - - scope.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "myclass", {}) - - scope.compiler.expects(:evaluate_classes).with(%w{myclass otherclass}, scope, false).returns(%w{myclass otherclass}) - - assert_nothing_raised do - scope.function_include(["myclass", "otherclass"]) - end - end - - def test_file - parser = mkparser - scope = mkscope(:parser => parser) - - file = Puppet::Parser::Functions.function(:file) - - file1 = tempfile - file2 = tempfile - file3 = tempfile - - File.open(file2, "w") { |f| f.puts "yaytest" } - - val = nil - assert_nothing_raised("Failed to call file with one arg") do - val = scope.function_file([file2]) - end - - assert_equal("yaytest\n", val, "file() failed") - - assert_nothing_raised("Failed to call file with two args") do - val = scope.function_file([file1, file2]) - end - - assert_equal("yaytest\n", val, "file() failed") - - assert_raise(Puppet::ParseError, "did not fail when files are missing") do - val = scope.function_file([file1, file3]) - end - end - - def test_generate - command = tempfile - sh = %x{which sh} - File.open(command, "w") do |f| - f.puts %{#!#{sh} - if [ -n "$1" ]; then - echo "yay-$1" - else - echo yay - fi - } - end - File.chmod(0755, command) - assert_equal("yay\n", %x{#{command}}, "command did not work") - assert_equal("yay-foo\n", %x{#{command} foo}, "command did not work") - - Puppet::Node::Environment.stubs(:current).returns nil - generate = Puppet::Parser::Functions.function(:generate) - - scope = mkscope - parser = mkparser - - val = nil - assert_nothing_raised("Could not call generator with no args") do - val = scope.function_generate([command]) - end - assert_equal("yay\n", val, "generator returned wrong results") - - assert_nothing_raised("Could not call generator with args") do - val = scope.function_generate([command, "foo"]) - end - assert_equal("yay-foo\n", val, "generator returned wrong results") - - assert_raise(Puppet::ParseError, "Did not fail with an unqualified path") do - val = scope.function_generate([File.basename(command), "foo"]) - end - - assert_raise(Puppet::ParseError, "Did not fail when command failed") do - val = scope.function_generate([%x{which touch}.chomp, "/this/dir/does/not/exist"]) - end - - fake = File.join(File.dirname(command), "..") - dir = File.dirname(command) - dirname = File.basename(dir) - bad = File.join(dir, "..", dirname, File.basename(command)) - assert_raise(Puppet::ParseError, "Did not fail when command failed") do - val = scope.function_generate([bad]) - end - end -end - diff --git a/test/language/parser.rb b/test/language/parser.rb deleted file mode 100755 index f7e636add..000000000 --- a/test/language/parser.rb +++ /dev/null @@ -1,738 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../lib/puppettest') - -require 'mocha' -require 'puppet' -require 'puppet/parser/parser' -require 'puppettest' -require 'puppettest/support/utils' - -class TestParser < Test::Unit::TestCase - include PuppetTest - include PuppetTest::ParserTesting - include PuppetTest::Support::Utils - def setup - super - #@lexer = Puppet::Parser::Lexer.new - end - - def teardown - super - Puppet::Node::Environment.clear - end - - def test_each_file - textfiles { |file| - Puppet::Node::Environment.clear - parser = mkparser - Puppet.debug("parsing #{file}") if __FILE__ == $0 - assert_nothing_raised { - parser.file = file - parser.parse - } - } - end - - def test_failers - failers { |file| - parser = mkparser - Puppet.debug("parsing failer #{file}") if __FILE__ == $0 - assert_raise(Puppet::ParseError, Puppet::Error, "Did not fail while parsing #{file}") { - Puppet[:manifest] = file - config = mkcompiler(parser) - config.compile - #ast.hostclass("").evaluate config.topscope - } - } - end - - def test_arrayrvalues - parser = mkparser - ret = nil - file = tempfile - assert_nothing_raised { - parser.string = "file { \"#{file}\": mode => [755, 640] }" - } - - assert_nothing_raised { - ret = parser.parse - } - end - - def test_arrayrvalueswithtrailingcomma - parser = mkparser - ret = nil - file = tempfile - assert_nothing_raised { - parser.string = "file { \"#{file}\": mode => [755, 640,] }" - } - - assert_nothing_raised { - ret = parser.parse - } - end - - def mkmanifest(file) - name = File.join(tmpdir, "file#{rand(100)}") - @@tmpfiles << name - - File.open(file, "w") { |f| - f.puts "file { \"%s\": ensure => file, mode => 755 }\n" % name - } - end - - def test_importglobbing - basedir = File.join(tmpdir, "importesting") - @@tmpfiles << basedir - Dir.mkdir(basedir) - - subdir = "subdir" - Dir.mkdir(File.join(basedir, subdir)) - manifest = File.join(basedir, "manifest") - File.open(manifest, "w") { |f| - f.puts "import \"%s/*\"" % subdir - } - - 4.times { |i| - path = File.join(basedir, subdir, "subfile#{i}.pp") - mkmanifest(path) - } - - assert_nothing_raised("Could not parse multiple files") { - parser = mkparser - parser.file = manifest - parser.parse - } - end - - def test_nonexistent_import - basedir = File.join(tmpdir, "importesting") - @@tmpfiles << basedir - Dir.mkdir(basedir) - manifest = File.join(basedir, "manifest") - File.open(manifest, "w") do |f| - f.puts "import \" no such file \"" - end - assert_raise(Puppet::ParseError) { - parser = mkparser - parser.file = manifest - parser.parse - } - end - - def test_trailingcomma - path = tempfile - str = %{file { "#{path}": ensure => file, } - } - - parser = mkparser - parser.string = str - - assert_nothing_raised("Could not parse trailing comma") { - parser.parse - } - end - - def test_importedclasses - imported = tempfile '.pp' - importer = tempfile '.pp' - - made = tempfile - - File.open(imported, "w") do |f| - f.puts %{class foo { file { "#{made}": ensure => file }}} - end - - File.open(importer, "w") do |f| - f.puts %{import "#{imported}"\ninclude foo} - end - - parser = mkparser - parser.file = importer - - # Make sure it parses fine - assert_nothing_raised { - parser.parse - } - - # Now make sure it actually does the work - assert_creates(importer, made) - end - - # Make sure fully qualified and unqualified files can be imported - def test_fqfilesandlocalfiles - dir = tempfile - Dir.mkdir(dir) - importer = File.join(dir, "site.pp") - fullfile = File.join(dir, "full.pp") - localfile = File.join(dir, "local.pp") - - files = [] - - File.open(importer, "w") do |f| - f.puts %{import "#{fullfile}"\ninclude full\nimport "local.pp"\ninclude local} - end - - fullmaker = tempfile - files << fullmaker - - File.open(fullfile, "w") do |f| - f.puts %{class full { file { "#{fullmaker}": ensure => file }}} - end - - localmaker = tempfile - files << localmaker - - File.open(localfile, "w") do |f| - f.puts %{class local { file { "#{localmaker}": ensure => file }}} - end - - parser = mkparser - parser.file = importer - - # Make sure it parses - assert_nothing_raised { - parser.parse - } - - # Now make sure it actually does the work - assert_creates(importer, *files) - end - - # Make sure the parser adds '.pp' when necessary - def test_addingpp - dir = tempfile - Dir.mkdir(dir) - importer = File.join(dir, "site.pp") - localfile = File.join(dir, "local.pp") - - files = [] - - File.open(importer, "w") do |f| - f.puts %{import "local"\ninclude local} - end - - file = tempfile - files << file - - File.open(localfile, "w") do |f| - f.puts %{class local { file { "#{file}": ensure => file }}} - end - - parser = mkparser - parser.file = importer - - assert_nothing_raised { - parser.parse - } - end - - # Make sure that file importing changes file relative names. - def test_changingrelativenames - dir = tempfile - Dir.mkdir(dir) - Dir.mkdir(File.join(dir, "subdir")) - top = File.join(dir, "site.pp") - subone = File.join(dir, "subdir/subone") - subtwo = File.join(dir, "subdir/subtwo") - - files = [] - file = tempfile - files << file - - File.open(subone + ".pp", "w") do |f| - f.puts %{class one { file { "#{file}": ensure => file }}} - end - - otherfile = tempfile - files << otherfile - File.open(subtwo + ".pp", "w") do |f| - f.puts %{import "subone"\n class two inherits one { - file { "#{otherfile}": ensure => file } - }} - end - - File.open(top, "w") do |f| - f.puts %{import "subdir/subtwo"} - end - - parser = mkparser - parser.file = top - - assert_nothing_raised { - parser.parse - } - end - - # Defaults are purely syntactical, so it doesn't make sense to be able to - # collect them. - def test_uncollectabledefaults - string = "@Port { protocols => tcp }" - - assert_raise(Puppet::ParseError) { - mkparser.parse(string) - } - end - - # Verify that we can parse collections - def test_collecting - text = "Port <| |>" - parser = mkparser - parser.string = text - - ret = nil - assert_nothing_raised { - ret = parser.parse - } - - ret.code.each do |obj| - assert_instance_of(AST::Collection, obj) - end - end - - def test_emptyfile - file = tempfile - File.open(file, "w") do |f| - f.puts %{} - end - parser = mkparser - parser.file = file - assert_nothing_raised { - parser.parse - } - end - - def test_multiple_nodes_named - file = tempfile - other = tempfile - - File.open(file, "w") do |f| - f.puts %{ -node nodeA, nodeB { - file { "#{other}": ensure => file } - -} -} - end - - parser = mkparser - parser.file = file - ast = nil - assert_nothing_raised { - ast = parser.parse - } - end - - def test_emptyarrays - str = %{$var = []\n} - - parser = mkparser - parser.string = str - - # Make sure it parses fine - assert_nothing_raised { - parser.parse - } - end - - # Make sure function names aren't reserved words. - def test_functionnamecollision - str = %{tag yayness -tag(rahness) - -file { "/tmp/yayness": - tag => "rahness", - ensure => exists -} -} - parser = mkparser - parser.string = str - - # Make sure it parses fine - assert_nothing_raised { - parser.parse - } - end - - def test_metaparams_in_definition_prototypes - parser = mkparser - - - assert_raise(Puppet::ParseError) { - parser.known_resource_types.import_ast(parser.parse(%{define mydef($schedule) {}}), '') - } - - assert_nothing_raised { - parser.known_resource_types.import_ast(parser.parse(%{define adef($schedule = false) {}}), '') - parser.known_resource_types.import_ast(parser.parse(%{define mydef($schedule = daily) {}}), '') - } - end - - def test_parsingif - parser = mkparser - exec = proc do |val| - %{exec { "/bin/echo #{val}": logoutput => true }} - end - str1 = %{if true { #{exec.call("true")} }} - ret = nil - assert_nothing_raised { - ret = parser.parse(str1).code[0] - } - assert_instance_of(Puppet::Parser::AST::IfStatement, ret) - parser = mkparser - str2 = %{if true { #{exec.call("true")} } else { #{exec.call("false")} }} - ret = parser.parse(str2).code[0] - assert_instance_of(Puppet::Parser::AST::IfStatement, ret) - assert_instance_of(Puppet::Parser::AST::Else, ret.else) - end - - def test_hostclass - parser = mkparser - - assert_nothing_raised { - parser.known_resource_types.import_ast(parser.parse(%{class myclass { class other {} }}), '') - } - assert(parser.hostclass("myclass"), "Could not find myclass") - assert(parser.hostclass("myclass::other"), "Could not find myclass::other") - - assert_nothing_raised { - parser.known_resource_types.import_ast(parser.parse("class base {} - class container { - class deep::sub inherits base {} - }"), '') - } - sub = parser.hostclass("container::deep::sub") - assert(sub, "Could not find sub") - - # Now try it with a parent class being a fq class - assert_nothing_raised { - parser.known_resource_types.import_ast(parser.parse("class container::one inherits container::deep::sub {}"), '') - } - sub = parser.hostclass("container::one") - assert(sub, "Could not find one") - assert_equal("container::deep::sub", sub.parent) - - # Finally, try including a qualified class - assert_nothing_raised("Could not include fully qualified class") { - parser.known_resource_types.import_ast(parser.parse("include container::deep::sub"), '') - } - end - - def test_topnamespace - parser = mkparser - - # Make sure we put the top-level code into a class called "" in - # the "" namespace - parser.initvars - assert_nothing_raised do - parser.known_resource_types.import_ast(parser.parse("Exec { path => '/usr/bin:/usr/sbin' }"), '') - assert_equal("", parser.known_resource_types.hostclass("").name) - assert_equal("", parser.known_resource_types.hostclass("").namespace) - end - end - - # Make sure virtual and exported resources work appropriately. - def test_virtualresources - tests = [:virtual] - if Puppet.features.rails? - catalog_cache_class = Puppet::Resource::Catalog.indirection.cache_class - facts_cache_class = Puppet::Node::Facts.indirection.cache_class - node_cache_class = Puppet::Node.indirection.cache_class - Puppet[:storeconfigs] = true - tests << :exported - end - - tests.each do |form| - parser = mkparser - - if form == :virtual - at = "@" - else - at = "@@" - end - - check = proc do |res, msg| - if res.is_a?(Puppet::Parser::Resource) - txt = res.ref - else - txt = res.class - end - # Real resources get marked virtual when exported - if form == :virtual or res.is_a?(Puppet::Parser::Resource) - assert(res.virtual, "#{msg} #{at}#{txt} is not virtual") - end - if form == :virtual - assert(! res.exported, "#{msg} #{at}#{txt} is exported") - else - assert(res.exported, "#{msg} #{at}#{txt} is not exported") - end - end - - ret = nil - assert_nothing_raised do - parser.known_resource_types.import_ast(parser.parse("#{at}file { '/tmp/testing': owner => root }"), '') - ret = parser.known_resource_types - end - - assert_instance_of(AST::ASTArray, ret.hostclass("").code) - resdef = ret.hostclass("").code[0] - assert_instance_of(AST::Resource, resdef) - assert_instance_of(AST::ASTArray, resdef.instances) - assert_equal(1, resdef.instances.children.length) - assert_equal("/tmp/testing", resdef.instances[0].title.value) - # We always get an astarray back, so... - check.call(resdef, "simple resource") - - # Now let's try it with multiple resources in the same spec - assert_nothing_raised do - parser.known_resource_types.import_ast(parser.parse("#{at}file { ['/tmp/1', '/tmp/2']: owner => root }"), '') - ret = parser.known_resource_types - end - - ret.hostclass("").code[0].each do |res| - assert_instance_of(AST::Resource, res) - check.call(res, "multiresource") - end - end - - ensure - if Puppet.features.rails? - Puppet[:storeconfigs] = false - Puppet::Resource::Catalog.indirection.cache_class = catalog_cache_class - Puppet::Node::Facts.indirection.cache_class = facts_cache_class - Puppet::Node.indirection.cache_class = node_cache_class - end - end - - def test_collections - tests = [:virtual] - if Puppet.features.rails? - catalog_cache_class = Puppet::Resource::Catalog.indirection.cache_class - facts_cache_class = Puppet::Node::Facts.indirection.cache_class - node_cache_class = Puppet::Node.indirection.cache_class - Puppet[:storeconfigs] = true - tests << :exported - end - - tests.each do |form| - Puppet::Node::Environment.clear - parser = mkparser - - if form == :virtual - arrow = "<||>" - else - arrow = "<<||>>" - end - - ret = nil - assert_nothing_raised do - ret = parser.parse("File #{arrow}") - end - - coll = ret.code[0] - assert_instance_of(AST::Collection, coll) - assert_equal(form, coll.form) - end - - ensure - if Puppet.features.rails? - Puppet[:storeconfigs] = false - Puppet::Resource::Catalog.indirection.cache_class = catalog_cache_class - Puppet::Node::Facts.indirection.cache_class = facts_cache_class - Puppet::Node.indirection.cache_class = node_cache_class - end - end - - def test_collectionexpressions - %w{== !=}.each do |oper| - Puppet::Node::Environment.clear - str = "File <| title #{oper} '/tmp/testing' |>" - - parser = mkparser - - res = nil - assert_nothing_raised do - res = parser.parse(str).code[0] - end - - assert_instance_of(AST::Collection, res) - - query = res.query - assert_instance_of(AST::CollExpr, query) - - assert_equal(:virtual, query.form) - assert_equal("title", query.test1.value) - assert_equal("/tmp/testing", query.test2.value) - assert_equal(oper, query.oper) - end - end - - def test_collectionstatements - %w{and or}.each do |joiner| - str = "File <| title == '/tmp/testing' #{joiner} owner == root |>" - - parser = mkparser - - res = nil - assert_nothing_raised do - res = parser.parse(str).code[0] - end - - assert_instance_of(AST::Collection, res) - - query = res.query - assert_instance_of(AST::CollExpr, query) - - assert_equal(joiner, query.oper) - assert_instance_of(AST::CollExpr, query.test1) - assert_instance_of(AST::CollExpr, query.test2) - end - end - - def test_collectionstatements_with_parens - [ - "(title == '/tmp/testing' and owner == root) or owner == wheel", - "(title == '/tmp/testing')" - ].each do |test| - str = "File <| #{test} |>" - parser = mkparser - - res = nil - assert_nothing_raised("Could not parse '#{test}'") do - res = parser.parse(str).code[0] - end - - assert_instance_of(AST::Collection, res) - - query = res.query - assert_instance_of(AST::CollExpr, query) - - #assert_equal(joiner, query.oper) - #assert_instance_of(AST::CollExpr, query.test1) - #assert_instance_of(AST::CollExpr, query.test2) - end - end - - def test_fully_qualified_definitions - parser = mkparser - - types = parser.known_resource_types - assert_nothing_raised("Could not parse fully-qualified definition") { - types.import_ast(parser.parse(%{define one::two { }}), '') - } - assert(parser.definition("one::two"), "Could not find one::two with no namespace") - end - - # #524 - def test_functions_with_no_arguments - parser = mkparser - assert_nothing_raised("Could not parse statement function with no args") { - parser.parse %{tag()} - } - assert_nothing_raised("Could not parse rvalue function with no args") { - parser.parse %{$testing = template()} - } - end - - # #774 - def test_fully_qualified_collection_statement - parser = mkparser - assert_nothing_raised("Could not parse fully qualified collection statement") { - parser.parse %{Foo::Bar <||>} - } - end - - def test_multiple_imports_on_one_line - one = tempfile '.pp' - two = tempfile '.pp' - base = tempfile '.pp' - File.open(one, "w") { |f| f.puts "$var = value" } - File.open(two, "w") { |f| f.puts "$var = value" } - File.open(base, "w") { |f| f.puts "import '#{one}', '#{two}'" } - - parser = mkparser - parser.file = base - - # Importing is logged at debug time. - Puppet::Util::Log.level = :debug - assert_nothing_raised("Parser could not import multiple files at once") do - parser.parse - end - - [one, two].each do |file| - assert(@logs.detect { |l| l.message =~ /importing '#{file}'/}, "did not import #{file}") - end - end - - def test_cannot_assign_qualified_variables - parser = mkparser - assert_raise(Puppet::ParseError, "successfully assigned a qualified variable") do - parser.parse("$one::two = yay") - end - end - - # #629 - undef keyword - def test_undef - parser = mkparser - result = nil - assert_nothing_raised("Could not parse assignment to undef") { - result = parser.parse %{$variable = undef} - } - - main = result.code - children = main.children - assert_instance_of(AST::VarDef, main.children[0]) - assert_instance_of(AST::Undef, main.children[0].value) - end - - # Prompted by #729 -- parsing should not modify the interpreter. - def test_parse - parser = mkparser - - str = "file { '/tmp/yay': ensure => file }\nclass yay {}\nnode foo {}\ndefine bar {}\n" - result = nil - assert_nothing_raised("Could not parse") do - parser.known_resource_types.import_ast(parser.parse(str), '') - result = parser.known_resource_types - end - assert_instance_of(Puppet::Resource::TypeCollection, result, "Did not get a ASTSet back from parsing") - - assert_instance_of(Puppet::Resource::Type, result.hostclass("yay"), "Did not create 'yay' class") - assert_instance_of(Puppet::Resource::Type, result.hostclass(""), "Did not create main class") - assert_instance_of(Puppet::Resource::Type, result.definition("bar"), "Did not create 'bar' definition") - assert_instance_of(Puppet::Resource::Type, result.node("foo"), "Did not create 'foo' node") - end - - def test_namesplit - parser = mkparser - - assert_nothing_raised do - {"base::sub" => %w{base sub}, - "main" => ["", "main"], - "one::two::three::four" => ["one::two::three", "four"], - }.each do |name, ary| - result = parser.namesplit(name) - assert_equal(ary, result, "#{name} split to #{result}") - end - end - end - - # Make sure class, node, and define methods are case-insensitive - def test_structure_case_insensitivity - parser = mkparser - - result = nil - assert_nothing_raised do - parser.known_resource_types.import_ast(parser.parse("class yayness { }"), '') - result = parser.known_resource_types.hostclass('yayness') - end - assert_equal(result, parser.find_hostclass("", "yayNess")) - - assert_nothing_raised do - parser.known_resource_types.import_ast(parser.parse("define funtest { }"), '') - result = parser.known_resource_types.definition('funtest') - end - assert_equal(result, parser.find_definition("", "fUntEst"), "#{"fUntEst"} was not matched") - end -end diff --git a/test/language/scope.rb b/test/language/scope.rb deleted file mode 100755 index c80178e7b..000000000 --- a/test/language/scope.rb +++ /dev/null @@ -1,266 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../lib/puppettest') - -require 'mocha' -require 'puppettest' -require 'puppettest/parsertesting' -require 'puppettest/resourcetesting' - -# so, what kind of things do we want to test? - -# we don't need to test function, since we're confident in the -# library tests. We do, however, need to test how things are actually -# working in the language. - -# so really, we want to do things like test that our ast is correct -# and test whether we've got things in the right scopes - -class TestScope < Test::Unit::TestCase - include PuppetTest::ParserTesting - include PuppetTest::ResourceTesting - - def setup - Puppet::Node::Environment.clear - super - end - - def to_ary(hash) - hash.collect { |key,value| - [key,value] - } - end - - def test_variables - config = mkcompiler - topscope = config.topscope - midscope = config.newscope(topscope) - botscope = config.newscope(midscope) - - scopes = {:top => topscope, :mid => midscope, :bot => botscope} - - # Set a variable in the top and make sure all three can get it - topscope['first'] = 'topval' - scopes.each do |name, scope| - assert_equal("topval", scope['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['second'] = "midval" - assert_nil(scopes[:top]['second'], "Found child var in top scope") - [:mid, :bot].each do |name| - assert_equal("midval", scopes[name]['second'], "Could not find var in #{name}") - end - - # And set something in the bottom, and make sure we only find it there. - botscope['third'] = "botval" - [:top, :mid].each do |name| - assert_nil(scopes[name]['third'], "Found child var in top scope") - end - assert_equal("botval", scopes[:bot]['third'], "Could not find var in bottom scope") - - - # Test that the scopes convert to hash structures correctly. - # For topscope recursive vs non-recursive should be identical - assert_equal(topscope.to_hash(false), topscope.to_hash(true), - "Recursive and non-recursive hash is identical for topscope") - - # Check the variable we expect is present. - assert_equal({"first" => "topval"}, topscope.to_hash, "topscope returns the expected hash of variables") - - # Now, check that midscope does the right thing in all cases. - - assert_equal( - {"second" => "midval"}, - midscope.to_hash(false), - - "midscope non-recursive hash contains only midscope variable") - - assert_equal( - {"first" => "topval", "second" => "midval"}, - midscope.to_hash(true), - - "midscope recursive hash contains topscope variable also") - - # Finally, check the ability to shadow symbols by adding a shadow to - # bottomscope, then checking that we see the right stuff. - botscope['first'] = "shadowval" - - assert_equal( - {"third" => "botval", "first" => "shadowval"}, - botscope.to_hash(false), - - "botscope has the right non-recursive hash") - - assert_equal( - {"third" => "botval", "first" => "shadowval", "second" => "midval"}, - botscope.to_hash(true), - - "botscope values shadow parent scope values") - end - - def test_declarative - # set to declarative - top = mkscope - sub = mkscope(:parent => top) - - assert_nothing_raised { - top['test'] = "value" - } - assert_raise(Puppet::ParseError) { - top['test'] = 'other' - } - assert_nothing_raised { - top['other'] = 'later' - } - assert_raise(Puppet::ParseError) { - top['other'] = 'yeehaw' - } - end - - def test_parent - config = mkcompiler - top = config.topscope - - # Make a subscope - sub = config.newscope(top) - - assert_equal(top, sub.parent, "Did not find parent scope correctly") - assert_equal(top, sub.parent, "Did not find parent scope on second call") - end - - # Make sure we know what we consider to be truth. - def test_truth - - assert_equal( - true, Puppet::Parser::Scope.true?("a string"), - - "Strings not considered true") - - assert_equal( - true, Puppet::Parser::Scope.true?(true), - - "True considered true") - - assert_equal( - false, Puppet::Parser::Scope.true?(""), - - "Empty strings considered true") - - assert_equal( - false, Puppet::Parser::Scope.true?(false), - - "false considered true") - - assert_equal( - false, Puppet::Parser::Scope.true?(:undef), - - "undef considered true") - end - - def test_virtual_definitions_do_not_get_evaluated - parser = mkparser - config = mkcompiler - - # Create a default source - parser.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "") - config.topscope.source = parser.known_resource_types.hostclass("") - - # And a scope resource - scope_res = Puppet::Parser::Resource.new(:file, "/file", :scope => config.topscope) - config.topscope.resource = scope_res - - args = AST::ASTArray.new( - :children => [nameobj("arg")] - ) - - # Create a top-level define - parser.known_resource_types.add Puppet::Resource::Type.new(:definition, "one", :arguments => [%w{arg}], - :code => AST::ASTArray.new( - :children => [ - resourcedef("file", "/tmp", {"owner" => varref("arg")}) - ] - )) - - # create a resource that calls our third define - obj = resourcedef("one", "boo", {"arg" => "parentfoo"}) - - # And mark it as virtual - obj.virtual = true - - # And then evaluate it - obj.evaluate config.topscope - - # And run the loop. - config.send(:evaluate_generators) - - %w{File}.each do |type| - objects = config.resources.find_all { |r| r.type == type and r.virtual } - - assert(objects.empty?, "Virtual define got evaluated") - end - end - - if defined? ::ActiveRecord - # Verify that we can both store and collect an object in the same - # run, whether it's in the same scope as a collection or a different - # scope. - def test_storeandcollect - catalog_cache_class = Puppet::Resource::Catalog.indirection.cache_class - facts_cache_class = Puppet::Node::Facts.indirection.cache_class - node_cache_class = Puppet::Node.indirection.cache_class - Puppet[:storeconfigs] = true - Puppet::Rails.init - sleep 1 - children = [] - Puppet[:code] = " -class yay { - @@host { myhost: ip => \"192.168.0.2\" } -} -include yay -@@host { puppet: ip => \"192.168.0.3\" } -Host <<||>>" - - config = nil - # We run it twice because we want to make sure there's no conflict - # if we pull it up from the database. - node = mknode - node.merge "hostname" => node.name - 2.times { |i| - catalog = Puppet::Parser::Compiler.new(node).compile - assert_instance_of(Puppet::Parser::Resource, catalog.resource(:host, "puppet")) - assert_instance_of(Puppet::Parser::Resource, catalog.resource(:host, "myhost")) - } - ensure - Puppet[:storeconfigs] = false - Puppet::Resource::Catalog.indirection.cache_class = catalog_cache_class - Puppet::Node::Facts.indirection.cache_class = facts_cache_class - Puppet::Node.indirection.cache_class = node_cache_class - end - else - $stderr.puts "No ActiveRecord -- skipping collection tests" - end - - def test_namespaces - scope = mkscope - - - assert_equal( - [""], scope.namespaces, - - "Started out with incorrect namespaces") - assert_nothing_raised { scope.add_namespace("fun::test") } - assert_equal(["fun::test"], scope.namespaces, "Did not add namespace correctly") - assert_nothing_raised { scope.add_namespace("yay::test") } - assert_equal(["fun::test", "yay::test"], scope.namespaces, "Did not add extra namespace correctly") - end - - # #629 - undef should be "" or :undef - def test_lookupvar_with_undef - scope = mkscope - - scope['testing'] = :undef - assert_equal(:undef, scope['testing'], "undef was not returned as :undef") - end -end - diff --git a/test/language/snippets.rb b/test/language/snippets.rb deleted file mode 100755 index 75d86ca76..000000000 --- a/test/language/snippets.rb +++ /dev/null @@ -1,503 +0,0 @@ -#!/usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../lib/puppettest') - -require 'puppet' -require 'puppet/parser/parser' -require 'puppettest' - -class TestSnippets < Test::Unit::TestCase - include PuppetTest - - def setup - super - @file = Puppet::Type.type(:file) - Facter.stubs(:to_hash).returns({}) - Facter.stubs(:value).returns("whatever") - end - - def self.snippetdir - PuppetTest.datadir "snippets" - end - - def assert_file(path, msg = nil) - unless file = @catalog.resource(:file, path) - msg ||= "Could not find file #{path}" - raise msg - end - end - - def assert_not_file(path, msg = nil) - if file = @catalog.resource(:file, path) - msg ||= "File #{path} exists!" - raise msg - end - end - - def assert_mode_equal(mode, path) - if mode.is_a? Integer - mode = mode.to_s(8) - end - unless file = @catalog.resource(:file, path) - raise "Could not find file #{path}" - end - - unless mode == file.should(:mode) - raise "Mode for %s is incorrect: %o vs %o" % [path, mode, file.should(:mode)] - end - end - - def snippet(name) - File.join(self.class.snippetdir, name) - end - - def file2ast(file) - parser = Puppet::Parser::Parser.new - parser.file = file - ast = parser.parse - - ast - end - - def snippet2ast(text) - parser = Puppet::Parser::Parser.new - parser.string = text - ast = parser.parse - - ast - end - - def ast2scope(ast) - scope = Puppet::Parser::Scope.new - ast.evaluate(scope) - - scope - end - - def snippet2scope(snippet) - ast = snippet2ast(snippet) - scope = ast2scope(ast) - end - - def properties(type) - properties = type.validproperties - end - - def metaparams(type) - mparams = [] - Puppet::Type.eachmetaparam { |param| - mparams.push param - } - - mparams - end - - def params(type) - params = [] - type.parameters.each { |name,property| - params.push name - } - - params - end - - def randthing(thing,type) - list = self.send(thing,type) - list[rand(list.length)] - end - - def randeach(type) - [:properties, :metaparams, :parameters].collect { |thing| - randthing(thing,type) - } - end - - @@snippets = { - true => [ - %{File { mode => 755 }} - ], - } - - def disabled_test_defaults - Puppet::Type.eachtype { |type| - next if type.name == :puppet or type.name == :component - - rands = randeach(type) - - name = type.name.to_s.capitalize - - [0..1, 0..2].each { |range| - params = rands[range] - paramstr = params.collect { |param| - "#{param} => fake" - }.join(", ") - - str = "#{name} { #{paramstr} }" - - scope = nil - assert_nothing_raised { - scope = snippet2scope(str) - } - - defaults = nil - assert_nothing_raised { - defaults = scope.lookupdefaults(name) - } - - p defaults - - params.each { |param| - puts "#{name} => '#{param}'" - assert(defaults.include?(param)) - } - } - } - end - - # this is here in case no tests get defined; otherwise we get a warning - def test_nothing - end - - def snippet_filecreate - %w{a b c d}.each { |letter| - path = "/tmp/create#{letter}test" - assert_file(path) - assert_mode_equal(0755, path) if %w{a b}.include?(letter) - } - end - - def snippet_simpledefaults - path = "/tmp/defaulttest" - assert_file(path) - assert_mode_equal(0755, path) - end - - def snippet_simpleselector - files = %w{a b c d}.collect { |letter| - path = "/tmp/snippetselect#{letter}test" - assert_file(path) - assert_mode_equal(0755, path) - } - end - - def snippet_classpathtest - path = "/tmp/classtest" - - file = @catalog.resource(:file, path) - assert(file, "did not create file #{path}") - - assert_equal( "/Stage[main]/Testing/Mytype[componentname]/File[/tmp/classtest]", file.path) - end - - def snippet_argumentdefaults - path1 = "/tmp/argumenttest1" - path2 = "/tmp/argumenttest2" - - file1 = @catalog.resource(:file, path1) - file2 = @catalog.resource(:file, path2) - - assert_file(path1) - assert_mode_equal(0755, path1) - - assert_file(path2) - assert_mode_equal(0644, path2) - end - - def snippet_casestatement - paths = %w{ - /tmp/existsfile - /tmp/existsfile2 - /tmp/existsfile3 - /tmp/existsfile4 - /tmp/existsfile5 - /tmp/existsfile6 - } - - paths.each { |path| - file = @catalog.resource(:file, path) - assert(file, "File #{path} is missing") - assert_mode_equal(0755, path) - } - end - - def snippet_implicititeration - paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration#{l}test" } - - paths.each { |path| - file = @catalog.resource(:file, path) - assert_file(path) - assert_mode_equal(0755, path) - } - end - - def snippet_multipleinstances - paths = %w{a b c}.collect { |l| "/tmp/multipleinstances#{l}" } - - paths.each { |path| - assert_file(path) - assert_mode_equal(0755, path) - - } - end - - def snippet_namevartest - file = "/tmp/testfiletest" - dir = "/tmp/testdirtest" - assert_file(file) - assert_file(dir) - assert_equal(:directory, @catalog.resource(:file, dir).should(:ensure), "Directory is not set to be a directory") - end - - def snippet_scopetest - file = "/tmp/scopetest" - assert_file(file) - assert_mode_equal(0755, file) - end - - def snippet_selectorvalues - nums = %w{1 2 3 4 5 6 7} - files = nums.collect { |n| - "/tmp/selectorvalues#{n}" - } - - files.each { |f| - assert_file(f) - assert_mode_equal(0755, f) - } - end - - def snippet_singleselector - nums = %w{1 2 3} - files = nums.collect { |n| - "/tmp/singleselector#{n}" - } - - files.each { |f| - assert_file(f) - assert_mode_equal(0755, f) - } - end - - def snippet_falsevalues - file = "/tmp/falsevaluesfalse" - assert_file(file) - end - - def disabled_snippet_classargtest - [1,2].each { |num| - file = "/tmp/classargtest#{num}" - assert_file(file) - assert_mode_equal(0755, file) - } - end - - def snippet_classheirarchy - [1,2,3].each { |num| - file = "/tmp/classheir#{num}" - assert_file(file) - assert_mode_equal(0755, file) - } - end - - def snippet_singleary - [1,2,3,4].each { |num| - file = "/tmp/singleary#{num}" - assert_file(file) - } - end - - def snippet_classincludes - [1,2,3].each { |num| - file = "/tmp/classincludes#{num}" - assert_file(file) - assert_mode_equal(0755, file) - } - end - - def snippet_componentmetaparams - ["/tmp/component1", "/tmp/component2"].each { |file| - assert_file(file) - } - end - - def snippet_aliastest - %w{/tmp/aliastest /tmp/aliastest2 /tmp/aliastest3}.each { |file| - assert_file(file) - } - end - - def snippet_singlequote - { 1 => 'a $quote', - 2 => 'some "\yayness\"' - }.each { |count, str| - path = "/tmp/singlequote#{count}" - assert_file(path) - assert_equal(str, @catalog.resource(:file, path).parameter(:content).actual_content) - } - end - - # There's no way to actually retrieve the list of classes from the - # transaction. - def snippet_tag - end - - # Make sure that set tags are correctly in place, yo. - def snippet_tagged - tags = {"testing" => true, "yayness" => false, - "both" => false, "bothtrue" => true, "define" => true} - - tags.each do |tag, retval| - assert_file("/tmp/tagged#{tag}#{retval.to_s}") - end - end - - def snippet_defineoverrides - file = "/tmp/defineoverrides1" - assert_file(file) - assert_mode_equal(0755, file) - end - - def snippet_deepclassheirarchy - 5.times { |i| - i += 1 - file = "/tmp/deepclassheir#{i}" - assert_file(file) - } - end - - def snippet_emptyclass - # There's nothing to check other than that it works - end - - def snippet_emptyexec - assert(@catalog.resource(:exec, "touch /tmp/emptyexectest"), "Did not create exec") - end - - def snippet_multisubs - path = "/tmp/multisubtest" - assert_file(path) - file = @catalog.resource(:file, path) - assert_equal("{md5}5fbef65269a99bddc2106251dd89b1dc", file.should(:content), "sub2 did not override content") - assert_mode_equal(0755, path) - end - - def snippet_collection - assert_file("/tmp/colltest1") - assert_nil(@catalog.resource(:file, "/tmp/colltest2"), "Incorrectly collected file") - end - - def snippet_virtualresources - %w{1 2 3 4}.each do |num| - assert_file("/tmp/virtualtest#{num}") - end - end - - def snippet_componentrequire - %w{1 2}.each do |num| - - assert_file( - "/tmp/testing_component_requires#{num}", - - "#{num} does not exist") - end - end - - def snippet_realize_defined_types - assert_file("/tmp/realize_defined_test1") - assert_file("/tmp/realize_defined_test2") - end - - def snippet_collection_within_virtual_definitions - assert_file("/tmp/collection_within_virtual_definitions1_foo.txt") - assert_file("/tmp/collection_within_virtual_definitions2_foo2.txt") - end - - def snippet_fqparents - assert_file("/tmp/fqparent1", "Did not make file from parent class") - assert_file("/tmp/fqparent2", "Did not make file from subclass") - end - - def snippet_fqdefinition - assert_file("/tmp/fqdefinition", "Did not make file from fully-qualified definition") - end - - def snippet_subclass_name_duplication - assert_file("/tmp/subclass_name_duplication1", "Did not make first file from duplicate subclass names") - assert_file("/tmp/subclass_name_duplication2", "Did not make second file from duplicate subclass names") - end - - def snippet_funccomma - assert_file("/tmp/funccomma1", "Did not make first file from trailing function comma") - assert_file("/tmp/funccomma2", "Did not make second file from trailing function comma") - end - - def snippet_arraytrailingcomma - assert_file("/tmp/arraytrailingcomma1", "Did not make first file from array") - assert_file("/tmp/arraytrailingcomma2", "Did not make second file from array") - end - - def snippet_multipleclass - assert_file("/tmp/multipleclassone", "one") - assert_file("/tmp/multipleclasstwo", "two") - end - - def snippet_multilinecomments - assert_not_file("/tmp/multilinecomments","Did create a commented resource"); - end - - def snippet_collection_override - path = "/tmp/collection" - assert_file(path) - assert_mode_equal(0600, path) - end - - def snippet_ifexpression - assert_file("/tmp/testiftest","if test"); - end - - def snippet_hash - assert_file("/tmp/myhashfile1","hash test 1"); - assert_file("/tmp/myhashfile2","hash test 2"); - assert_file("/tmp/myhashfile3","hash test 3"); - assert_file("/tmp/myhashfile4","hash test 4"); - end - - # Iterate across each of the snippets and create a test. - Dir.entries(snippetdir).sort.each { |file| - next if file =~ /^\./ - - - mname = "snippet_" + file.sub(/\.pp$/, '') - if self.method_defined?(mname) - #eval("alias #{testname} #{mname}") - testname = ("test_#{mname}").intern - self.send(:define_method, testname) { - Puppet[:manifest] = snippet(file) - facts = { - "hostname" => "testhost", - "domain" => "domain.com", - "ipaddress" => "127.0.0.1", - "fqdn" => "testhost.domain.com" - } - - node = Puppet::Node.new("testhost") - node.merge(facts) - - catalog = nil - assert_nothing_raised("Could not compile catalog") { - catalog = Puppet::Resource::Catalog.indirection.find(node) - } - - assert_nothing_raised("Could not convert catalog") { - catalog = catalog.to_ral - } - - @catalog = catalog - assert_nothing_raised { - self.send(mname) - } - } - mname = mname.intern - end - } -end