diff --git a/lib/puppet/indirector/terminus.rb b/lib/puppet/indirector/terminus.rb index a0623b284..3015c8a37 100644 --- a/lib/puppet/indirector/terminus.rb +++ b/lib/puppet/indirector/terminus.rb @@ -1,178 +1,179 @@ require 'puppet/indirector' require 'puppet/indirector/indirection' require 'puppet/util/instance_loader' # A simple class that can function as the base class for indirected types. class Puppet::Indirector::Terminus require 'puppet/util/docs' extend Puppet::Util::Docs class << self include Puppet::Util::InstanceLoader attr_accessor :name, :terminus_type attr_reader :abstract_terminus, :indirection # Are we an abstract terminus type, rather than an instance with an # associated indirection? def abstract_terminus? abstract_terminus end # Convert a constant to a short name. def const2name(const) const.sub(/^[A-Z]/) { |i| i.downcase }.gsub(/[A-Z]/) { |i| "_" + i.downcase }.intern end # Look up the indirection if we were only provided a name. def indirection=(name) if name.is_a?(Puppet::Indirector::Indirection) @indirection = name elsif ind = Puppet::Indirector::Indirection.instance(name) @indirection = ind else raise ArgumentError, "Could not find indirection instance %s for %s" % [name, self.name] end end def indirection_name @indirection.name end # Register our subclass with the appropriate indirection. # This follows the convention that our terminus is named after the # indirection. def inherited(subclass) longname = subclass.to_s if longname =~ /# 0 indirection_name = names.pop.sub(/^[A-Z]/) { |i| i.downcase }.gsub(/[A-Z]/) { |i| "_" + i.downcase }.intern if indirection_name == "" or indirection_name.nil? raise Puppet::DevError, "Could not discern indirection model from class constant" end # This will throw an exception if the indirection instance cannot be found. # Do this last, because it also registers the terminus type with the indirection, # which needs the above information. subclass.indirection = indirection_name # And add this instance to the instance hash. Puppet::Indirector::Terminus.register_terminus_class(subclass) end # Mark that this instance is abstract. def mark_as_abstract_terminus @abstract_terminus = true end def model indirection.model end # Convert a short name to a constant. def name2const(name) name.to_s.capitalize.sub(/_(.)/) { |i| $1.upcase } end # Register a class, probably autoloaded. def register_terminus_class(klass) setup_instance_loading klass.indirection_name instance_hash(klass.indirection_name)[klass.name] = klass end # Return a terminus by name, using the autoloader. def terminus_class(indirection_name, terminus_type) setup_instance_loading indirection_name loaded_instance(indirection_name, terminus_type) end # Return all terminus classes for a given indirection. def terminus_classes(indirection_name) setup_instance_loading indirection_name # Load them all. instance_loader(indirection_name).loadall # And return the list of names. loaded_instances(indirection_name) end private def setup_instance_loading(type) unless instance_loading?(type) instance_load type, "puppet/indirector/%s" % type end end end # Do we have an update for this object? This compares the provided version # to our version, and returns true if our version is at least as high # as the asked-about version. def has_most_recent?(key, vers) raise Puppet::DevError.new("Cannot check update status when no 'version' method is defined") unless respond_to?(:version) if existing_version = version(key) #puts "%s fresh: %s (%s vs %s)" % [self.name, (existing_version.to_f >= vers.to_f).inspect, existing_version.to_f, vers.to_f] existing_version.to_f >= vers.to_f else false end end def indirection self.class.indirection end def initialize if self.class.abstract_terminus? raise Puppet::DevError, "Cannot create instances of abstract terminus types" end end def model self.class.model end def name self.class.name end def terminus_type self.class.terminus_type end # Provide a default method for retrieving an instance's version. # By default, just find the resource and get its version. Individual # terminus types can override this method to provide custom definitions of # 'versions'. def version(name) raise Puppet::DevError.new("Cannot retrieve an instance's version without a :find method") unless respond_to?(:find) if instance = find(name) instance.version else nil end end end diff --git a/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb b/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb index 3152c1bda..e2f3d4728 100644 --- a/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb +++ b/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb @@ -1,39 +1,43 @@ dir = File.expand_path(File.dirname(__FILE__)) [ "#{dir}/../../lib", "#{dir}/../../test/lib"].each do |dir| fulldir = File.expand_path(dir) $LOAD_PATH.unshift(fulldir) unless $LOAD_PATH.include?(fulldir) end require 'spec' require 'puppettest' require 'puppettest/runnable_test' module Spec module Runner class ExampleGroupRunner - def run_behaviours - @behaviours.each do |behaviour| - # LAK:NOTE: this 'runnable' test is Puppet-specific. - next unless behaviour.runnable? - behaviour.run(@options.reporter, @options.dry_run, @options.reverse, @options.timeout) + def run + prepare + success = true + example_groups.each do |example_group| + next unless example_group.runnable? + success = success & example_group.run end + return success + ensure + finish end end end end module Spec module Example class ExampleGroup extend PuppetTest::RunnableTest end end end module Test module Unit class TestCase extend PuppetTest::RunnableTest end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 97ab007b0..db14b47cb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,37 +1,36 @@ dir = File.expand_path(File.dirname(__FILE__)) $LOAD_PATH.unshift("#{dir}/") $LOAD_PATH.unshift("#{dir}/../lib") $LOAD_PATH.unshift("#{dir}/../test/lib") # Add the old test dir, so that we can still find our local mocha and spec # include any gems in vendor/gems Dir["#{dir}/../vendor/gems/**"].each do |path| libpath = File.join(path, "lib") if File.directory?(libpath) $LOAD_PATH.unshift(libpath) else $LOAD_PATH.unshift(path) end end require 'puppettest' require 'puppettest/runnable_test' require 'mocha' require 'spec' +# load any monkey-patches +Dir["#{dir}/monkey_patches/*.rb"].map { |file| require file } Spec::Runner.configure do |config| config.mock_with :mocha - config.prepend_before :all do - setup_mocks_for_rspec - setup() if respond_to? :setup - end - - config.prepend_after :all do - teardown() if respond_to? :teardown - end +# config.prepend_before :all do +# setup_mocks_for_rspec +# setup() if respond_to? :setup +# end +# +# config.prepend_after :all do +# teardown() if respond_to? :teardown +# end end - -# load any monkey-patches -Dir["#{dir}/monkey_patches/*.rb"].map { |file| require file } diff --git a/spec/unit/indirector/rest.rb b/spec/unit/indirector/rest.rb index cf29577b9..3c4716dc8 100755 --- a/spec/unit/indirector/rest.rb +++ b/spec/unit/indirector/rest.rb @@ -1,30 +1,30 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/indirector/rest' describe Puppet::Indirector::REST do # FIXME : TODO / look through this, does this make sense? before do Puppet::Indirector::Terminus.stubs(:register_terminus_class) @model = mock 'model' @indirection = stub 'indirection', :name => :mystuff, :register_terminus_type => nil, :model => @model Puppet::Indirector::Indirection.stubs(:instance).returns(@indirection) @rest_class = Class.new(Puppet::Indirector::REST) do def self.to_s - "Testing" + "This::Is::A::Test::Class" end end @searcher = @rest_class.new end it "should return an instance of the indirected model" it "should deserialize result data after a call into a Model instance for find" it "should deserialize result data after a call into a list of Model instances for search" it "should deserialize result data after a call into a boolean for save" it "should deserialize result data after a call into a boolean for destroy" it "should generate an error when result data deserializes improperly" it "should generate an error when result data specifies an error" end diff --git a/spec/unit/parser/ast/definition.rb b/spec/unit/parser/ast/definition.rb index f236e23b7..a58e4d00e 100755 --- a/spec/unit/parser/ast/definition.rb +++ b/spec/unit/parser/ast/definition.rb @@ -1,195 +1,195 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../../spec_helper' describe Puppet::Parser::AST::Definition, "when initializing" do end describe Puppet::Parser::AST::Definition, "when evaluating" do before do @type = Puppet::Parser::Resource @parser = Puppet::Parser::Parser.new :Code => "" @source = @parser.newclass "" @definition = @parser.newdefine "mydefine" @node = Puppet::Node.new("yaynode") @compiler = Puppet::Parser::Compiler.new(@node, @parser) @scope = @compiler.topscope @resource = Puppet::Parser::Resource.new(:type => "mydefine", :title => "myresource", :scope => @scope, :source => @source) end it "should create a new scope" do scope = nil code = mock 'code' code.expects(:safeevaluate).with do |scope| scope.object_id.should_not == @scope.object_id true end @definition.stubs(:code).returns(code) @definition.evaluate_code(@resource) end # it "should copy its namespace to the scope" # # it "should mark the scope virtual if the resource is virtual" # # it "should mark the scope exported if the resource is exported" # # it "should set the resource's parameters as variables in the scope" # # it "should set the resource's title as a variable in the scope" # # it "should copy the resource's title in a 'name' variable in the scope" # # it "should not copy the resource's title as the name if 'name' is one of the resource parameters" # # it "should evaluate the associated code with the new scope" - def test_initialize + def old_test_initialize parser = mkparser # Create a new definition klass = parser.newdefine "yayness", :arguments => [["owner", stringobj("nobody")], %w{mode}], :code => AST::ASTArray.new( :children => [resourcedef("file", "/tmp/$name", "owner" => varref("owner"), "mode" => varref("mode"))] ) # Test validattr? a couple different ways [:owner, "owner", :schedule, "schedule"].each do |var| assert(klass.validattr?(var), "%s was not considered valid" % var.inspect) end [:random, "random"].each do |var| assert(! klass.validattr?(var), "%s was considered valid" % var.inspect) end end - def test_evaluate + def oldtest_evaluate parser = mkparser config = mkcompiler config.send(:evaluate_main) scope = config.topscope klass = parser.newdefine "yayness", :arguments => [["owner", stringobj("nobody")], %w{mode}], :code => AST::ASTArray.new( :children => [resourcedef("file", "/tmp/$name", "owner" => varref("owner"), "mode" => varref("mode"))] ) resource = Puppet::Parser::Resource.new( :title => "first", :type => "yayness", :exported => false, :virtual => false, :scope => scope, :source => scope.source ) resource.send(:set_parameter, "name", "first") resource.send(:set_parameter, "mode", "755") resource.stubs(:title) assert_nothing_raised do klass.evaluate_code(resource) end firstobj = config.findresource("File[/tmp/first]") assert(firstobj, "Did not create /tmp/first obj") assert_equal("File", firstobj.type) assert_equal("/tmp/first", firstobj.title) assert_equal("nobody", firstobj[:owner]) assert_equal("755", firstobj[:mode]) # Make sure we can't evaluate it with the same args assert_raise(Puppet::ParseError) do klass.evaluate_code(resource) end # Now create another with different args resource2 = Puppet::Parser::Resource.new( :title => "second", :type => "yayness", :exported => false, :virtual => false, :scope => scope, :source => scope.source ) resource2.send(:set_parameter, "name", "second") resource2.send(:set_parameter, "mode", "755") resource2.send(:set_parameter, "owner", "daemon") assert_nothing_raised do klass.evaluate_code(resource2) end secondobj = config.findresource("File[/tmp/second]") assert(secondobj, "Did not create /tmp/second obj") assert_equal("File", secondobj.type) assert_equal("/tmp/second", secondobj.title) assert_equal("daemon", secondobj[:owner]) assert_equal("755", secondobj[:mode]) end # #539 - definitions should support both names and titles - def test_names_and_titles + def oldtest_names_and_titles parser = mkparser scope = mkscope :parser => parser [ {:name => "one", :title => "two"}, {:title => "mytitle"} ].each_with_index do |hash, i| # Create a definition that uses both name and title. Put this # inside the loop so the subscope expectations work. klass = parser.newdefine "yayness%s" % i resource = Puppet::Parser::Resource.new( :title => hash[:title], :type => "yayness%s" % i, :exported => false, :virtual => false, :scope => scope, :source => scope.source ) subscope = klass.subscope(scope, resource) klass.expects(:subscope).returns(subscope) if hash[:name] resource.stubs(:to_hash).returns({:name => hash[:name]}) end assert_nothing_raised("Could not evaluate definition with %s" % hash.inspect) do klass.evaluate_code(resource) end name = hash[:name] || hash[:title] title = hash[:title] assert_equal(name, subscope.lookupvar("name"), "Name did not get set correctly") assert_equal(title, subscope.lookupvar("title"), "title did not get set correctly") [:name, :title].each do |param| val = resource.send(param) assert(subscope.tags.include?(val), "Scope was not tagged with %s '%s'" % [param, val]) end end end # Testing the root cause of #615. We should be using the fqname for the type, instead # of just the short name. - def test_fully_qualified_types + def oldtest_fully_qualified_types parser = mkparser klass = parser.newclass("one::two") assert_equal("one::two", klass.classname, "Class did not get fully qualified class name") end end diff --git a/spec/unit/parser/lexer.rb b/spec/unit/parser/lexer.rb index cddbef1ed..9972f7268 100755 --- a/spec/unit/parser/lexer.rb +++ b/spec/unit/parser/lexer.rb @@ -1,465 +1,465 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/parser/lexer' describe Puppet::Parser::Lexer::Token do before do @token = Puppet::Parser::Lexer::Token.new(%r{something}, :NAME) end [:regex, :name, :string, :skip, :incr_line, :skip_text].each do |param| it "should have a #{param.to_s} reader" do - @token.should respond_to?(param) + @token.should be_respond_to(param) end it "should have a #{param.to_s} writer" do - @token.should respond_to?(param.to_s + "=") + @token.should be_respond_to(param.to_s + "=") end end end describe Puppet::Parser::Lexer::Token, "when initializing" do it "should create a regex if the first argument is a string" do Puppet::Parser::Lexer::Token.new("something", :NAME).regex.should == %r{something} end it "should set the string if the first argument is one" do Puppet::Parser::Lexer::Token.new("something", :NAME).string.should == "something" end it "should set the regex if the first argument is one" do Puppet::Parser::Lexer::Token.new(%r{something}, :NAME).regex.should == %r{something} end end describe Puppet::Parser::Lexer::TokenList do before do @list = Puppet::Parser::Lexer::TokenList.new end it "should have a method for retrieving tokens by the name" do token = @list.add_token :name, "whatever" @list[:name].should equal(token) end it "should have a method for retrieving string tokens by the string" do token = @list.add_token :name, "whatever" @list.lookup("whatever").should equal(token) end it "should add tokens to the list when directed" do token = @list.add_token :name, "whatever" @list[:name].should equal(token) end it "should have a method for adding multiple tokens at once" do @list.add_tokens "whatever" => :name, "foo" => :bar @list[:name].should_not be_nil @list[:bar].should_not be_nil end it "should fail to add tokens sharing a name with an existing token" do @list.add_token :name, "whatever" lambda { @list.add_token :name, "whatever" }.should raise_error(ArgumentError) end it "should set provided options on tokens being added" do token = @list.add_token :name, "whatever", :skip_text => true token.skip_text.should == true end it "should define any provided blocks as a :convert method" do token = @list.add_token(:name, "whatever") do "foo" end token.convert.should == "foo" end it "should store all string tokens in the :string_tokens list" do one = @list.add_token(:name, "1") @list.string_tokens.should be_include(one) end it "should store all regex tokens in the :regex_tokens list" do one = @list.add_token(:name, %r{one}) @list.regex_tokens.should be_include(one) end it "should not store string tokens in the :regex_tokens list" do one = @list.add_token(:name, "1") @list.regex_tokens.should_not be_include(one) end it "should not store regex tokens in the :string_tokens list" do one = @list.add_token(:name, %r{one}) @list.string_tokens.should_not be_include(one) end it "should sort the string tokens inversely by length when asked" do one = @list.add_token(:name, "1") two = @list.add_token(:other, "12") @list.sort_tokens @list.string_tokens.should == [two, one] end end describe Puppet::Parser::Lexer::TOKENS do before do @lexer = Puppet::Parser::Lexer.new() end { :LBRACK => '[', :RBRACK => ']', :LBRACE => '{', :RBRACE => '}', :LPAREN => '(', :RPAREN => ')', :EQUALS => '=', :ISEQUAL => '==', :GREATEREQUAL => '>=', :GREATERTHAN => '>', :LESSTHAN => '<', :LESSEQUAL => '<=', :NOTEQUAL => '!=', :NOT => '!', :COMMA => ',', :DOT => '.', :COLON => ':', :AT => '@', :LLCOLLECT => '<<|', :RRCOLLECT => '|>>', :LCOLLECT => '<|', :RCOLLECT => '|>', :SEMIC => ';', :QMARK => '?', :BACKSLASH => '\\', :FARROW => '=>', :PARROW => '+>' }.each do |name, string| it "should have a token named #{name.to_s}" do Puppet::Parser::Lexer::TOKENS[name].should_not be_nil end it "should match '#{string}' for the token #{name.to_s}" do Puppet::Parser::Lexer::TOKENS[name].string.should == string end end { "case" => :CASE, "class" => :CLASS, "default" => :DEFAULT, "define" => :DEFINE, "import" => :IMPORT, "if" => :IF, "elsif" => :ELSIF, "else" => :ELSE, "inherits" => :INHERITS, "node" => :NODE, "and" => :AND, "or" => :OR, "undef" => :UNDEF, "false" => :FALSE, "true" => :TRUE }.each do |string, name| it "should have a keyword named #{name.to_s}" do Puppet::Parser::Lexer::KEYWORDS[name].should_not be_nil end it "should have the keyword for #{name.to_s} set to #{string}" do Puppet::Parser::Lexer::KEYWORDS[name].string.should == string end end # These tokens' strings don't matter, just that the tokens exist. [:DQTEXT, :SQTEXT, :BOOLEAN, :NAME, :NUMBER, :COMMENT, :RETURN, :SQUOTE, :DQUOTE, :VARIABLE].each do |name| it "should have a token named #{name.to_s}" do Puppet::Parser::Lexer::TOKENS[name].should_not be_nil end end end describe Puppet::Parser::Lexer::TOKENS[:NAME] do before { @token = Puppet::Parser::Lexer::TOKENS[:NAME] } it "should match against lower-case alpha-numeric terms" do @token.regex.should =~ "one-two" end it "should return itself and the value if the matched term is not a keyword" do Puppet::Parser::Lexer::KEYWORDS.expects(:lookup).returns(nil) @token.convert(stub("lexer"), "myval").should == [Puppet::Parser::Lexer::TOKENS[:NAME], "myval"] end it "should return the keyword token and the value if the matched term is a keyword" do keyword = stub 'keyword', :name => :testing Puppet::Parser::Lexer::KEYWORDS.expects(:lookup).returns(keyword) @token.convert(stub("lexer"), "myval").should == [keyword, "myval"] end it "should return the BOOLEAN token and 'true' if the matched term is the string 'true'" do keyword = stub 'keyword', :name => :TRUE Puppet::Parser::Lexer::KEYWORDS.expects(:lookup).returns(keyword) @token.convert(stub('lexer'), "true").should == [Puppet::Parser::Lexer::TOKENS[:BOOLEAN], true] end it "should return the BOOLEAN token and 'false' if the matched term is the string 'false'" do keyword = stub 'keyword', :name => :FALSE Puppet::Parser::Lexer::KEYWORDS.expects(:lookup).returns(keyword) @token.convert(stub('lexer'), "false").should == [Puppet::Parser::Lexer::TOKENS[:BOOLEAN], false] end end describe Puppet::Parser::Lexer::TOKENS[:NUMBER] do before { @token = Puppet::Parser::Lexer::TOKENS[:NUMBER] } it "should match against numeric terms" do @token.regex.should =~ "2982383139" end it "should return the NAME token and the value" do @token.convert(stub("lexer"), "myval").should == [Puppet::Parser::Lexer::TOKENS[:NAME], "myval"] end end describe Puppet::Parser::Lexer::TOKENS[:COMMENT] do before { @token = Puppet::Parser::Lexer::TOKENS[:COMMENT] } it "should match against lines starting with '#'" do @token.regex.should =~ "# this is a comment" end it "should be marked to get skipped" do @token.skip?.should be_true end end describe Puppet::Parser::Lexer::TOKENS[:RETURN] do before { @token = Puppet::Parser::Lexer::TOKENS[:RETURN] } it "should match against carriage returns" do @token.regex.should =~ "\n" end it "should be marked to initiate text skipping" do @token.skip_text.should be_true end it "should be marked to increment the line" do @token.incr_line.should be_true end end describe Puppet::Parser::Lexer::TOKENS[:SQUOTE] do before { @token = Puppet::Parser::Lexer::TOKENS[:SQUOTE] } it "should match against single quotes" do @token.regex.should =~ "'" end it "should slurp the rest of the quoted string" do lexer = stub("lexer") lexer.expects(:slurpstring).with("myval").returns("otherval") @token.convert(lexer, "myval") end it "should return the SQTEXT token with the slurped string" do lexer = stub("lexer") lexer.stubs(:slurpstring).with("myval").returns("otherval") @token.convert(lexer, "myval").should == [Puppet::Parser::Lexer::TOKENS[:SQTEXT], "otherval"] end end describe Puppet::Parser::Lexer::TOKENS[:DQUOTE] do before { @token = Puppet::Parser::Lexer::TOKENS[:DQUOTE] } it "should match against single quotes" do @token.regex.should =~ '"' end it "should slurp the rest of the quoted string" do lexer = stub("lexer") lexer.expects(:slurpstring).with("myval").returns("otherval") @token.convert(lexer, "myval") end it "should return the DQTEXT token with the slurped string" do lexer = stub("lexer") lexer.stubs(:slurpstring).with("myval").returns("otherval") @token.convert(lexer, "myval").should == [Puppet::Parser::Lexer::TOKENS[:DQTEXT], "otherval"] end end describe Puppet::Parser::Lexer::TOKENS[:VARIABLE] do before { @token = Puppet::Parser::Lexer::TOKENS[:VARIABLE] } it "should match against alpha words prefixed with '$'" do @token.regex.should =~ '$this_var' end it "should return the VARIABLE token and the variable name stripped of the '$'" do @token.convert(stub("lexer"), "$myval").should == [Puppet::Parser::Lexer::TOKENS[:VARIABLE], "myval"] end end # FIXME: We need to rewrite all of these tests, but I just don't want to take the time right now. describe "Puppet::Parser::Lexer in the old tests" do before { @lexer = Puppet::Parser::Lexer.new } it "should do simple lexing" do strings = { %q{\\} => [[:BACKSLASH,"\\"],[false,false]], %q{simplest scanner test} => [[:NAME,"simplest"],[:NAME,"scanner"],[:NAME,"test"],[false,false]], %q{returned scanner test } => [[:NAME,"returned"],[:NAME,"scanner"],[:NAME,"test"],[false,false]] } strings.each { |str,ary| @lexer.string = str @lexer.fullscan().should == ary } end it "should correctly lex quoted strings" do strings = { %q{a simple "scanner" test } => [[:NAME,"a"],[:NAME,"simple"],[:DQTEXT,"scanner"],[:NAME,"test"],[false,false]], %q{a simple 'single quote scanner' test } => [[:NAME,"a"],[:NAME,"simple"],[:SQTEXT,"single quote scanner"],[:NAME,"test"],[false,false]], %q{a harder 'a $b \c"' } => [[:NAME,"a"],[:NAME,"harder"],[:SQTEXT,'a $b \c"'],[false,false]], %q{a harder "scanner test" } => [[:NAME,"a"],[:NAME,"harder"],[:DQTEXT,"scanner test"],[false,false]], %q{a hardest "scanner \"test\"" } => [[:NAME,"a"],[:NAME,"hardest"],[:DQTEXT,'scanner "test"'],[false,false]], %q{a hardestest "scanner \"test\" " } => [[:NAME,"a"],[:NAME,"hardestest"],[:DQTEXT,'scanner "test" '],[false,false]], %q{function("call")} => [[:NAME,"function"],[:LPAREN,"("],[:DQTEXT,'call'],[:RPAREN,")"],[false,false]] } strings.each { |str,array| @lexer.string = str @lexer.fullscan().should == array } end it "should fail usefully" do strings = %w{ ^ } strings.each { |str| @lexer.string = str lambda { @lexer.fullscan() }.should raise_error(RuntimeError) } end it "should fail if the string is not set" do lambda { @lexer.fullscan() }.should raise_error(Puppet::LexError) end it "should correctly identify keywords" do @lexer.string = "case" @lexer.fullscan.should == [[:CASE, "case"], [false, false]] end it "should correctly match strings" do names = %w{this is a bunch of names} types = %w{Many Different Words A Word} words = %w{differently Cased words A a} names.each { |t| @lexer.string = t @lexer.fullscan.should == [[:NAME,t],[false,false]] } types.each { |t| @lexer.string = t @lexer.fullscan.should == [[:CLASSREF,t],[false,false]] } end it "should correctly parse empty strings" do bit = '$var = ""' @lexer.string = bit lambda { @lexer.fullscan }.should_not raise_error end it "should correctly parse virtual resources" do string = "@type {" @lexer.string = string @lexer.fullscan.should == [[:AT, "@"], [:NAME, "type"], [:LBRACE, "{"], [false,false]] end it "should correctly deal with namespaces" do @lexer.string = %{class myclass} @lexer.fullscan @lexer.namespace.should == "myclass" @lexer.namepop @lexer.namespace.should == "" @lexer.string = "class base { class sub { class more" @lexer.fullscan @lexer.namespace.should == "base::sub::more" @lexer.namepop @lexer.namespace.should == "base::sub" end it "should correctly handle fully qualified names" do @lexer.string = "class base { class sub::more {" @lexer.fullscan @lexer.namespace.should == "base::sub::more" @lexer.namepop @lexer.namespace.should == "base" end it "should correctly lex variables" do ["$variable", "$::variable", "$qualified::variable", "$further::qualified::variable"].each do |string| @lexer.string = string @lexer.scan do |t, s| t.should == :VARIABLE string.sub(/^\$/, '').should == s break end end end # #774 it "should correctly parse the CLASSREF token" do string = ["Foo", "::Foo","Foo::Bar","::Foo::Bar"] string.each do |foo| @lexer.string = foo @lexer.fullscan[0].should == [:CLASSREF, foo] end end end require 'puppettest/support/utils' describe "Puppet::Parser::Lexer in the old tests when lexing example files" do extend PuppetTest extend PuppetTest::Support::Utils textfiles() do |file| it "should correctly lex #{file}" do lexer = Puppet::Parser::Lexer.new() lexer.file = file lambda { lexer.fullscan() }.should_not raise_error end end end