diff --git a/lib/puppet/node/environment.rb b/lib/puppet/node/environment.rb index ad11a0476..3d55ac1a0 100644 --- a/lib/puppet/node/environment.rb +++ b/lib/puppet/node/environment.rb @@ -1,167 +1,173 @@ require 'puppet/util/cacher' require 'monitor' # Just define it, so this class has fewer load dependencies. class Puppet::Node end # Model the environment that a node can operate in. This class just # provides a simple wrapper for the functionality around environments. class Puppet::Node::Environment module Helper def environment Puppet::Node::Environment.new(@environment) end def environment=(env) if env.is_a?(String) or env.is_a?(Symbol) @environment = env else @environment = env.name end end end include Puppet::Util::Cacher @seen = {} # Return an existing environment instance, or create a new one. def self.new(name = nil) return name if name.is_a?(self) name ||= Puppet.settings.value(:environment) raise ArgumentError, "Environment name must be specified" unless name symbol = name.to_sym return @seen[symbol] if @seen[symbol] obj = self.allocate obj.send :initialize, symbol @seen[symbol] = obj end def self.current Thread.current[:environment] || root end def self.current=(env) Thread.current[:environment] = new(env) end def self.root @root end # This is only used for testing. def self.clear @seen.clear end attr_reader :name # Return an environment-specific setting. def [](param) Puppet.settings.value(param, self.name) end def initialize(name) @name = name extend MonitorMixin end def known_resource_types # This makes use of short circuit evaluation to get the right thread-safe # per environment semantics with an efficient most common cases; we almost # always just return our thread's known-resource types. Only at the start # of a compilation (after our thread var has been set to nil) or when the # environment has changed do we delve deeper. Thread.current[:known_resource_types] = nil if (krt = Thread.current[:known_resource_types]) && krt.environment != self Thread.current[:known_resource_types] ||= synchronize { if @known_resource_types.nil? or @known_resource_types.stale? @known_resource_types = Puppet::Resource::TypeCollection.new(self) - perform_initial_import + @known_resource_types.import_ast(perform_initial_import, '') end @known_resource_types } end def module(name) mod = Puppet::Module.new(name, self) return nil unless mod.exist? mod end # Cache the modulepath, so that we aren't searching through # all known directories all the time. cached_attr(:modulepath, :ttl => Puppet[:filetimeout]) do dirs = self[:modulepath].split(File::PATH_SEPARATOR) dirs = ENV["PUPPETLIB"].split(File::PATH_SEPARATOR) + dirs if ENV["PUPPETLIB"] validate_dirs(dirs) end # Return all modules from this environment. # Cache the list, because it can be expensive to create. cached_attr(:modules, :ttl => Puppet[:filetimeout]) do module_names = modulepath.collect { |path| Dir.entries(path) }.flatten.uniq module_names.collect do |path| begin Puppet::Module.new(path, self) rescue Puppet::Module::Error => e nil end end.compact end # Cache the manifestdir, so that we aren't searching through # all known directories all the time. cached_attr(:manifestdir, :ttl => Puppet[:filetimeout]) do validate_dirs(self[:manifestdir].split(File::PATH_SEPARATOR)) end def to_s name.to_s end # The only thing we care about when serializing an environment is its # identity; everything else is ephemeral and should not be stored or # transmitted. def to_zaml(z) self.to_s.to_zaml(z) end def validate_dirs(dirs) dirs.collect do |dir| if dir !~ /^#{File::SEPARATOR}/ File.join(Dir.getwd, dir) else dir end end.find_all do |p| p =~ /^#{File::SEPARATOR}/ && FileTest.directory?(p) end end private def perform_initial_import - return if Puppet.settings[:ignoreimport] + return empty_parse_result if Puppet.settings[:ignoreimport] parser = Puppet::Parser::Parser.new(self) if code = Puppet.settings.uninterpolated_value(:code, name.to_s) and code != "" parser.string = code else file = Puppet.settings.value(:manifest, name.to_s) - return unless File.exist?(file) + return empty_parse_result unless File.exist?(file) parser.file = file end parser.parse rescue => detail msg = "Could not parse for environment #{self}: #{detail}" error = Puppet::Error.new(msg) error.set_backtrace(detail.backtrace) raise error end + def empty_parse_result + # Return an empty toplevel hostclass to use as the result of + # perform_initial_import when no file was actually loaded. + return Puppet::Parser::AST::Hostclass.new('') + end + @root = new(:'*root*') end diff --git a/lib/puppet/parser/ast.rb b/lib/puppet/parser/ast.rb index 54e034acb..0369a6d28 100644 --- a/lib/puppet/parser/ast.rb +++ b/lib/puppet/parser/ast.rb @@ -1,134 +1,137 @@ # the parent class for all of our syntactical objects require 'puppet' require 'puppet/util/autoload' require 'puppet/file_collection/lookup' # The base class for all of the objects that make up the parse trees. # Handles things like file name, line #, and also does the initialization # for all of the parameters of all of the child objects. class Puppet::Parser::AST # Do this so I don't have to type the full path in all of the subclasses AST = Puppet::Parser::AST include Puppet::FileCollection::Lookup include Puppet::Util::Errors include Puppet::Util::MethodHelper include Puppet::Util::Docs attr_accessor :parent, :scope # don't fetch lexer comment by default def use_docs self.class.use_docs end # allow our subclass to specify they want documentation class << self attr_accessor :use_docs def associates_doc self.use_docs = true end end # Does this ast object set something? If so, it gets evaluated first. def self.settor? if defined?(@settor) @settor else false end end # Evaluate the current object. Just a stub method, since the subclass # should override this method. # of the contained children and evaluates them in turn, returning a # list of all of the collected values, rejecting nil values def evaluate(*options) raise Puppet::DevError, "Did not override #evaluate in #{self.class}" end # Throw a parse error. def parsefail(message) self.fail(Puppet::ParseError, message) end # Wrap a statemp in a reusable way so we always throw a parse error. def parsewrap exceptwrap :type => Puppet::ParseError do yield end end # The version of the evaluate method that should be called, because it # correctly handles errors. It is critical to use this method because # it can enable you to catch the error where it happens, rather than # much higher up the stack. def safeevaluate(*options) # We duplicate code here, rather than using exceptwrap, because this # is called so many times during parsing. begin return self.evaluate(*options) rescue Puppet::Error => detail raise adderrorcontext(detail) rescue => detail error = Puppet::Error.new(detail.to_s) # We can't use self.fail here because it always expects strings, # not exceptions. raise adderrorcontext(error, detail) end end # Initialize the object. Requires a hash as the argument, and # takes each of the parameters of the hash and calls the settor # method for them. This is probably pretty inefficient and should # likely be changed at some point. def initialize(args) set_options(args) end # evaluate ourselves, and match def evaluate_match(value, scope) obj = self.safeevaluate(scope) obj = obj.downcase if obj.respond_to?(:downcase) value = value.downcase if value.respond_to?(:downcase) obj = Puppet::Parser::Scope.number?(obj) || obj value = Puppet::Parser::Scope.number?(value) || value # "" == undef for case/selector/if obj == value or (obj == "" and value == :undef) end end # And include all of the AST subclasses. require 'puppet/parser/ast/arithmetic_operator' require 'puppet/parser/ast/astarray' require 'puppet/parser/ast/asthash' -require 'puppet/parser/ast/branch' require 'puppet/parser/ast/boolean_operator' +require 'puppet/parser/ast/branch' require 'puppet/parser/ast/caseopt' require 'puppet/parser/ast/casestatement' require 'puppet/parser/ast/collection' require 'puppet/parser/ast/collexpr' require 'puppet/parser/ast/comparison_operator' +require 'puppet/parser/ast/definition' require 'puppet/parser/ast/else' require 'puppet/parser/ast/function' +require 'puppet/parser/ast/hostclass' require 'puppet/parser/ast/ifstatement' require 'puppet/parser/ast/in_operator' require 'puppet/parser/ast/leaf' require 'puppet/parser/ast/match_operator' require 'puppet/parser/ast/minus' +require 'puppet/parser/ast/node' require 'puppet/parser/ast/nop' require 'puppet/parser/ast/not' +require 'puppet/parser/ast/relationship' require 'puppet/parser/ast/resource' require 'puppet/parser/ast/resource_defaults' require 'puppet/parser/ast/resource_override' require 'puppet/parser/ast/resource_reference' require 'puppet/parser/ast/resourceparam' require 'puppet/parser/ast/selector' require 'puppet/parser/ast/tag' require 'puppet/parser/ast/vardef' -require 'puppet/parser/ast/relationship' diff --git a/lib/puppet/parser/ast/astarray.rb b/lib/puppet/parser/ast/astarray.rb index 529998e3c..432300c7a 100644 --- a/lib/puppet/parser/ast/astarray.rb +++ b/lib/puppet/parser/ast/astarray.rb @@ -1,61 +1,78 @@ require 'puppet/parser/ast/branch' class Puppet::Parser::AST # The basic container class. This object behaves almost identically # to a normal array except at initialization time. Note that its name # is 'AST::ASTArray', rather than plain 'AST::Array'; I had too many # bugs when it was just 'AST::Array', because things like # 'object.is_a?(Array)' never behaved as I expected. class ASTArray < Branch include Enumerable + # True if this ASTArray represents a list of statements in a + # context that defines a namespace. Classes and definitions may + # only appear in such a context. + attr_accessor :is_a_namespace + # Return a child by index. Probably never used. def [](index) @children[index] end # Evaluate our children. def evaluate(scope) # Make a new array, so we don't have to deal with the details of # flattening and such items = [] # First clean out any AST::ASTArrays @children.each { |child| if child.instance_of?(AST::ASTArray) child.each do |ac| items << ac end else items << child end } rets = items.flatten.collect { |child| - child.safeevaluate(scope) + if child.respond_to? :instantiate + if is_a_namespace + # no problem, just don't evaluate it. + else + msg = "Classes, definitions, and nodes may only appear at toplevel or inside other classes" + error = Puppet::Error.new(msg) + error.line = child.line + error.file = child.file + raise error + end + else + child.safeevaluate(scope) + end } rets.reject { |o| o.nil? } end def push(*ary) ary.each { |child| #Puppet.debug "adding %s(%s) of type %s to %s" % # [child, child.object_id, child.class.to_s.sub(/.+::/,''), # self.object_id] @children.push(child) } self end def to_s "[" + @children.collect { |c| c.to_s }.join(', ') + "]" end end # A simple container class, containing the parameters for an object. # Used for abstracting the grammar declarations. Basically unnecessary # except that I kept finding bugs because I had too many arrays that # meant completely different things. class ResourceInstance < ASTArray; end end diff --git a/lib/puppet/parser/ast/definition.rb b/lib/puppet/parser/ast/definition.rb new file mode 100644 index 000000000..09f52b519 --- /dev/null +++ b/lib/puppet/parser/ast/definition.rb @@ -0,0 +1,12 @@ +require 'puppet/parser/ast/top_level_construct' + +class Puppet::Parser::AST::Definition < Puppet::Parser::AST::TopLevelConstruct + def initialize(name, context = {}) + @name = name + @context = context + end + + def instantiate(modname) + return [Puppet::Resource::Type.new(:definition, @name, @context.merge(:module_name => modname))] + end +end diff --git a/lib/puppet/parser/ast/hostclass.rb b/lib/puppet/parser/ast/hostclass.rb new file mode 100644 index 000000000..d539e4deb --- /dev/null +++ b/lib/puppet/parser/ast/hostclass.rb @@ -0,0 +1,26 @@ +require 'puppet/parser/ast/top_level_construct' + +class Puppet::Parser::AST::Hostclass < Puppet::Parser::AST::TopLevelConstruct + attr_accessor :name, :context + + def initialize(name, context = {}) + @context = context + @name = name + end + + def instantiate(modname) + all_types = [Puppet::Resource::Type.new(:hostclass, @name, @context.merge(:module_name => modname))] + if code + code.each do |nested_ast_node| + if nested_ast_node.respond_to? :instantiate + all_types += nested_ast_node.instantiate(modname) + end + end + end + return all_types + end + + def code() + @context[:code] + end +end diff --git a/lib/puppet/parser/ast/node.rb b/lib/puppet/parser/ast/node.rb new file mode 100644 index 000000000..c19a24ce0 --- /dev/null +++ b/lib/puppet/parser/ast/node.rb @@ -0,0 +1,17 @@ +require 'puppet/parser/ast/top_level_construct' + +class Puppet::Parser::AST::Node < Puppet::Parser::AST::TopLevelConstruct + attr_accessor :names + + def initialize(names, context = {}) + raise ArgumentError, "names should be an array" unless names.is_a? Array + @names = names + @context = context + end + + def instantiate(modname) + @names.collect do |name| + Puppet::Resource::Type.new(:node, name, @context.merge(:module_name => modname)) + end + end +end diff --git a/lib/puppet/parser/ast/top_level_construct.rb b/lib/puppet/parser/ast/top_level_construct.rb new file mode 100644 index 000000000..901a939c2 --- /dev/null +++ b/lib/puppet/parser/ast/top_level_construct.rb @@ -0,0 +1,4 @@ +# The base class for AST nodes representing top level things: +# hostclasses, definitions, and nodes. +class Puppet::Parser::AST::TopLevelConstruct < Puppet::Parser::AST +end diff --git a/lib/puppet/parser/grammar.ra b/lib/puppet/parser/grammar.ra index 7a316d4d7..3185c435d 100644 --- a/lib/puppet/parser/grammar.ra +++ b/lib/puppet/parser/grammar.ra @@ -1,875 +1,861 @@ # vim: syntax=ruby # the parser class Puppet::Parser::Parser token STRING DQPRE DQMID DQPOST token LBRACK RBRACK LBRACE RBRACE SYMBOL FARROW COMMA TRUE token FALSE EQUALS APPENDS LESSEQUAL NOTEQUAL DOT COLON LLCOLLECT RRCOLLECT token QMARK LPAREN RPAREN ISEQUAL GREATEREQUAL GREATERTHAN LESSTHAN token IF ELSE IMPORT DEFINE ELSIF VARIABLE CLASS INHERITS NODE BOOLEAN token NAME SEMIC CASE DEFAULT AT LCOLLECT RCOLLECT CLASSNAME CLASSREF token NOT OR AND UNDEF PARROW PLUS MINUS TIMES DIV LSHIFT RSHIFT UMINUS token MATCH NOMATCH REGEX IN_EDGE OUT_EDGE IN_EDGE_SUB OUT_EDGE_SUB token IN prechigh right NOT nonassoc UMINUS left IN MATCH NOMATCH left TIMES DIV left MINUS PLUS left LSHIFT RSHIFT left NOTEQUAL ISEQUAL left GREATEREQUAL GREATERTHAN LESSTHAN LESSEQUAL left AND left OR preclow rule program: statements { - if val[0] - # Make sure we always return an array. - if val[0].is_a?(AST::ASTArray) - if val[0].children.empty? - result = nil - else - result = val[0] - end - else - result = aryfy(val[0]) - end - else - result = nil - end + val[0].is_a_namespace = true + result = val[0] } | nil -statements: statement + statements: statement { + result = ast AST::ASTArray, :children => [val[0]] + } | statements statement { - if val[0] and val[1] - if val[0].instance_of?(AST::ASTArray) - val[0].push(val[1]) - result = val[0] - else - result = ast AST::ASTArray, :children => [val[0],val[1]] - end - elsif obj = (val[0] || val[1]) - result = obj - else result = nil - end -} + val[0].push(val[1]) + result = val[0] + } # The main list of valid statements statement: resource | virtualresource | collection | assignment | casestatement | ifstatement_begin | import | fstatement | definition | hostclass | nodedef | resourceoverride | append | relationship relationship: relationship_side edge relationship_side { result = AST::Relationship.new(val[0], val[2], val[1][:value], ast_context) } | relationship edge relationship_side { result = AST::Relationship.new(val[0], val[2], val[1][:value], ast_context) } relationship_side: resource | resourceref | collection edge: IN_EDGE | OUT_EDGE | IN_EDGE_SUB | OUT_EDGE_SUB fstatement: NAME LPAREN funcvalues RPAREN { args = aryfy(val[2]) result = ast AST::Function, :name => val[0][:value], :line => val[0][:line], :arguments => args, :ftype => :statement } | NAME LPAREN funcvalues COMMA RPAREN { args = aryfy(val[2]) result = ast AST::Function, :name => val[0][:value], :line => val[0][:line], :arguments => args, :ftype => :statement } | NAME LPAREN RPAREN { result = ast AST::Function, :name => val[0][:value], :line => val[0][:line], :arguments => AST::ASTArray.new({}), :ftype => :statement } | NAME funcvalues { args = aryfy(val[1]) result = ast AST::Function, :name => val[0][:value], :line => val[0][:line], :arguments => args, :ftype => :statement } funcvalues: namestring | resourceref | funcvalues COMMA namestring { result = aryfy(val[0], val[2]) result.line = @lexer.line result.file = @lexer.file } | funcvalues COMMA resourceref { unless val[0].is_a?(AST::ASTArray) val[0] = aryfy(val[0]) end val[0].push(val[2]) result = val[0] } # This is *almost* an rvalue, but I couldn't get a full # rvalue to work without scads of shift/reduce conflicts. namestring: name | variable | type | boolean | funcrvalue | selector | quotedtext | hasharrayaccesses | CLASSNAME { result = ast AST::Name, :value => val[0][:value] } resource: classname LBRACE resourceinstances endsemi RBRACE { @lexer.commentpop array = val[2] array = [array] if array.instance_of?(AST::ResourceInstance) result = ast AST::ASTArray # this iterates across each specified resourceinstance array.each { |instance| raise Puppet::Dev, "Got something that isn't an instance" unless instance.instance_of?(AST::ResourceInstance) # now, i need to somehow differentiate between those things with # arrays in their names, and normal things result.push ast( AST::Resource, :type => val[0], :title => instance[0], :parameters => instance[1]) } } | classname LBRACE params endcomma RBRACE { # This is a deprecated syntax. error "All resource specifications require names" } | classref LBRACE params endcomma RBRACE { # a defaults setting for a type @lexer.commentpop result = ast(AST::ResourceDefaults, :type => val[0], :parameters => val[2]) } # Override a value set elsewhere in the configuration. resourceoverride: resourceref LBRACE anyparams endcomma RBRACE { @lexer.commentpop result = ast AST::ResourceOverride, :object => val[0], :parameters => val[2] } # Exported and virtual resources; these don't get sent to the client # unless they get collected elsewhere in the db. virtualresource: at resource { type = val[0] if (type == :exported and ! Puppet[:storeconfigs]) and ! Puppet[:parseonly] Puppet.warning addcontext("You cannot collect without storeconfigs being set") end error "Defaults are not virtualizable" if val[1].is_a? AST::ResourceDefaults method = type.to_s + "=" # Just mark our resources as exported and pass them through. if val[1].instance_of?(AST::ASTArray) val[1].each do |obj| obj.send(method, true) end else val[1].send(method, true) end result = val[1] } at: AT { result = :virtual } | AT AT { result = :exported } # A collection statement. Currently supports no arguments at all, but eventually # will, I assume. collection: classref collectrhand LBRACE anyparams endcomma RBRACE { @lexer.commentpop Puppet.warning addcontext("Collection names must now be capitalized") if val[0] =~ /^[a-z]/ type = val[0].downcase args = {:type => type} if val[1].is_a?(AST::CollExpr) args[:query] = val[1] args[:query].type = type args[:form] = args[:query].form else args[:form] = val[1] end if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly] Puppet.warning addcontext("You cannot collect exported resources without storeconfigs being set; the collection will be ignored") end args[:override] = val[3] result = ast AST::Collection, args } | classref collectrhand { if val[0] =~ /^[a-z]/ Puppet.warning addcontext("Collection names must now be capitalized") end type = val[0].downcase args = {:type => type } if val[1].is_a?(AST::CollExpr) args[:query] = val[1] args[:query].type = type args[:form] = args[:query].form else args[:form] = val[1] end if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly] Puppet.warning addcontext("You cannot collect exported resources without storeconfigs being set; the collection will be ignored") end result = ast AST::Collection, args } collectrhand: LCOLLECT collstatements RCOLLECT { if val[1] result = val[1] result.form = :virtual else result = :virtual end } | LLCOLLECT collstatements RRCOLLECT { if val[1] result = val[1] result.form = :exported else result = :exported end } # A mini-language for handling collection comparisons. This is organized # to avoid the need for precedence indications. collstatements: nil | collstatement | collstatements colljoin collstatement { result = ast AST::CollExpr, :test1 => val[0], :oper => val[1], :test2 => val[2] } collstatement: collexpr | LPAREN collstatements RPAREN { result = val[1] result.parens = true } colljoin: AND { result=val[0][:value] } | OR { result=val[0][:value] } collexpr: colllval ISEQUAL simplervalue { result = ast AST::CollExpr, :test1 => val[0], :oper => val[1][:value], :test2 => val[2] #result = ast AST::CollExpr #result.push *val } | colllval NOTEQUAL simplervalue { result = ast AST::CollExpr, :test1 => val[0], :oper => val[1][:value], :test2 => val[2] #result = ast AST::CollExpr #result.push *val } colllval: variable | name resourceinst: resourcename COLON params endcomma { result = ast AST::ResourceInstance, :children => [val[0],val[2]] } resourceinstances: resourceinst | resourceinstances SEMIC resourceinst { if val[0].instance_of?(AST::ResourceInstance) result = ast AST::ASTArray, :children => [val[0],val[2]] else val[0].push val[2] result = val[0] end } endsemi: # nothing | SEMIC undef: UNDEF { result = ast AST::Undef, :value => :undef } name: NAME { result = ast AST::Name, :value => val[0][:value], :line => val[0][:line] } type: CLASSREF { result = ast AST::Type, :value => val[0][:value], :line => val[0][:line] } resourcename: quotedtext | name | type | selector | variable | array | hasharrayaccesses assignment: VARIABLE EQUALS expression { raise Puppet::ParseError, "Cannot assign to variables in other namespaces" if val[0][:value] =~ /::/ # this is distinct from referencing a variable variable = ast AST::Name, :value => val[0][:value], :line => val[0][:line] result = ast AST::VarDef, :name => variable, :value => val[2], :line => val[0][:line] } | hasharrayaccess EQUALS expression { result = ast AST::VarDef, :name => val[0], :value => val[2] } append: VARIABLE APPENDS expression { variable = ast AST::Name, :value => val[0][:value], :line => val[0][:line] result = ast AST::VarDef, :name => variable, :value => val[2], :append => true, :line => val[0][:line] } params: # nothing { result = ast AST::ASTArray } | param { result = val[0] } | params COMMA param { if val[0].instance_of?(AST::ASTArray) val[0].push(val[2]) result = val[0] else result = ast AST::ASTArray, :children => [val[0],val[2]] end } param: NAME FARROW rvalue { result = ast AST::ResourceParam, :param => val[0][:value], :line => val[0][:line], :value => val[2] } addparam: NAME PARROW rvalue { result = ast AST::ResourceParam, :param => val[0][:value], :line => val[0][:line], :value => val[2], :add => true } anyparam: param | addparam anyparams: # nothing { result = ast AST::ASTArray } | anyparam { result = val[0] } | anyparams COMMA anyparam { if val[0].instance_of?(AST::ASTArray) val[0].push(val[2]) result = val[0] else result = ast AST::ASTArray, :children => [val[0],val[2]] end } rvalues: rvalue | rvalues comma rvalue { if val[0].instance_of?(AST::ASTArray) result = val[0].push(val[2]) else result = ast AST::ASTArray, :children => [val[0],val[2]] end } simplervalue: quotedtext | name | type | boolean | selector | variable rvalue: quotedtext | name | type | boolean | selector | variable | array | hash | hasharrayaccesses | resourceref | funcrvalue | undef # We currently require arguments in these functions. funcrvalue: NAME LPAREN funcvalues RPAREN { args = aryfy(val[2]) result = ast AST::Function, :name => val[0][:value], :line => val[0][:line], :arguments => args, :ftype => :rvalue } | NAME LPAREN RPAREN { result = ast AST::Function, :name => val[0][:value], :line => val[0][:line], :arguments => AST::ASTArray.new({}), :ftype => :rvalue } quotedtext: STRING { result = ast AST::String, :value => val[0][:value], :line => val[0][:line] } | DQPRE dqrval { result = ast AST::Concat, :value => [ast(AST::String,val[0])]+val[1], :line => val[0][:line] } dqrval: expression dqtail { result = [val[0]] + val[1] } dqtail: DQPOST { result = [ast(AST::String,val[0])] } | DQMID dqrval { result = [ast(AST::String,val[0])] + val[1] } boolean: BOOLEAN { result = ast AST::Boolean, :value => val[0][:value], :line => val[0][:line] } resourceref: NAME LBRACK rvalues RBRACK { Puppet.warning addcontext("Deprecation notice: Resource references should now be capitalized") result = ast AST::ResourceReference, :type => val[0][:value], :line => val[0][:line], :title => val[2] } | classref LBRACK rvalues RBRACK { result = ast AST::ResourceReference, :type => val[0], :title => val[2] } ifstatement_begin: IF ifstatement { result = val[1] } ifstatement: expression LBRACE statements RBRACE else { @lexer.commentpop args = { :test => val[0], :statements => val[2] } args[:else] = val[4] if val[4] result = ast AST::IfStatement, args } | expression LBRACE RBRACE else { @lexer.commentpop args = { :test => val[0], :statements => ast(AST::Nop) } args[:else] = val[3] if val[3] result = ast AST::IfStatement, args } else: # nothing | ELSIF ifstatement { result = ast AST::Else, :statements => val[1] } | ELSE LBRACE statements RBRACE { @lexer.commentpop result = ast AST::Else, :statements => val[2] } | ELSE LBRACE RBRACE { @lexer.commentpop result = ast AST::Else, :statements => ast(AST::Nop) } # Unlike yacc/bison, it seems racc # gives tons of shift/reduce warnings # with the following syntax: # # expression: ... # | expression arithop expressio { ... } # # arithop: PLUS | MINUS | DIVIDE | TIMES ... # # So I had to develop the expression by adding one rule # per operator :-( expression: rvalue | expression IN rvalue { result = ast AST::InOperator, :lval => val[0], :rval => val[2] } | expression MATCH regex { result = ast AST::MatchOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression NOMATCH regex { result = ast AST::MatchOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression PLUS expression { result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression MINUS expression { result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression DIV expression { result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression TIMES expression { result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression LSHIFT expression { result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression RSHIFT expression { result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | MINUS expression =UMINUS { result = ast AST::Minus, :value => val[1] } | expression NOTEQUAL expression { result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression ISEQUAL expression { result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression GREATERTHAN expression { result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression GREATEREQUAL expression { result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression LESSTHAN expression { result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression LESSEQUAL expression { result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | NOT expression { result = ast AST::Not, :value => val[1] } | expression AND expression { result = ast AST::BooleanOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | expression OR expression { result = ast AST::BooleanOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] } | LPAREN expression RPAREN { result = val[1] } casestatement: CASE rvalue LBRACE caseopts RBRACE { @lexer.commentpop options = val[3] options = ast AST::ASTArray, :children => [val[3]] unless options.instance_of?(AST::ASTArray) result = ast AST::CaseStatement, :test => val[1], :options => options } caseopts: caseopt | caseopts caseopt { if val[0].instance_of?(AST::ASTArray) val[0].push val[1] result = val[0] else result = ast AST::ASTArray, :children => [val[0], val[1]] end } caseopt: casevalues COLON LBRACE statements RBRACE { @lexer.commentpop result = ast AST::CaseOpt, :value => val[0], :statements => val[3] } | casevalues COLON LBRACE RBRACE { @lexer.commentpop result = ast( AST::CaseOpt, :value => val[0], :statements => ast(AST::ASTArray) ) } casevalues: selectlhand | casevalues COMMA selectlhand { if val[0].instance_of?(AST::ASTArray) val[0].push(val[2]) result = val[0] else result = ast AST::ASTArray, :children => [val[0],val[2]] end } selector: selectlhand QMARK svalues { result = ast AST::Selector, :param => val[0], :values => val[2] } svalues: selectval | LBRACE sintvalues endcomma RBRACE { @lexer.commentpop result = val[1] } sintvalues: selectval | sintvalues comma selectval { if val[0].instance_of?(AST::ASTArray) val[0].push(val[2]) result = val[0] else result = ast AST::ASTArray, :children => [val[0],val[2]] end } selectval: selectlhand FARROW rvalue { result = ast AST::ResourceParam, :param => val[0], :value => val[2] } selectlhand: name | type | quotedtext | variable | funcrvalue | boolean | undef | DEFAULT { result = ast AST::Default, :value => val[0][:value], :line => val[0][:line] } | regex # These are only used for importing, and we don't interpolate there. string: STRING { result = [val[0][:value]] } strings: string | strings COMMA string { result = val[0] += val[2] } import: IMPORT strings { val[1].each do |file| import(file) end result = AST::ASTArray.new(:children => []) } # Disable definition inheritance for now. 8/27/06, luke #definition: DEFINE NAME argumentlist parent LBRACE statements RBRACE { definition: DEFINE classname argumentlist LBRACE statements RBRACE { @lexer.commentpop - newdefine classname(val[1]), :arguments => val[2], :code => val[4], :line => val[0][:line] + result = Puppet::Parser::AST::Definition.new(classname(val[1]), + ast_context(true).merge(:arguments => val[2], :code => val[4], + :line => val[0][:line])) @lexer.indefine = false - result = nil #} | DEFINE NAME argumentlist parent LBRACE RBRACE { } | DEFINE classname argumentlist LBRACE RBRACE { @lexer.commentpop - newdefine classname(val[1]), :arguments => val[2], :line => val[0][:line] + result = Puppet::Parser::AST::Definition.new(classname(val[1]), + ast_context(true).merge(:arguments => val[2], :line => val[0][:line])) @lexer.indefine = false - result = nil } #hostclass: CLASS NAME argumentlist parent LBRACE statements RBRACE { hostclass: CLASS classname argumentlist classparent LBRACE statements RBRACE { @lexer.commentpop # Our class gets defined in the parent namespace, not our own. @lexer.namepop - newclass classname(val[1]), :arguments => val[2], :parent => val[3], :code => val[5], :line => val[0][:line] - result = nil + val[5].is_a_namespace = true + result = Puppet::Parser::AST::Hostclass.new(classname(val[1]), + ast_context(true).merge(:arguments => val[2], :parent => val[3], + :code => val[5], :line => val[0][:line])) } | CLASS classname argumentlist classparent LBRACE RBRACE { @lexer.commentpop # Our class gets defined in the parent namespace, not our own. @lexer.namepop - newclass classname(val[1]), :arguments => val[2], :parent => val[3], :line => val[0][:line] - result = nil + result = Puppet::Parser::AST::Hostclass.new(classname(val[1]), + ast_context(true).merge(:arguments => val[2], :parent => val[3], + :line => val[0][:line])) } nodedef: NODE hostnames nodeparent LBRACE statements RBRACE { @lexer.commentpop - newnode val[1], :parent => val[2], :code => val[4], :line => val[0][:line] - result = nil + result = Puppet::Parser::AST::Node.new(val[1], + ast_context(true).merge(:parent => val[2], :code => val[4], + :line => val[0][:line])) } | NODE hostnames nodeparent LBRACE RBRACE { @lexer.commentpop - newnode val[1], :parent => val[2], :line => val[0][:line] - result = nil + result = Puppet::Parser::AST::Node.new(val[1], ast_context(true).merge(:parent => val[2], :line => val[0][:line])) } classref: CLASSREF { result = val[0][:value] } classname: NAME { result = val[0][:value] } | CLASSNAME { result = val[0][:value] } | CLASS { result = "class" } # Multiple hostnames, as used for node names. These are all literal # strings, not AST objects. -hostnames: nodename +hostnames: nodename { + result = [result] +} | hostnames COMMA nodename { result = val[0] - result = [result] unless result.is_a?(Array) result << val[2] } nodename: hostname { result = ast AST::HostName, :value => val[0] } hostname: NAME { result = val[0][:value] } | STRING { result = val[0][:value] } | DEFAULT { result = val[0][:value] } | regex nil: { result = nil } nothing: { result = ast AST::ASTArray, :children => [] } argumentlist: nil | LPAREN nothing RPAREN { result = nil } | LPAREN arguments RPAREN { result = val[1] result = [result] unless result[0].is_a?(Array) } arguments: argument | arguments COMMA argument { result = val[0] result = [result] unless result[0].is_a?(Array) result << val[2] } argument: NAME EQUALS rvalue { Puppet.warning addcontext("Deprecation notice: must now include '$' in prototype") result = [val[0][:value], val[2]] } | NAME { Puppet.warning addcontext("Deprecation notice: must now include '$' in prototype") result = [val[0][:value]] } | VARIABLE EQUALS rvalue { result = [val[0][:value], val[2]] } | VARIABLE { result = [val[0][:value]] } nodeparent: nil | INHERITS hostname { result = val[1] } classparent: nil | INHERITS classnameordefault { result = val[1] } classnameordefault: classname | DEFAULT variable: VARIABLE { result = ast AST::Variable, :value => val[0][:value], :line => val[0][:line] } array: LBRACK rvalues RBRACK { if val[1].instance_of?(AST::ASTArray) result = val[1] else result = ast AST::ASTArray, :children => [val[1]] end } | LBRACK rvalues COMMA RBRACK { if val[1].instance_of?(AST::ASTArray) result = val[1] else result = ast AST::ASTArray, :children => [val[1]] end } | LBRACK RBRACK { result = ast AST::ASTArray } comma: FARROW | COMMA endcomma: # nothing | COMMA { result = nil } regex: REGEX { result = ast AST::Regex, :value => val[0][:value] } hash: LBRACE hashpairs RBRACE { if val[1].instance_of?(AST::ASTHash) result = val[1] else result = ast AST::ASTHash, { :value => val[1] } end } | LBRACE hashpairs COMMA RBRACE { if val[1].instance_of?(AST::ASTHash) result = val[1] else result = ast AST::ASTHash, { :value => val[1] } end } | LBRACE RBRACE { result = ast AST::ASTHash } hashpairs: hashpair | hashpairs COMMA hashpair { if val[0].instance_of?(AST::ASTHash) result = val[0].merge(val[2]) else result = ast AST::ASTHash, :value => val[0] result.merge(val[2]) end } hashpair: key FARROW rvalue { result = ast AST::ASTHash, { :value => { val[0] => val[2] } } } key: NAME { result = val[0][:value] } | quotedtext { result = val[0] } hasharrayaccess: VARIABLE LBRACK rvalue RBRACK { result = ast AST::HashOrArrayAccess, :variable => val[0][:value], :key => val[2] } hasharrayaccesses: hasharrayaccess | hasharrayaccess LBRACK rvalue RBRACK { result = ast AST::HashOrArrayAccess, :variable => val[0], :key => val[2] } end ---- header ---- require 'puppet' require 'puppet/util/loadedfile' require 'puppet/parser/lexer' require 'puppet/parser/ast' module Puppet class ParseError < Puppet::Error; end class ImportError < Racc::ParseError; end class AlreadyImportedError < ImportError; end end ---- inner ---- # It got too annoying having code in a file that needs to be compiled. require 'puppet/parser/parser_support' # Make emacs happy # Local Variables: # mode: ruby # End: # $Id$ diff --git a/lib/puppet/parser/parser.rb b/lib/puppet/parser/parser.rb index 5be9e5a3f..e4f5149b9 100644 --- a/lib/puppet/parser/parser.rb +++ b/lib/puppet/parser/parser.rb @@ -1,2602 +1,2689 @@ # # DO NOT MODIFY!!!! -# This file is automatically generated by racc 1.4.5 -# from racc grammer file "grammar.ra". +# This file is automatically generated by Racc 1.4.6 +# from Racc grammer file "". # -require 'racc/parser' - +require 'racc/parser.rb' require 'puppet' require 'puppet/util/loadedfile' require 'puppet/parser/lexer' require 'puppet/parser/ast' module Puppet - class ParseError < Puppet::Error; end - class ImportError < Racc::ParseError; end - class AlreadyImportedError < ImportError; end + class ParseError < Puppet::Error; end + class ImportError < Racc::ParseError; end + class AlreadyImportedError < ImportError; end end - module Puppet - module Parser - class Parser < Racc::Parser -module_eval <<'..end grammar.ra modeval..id7145220b1b', 'grammar.ra', 876 +module_eval(<<'...end grammar.ra/module_eval...', 'grammar.ra', 851) # It got too annoying having code in a file that needs to be compiled. require 'puppet/parser/parser_support' # Make emacs happy # Local Variables: # mode: ruby # End: # $Id$ - -..end grammar.ra modeval..id7145220b1b - -##### racc 1.4.5 generates ### - -racc_reduce_table = [ - 0, 0, :racc_error, - 1, 70, :_reduce_1, - 1, 70, :_reduce_none, - 1, 71, :_reduce_none, - 2, 71, :_reduce_4, - 1, 73, :_reduce_none, - 1, 73, :_reduce_none, - 1, 73, :_reduce_none, - 1, 73, :_reduce_none, - 1, 73, :_reduce_none, - 1, 73, :_reduce_none, - 1, 73, :_reduce_none, - 1, 73, :_reduce_none, - 1, 73, :_reduce_none, - 1, 73, :_reduce_none, - 1, 73, :_reduce_none, - 1, 73, :_reduce_none, - 1, 73, :_reduce_none, - 1, 73, :_reduce_none, - 3, 87, :_reduce_19, - 3, 87, :_reduce_20, - 1, 88, :_reduce_none, - 1, 88, :_reduce_none, - 1, 88, :_reduce_none, - 1, 89, :_reduce_none, - 1, 89, :_reduce_none, - 1, 89, :_reduce_none, - 1, 89, :_reduce_none, - 4, 81, :_reduce_28, - 5, 81, :_reduce_29, - 3, 81, :_reduce_30, - 2, 81, :_reduce_31, - 1, 91, :_reduce_none, - 1, 91, :_reduce_none, - 3, 91, :_reduce_34, - 3, 91, :_reduce_35, - 1, 92, :_reduce_none, - 1, 92, :_reduce_none, - 1, 92, :_reduce_none, - 1, 92, :_reduce_none, - 1, 92, :_reduce_none, - 1, 92, :_reduce_none, - 1, 92, :_reduce_none, - 1, 92, :_reduce_none, - 1, 92, :_reduce_44, - 5, 74, :_reduce_45, - 5, 74, :_reduce_46, - 5, 74, :_reduce_47, - 5, 85, :_reduce_48, - 2, 75, :_reduce_49, - 1, 108, :_reduce_50, - 2, 108, :_reduce_51, - 6, 76, :_reduce_52, - 2, 76, :_reduce_53, - 3, 109, :_reduce_54, - 3, 109, :_reduce_55, - 1, 110, :_reduce_none, - 1, 110, :_reduce_none, - 3, 110, :_reduce_58, - 1, 111, :_reduce_none, - 3, 111, :_reduce_60, - 1, 112, :_reduce_61, - 1, 112, :_reduce_62, - 3, 113, :_reduce_63, - 3, 113, :_reduce_64, - 1, 114, :_reduce_none, - 1, 114, :_reduce_none, - 4, 116, :_reduce_67, - 1, 102, :_reduce_none, - 3, 102, :_reduce_69, - 0, 103, :_reduce_none, - 1, 103, :_reduce_none, - 1, 118, :_reduce_72, - 1, 93, :_reduce_73, - 1, 95, :_reduce_74, - 1, 117, :_reduce_none, - 1, 117, :_reduce_none, - 1, 117, :_reduce_none, - 1, 117, :_reduce_none, - 1, 117, :_reduce_none, - 1, 117, :_reduce_none, - 1, 117, :_reduce_none, - 3, 77, :_reduce_82, - 3, 77, :_reduce_83, - 3, 86, :_reduce_84, - 0, 104, :_reduce_85, - 1, 104, :_reduce_86, - 3, 104, :_reduce_87, - 3, 122, :_reduce_88, - 3, 124, :_reduce_89, - 1, 125, :_reduce_none, - 1, 125, :_reduce_none, - 0, 107, :_reduce_92, - 1, 107, :_reduce_93, - 3, 107, :_reduce_94, - 1, 126, :_reduce_none, - 3, 126, :_reduce_96, - 1, 115, :_reduce_none, - 1, 115, :_reduce_none, - 1, 115, :_reduce_none, - 1, 115, :_reduce_none, - 1, 115, :_reduce_none, - 1, 115, :_reduce_none, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 1, 123, :_reduce_none, - 4, 97, :_reduce_115, - 3, 97, :_reduce_116, - 1, 99, :_reduce_117, - 2, 99, :_reduce_118, - 2, 129, :_reduce_119, - 1, 130, :_reduce_120, - 2, 130, :_reduce_121, - 1, 96, :_reduce_122, - 4, 90, :_reduce_123, - 4, 90, :_reduce_124, - 2, 79, :_reduce_125, - 5, 131, :_reduce_126, - 4, 131, :_reduce_127, - 0, 132, :_reduce_none, - 2, 132, :_reduce_129, - 4, 132, :_reduce_130, - 3, 132, :_reduce_131, - 1, 120, :_reduce_none, - 3, 120, :_reduce_133, - 3, 120, :_reduce_134, - 3, 120, :_reduce_135, - 3, 120, :_reduce_136, - 3, 120, :_reduce_137, - 3, 120, :_reduce_138, - 3, 120, :_reduce_139, - 3, 120, :_reduce_140, - 3, 120, :_reduce_141, - 2, 120, :_reduce_142, - 3, 120, :_reduce_143, - 3, 120, :_reduce_144, - 3, 120, :_reduce_145, - 3, 120, :_reduce_146, - 3, 120, :_reduce_147, - 3, 120, :_reduce_148, - 2, 120, :_reduce_149, - 3, 120, :_reduce_150, - 3, 120, :_reduce_151, - 3, 120, :_reduce_152, - 5, 78, :_reduce_153, - 1, 134, :_reduce_none, - 2, 134, :_reduce_155, - 5, 135, :_reduce_156, - 4, 135, :_reduce_157, - 1, 136, :_reduce_none, - 3, 136, :_reduce_159, - 3, 98, :_reduce_160, - 1, 138, :_reduce_none, - 4, 138, :_reduce_162, - 1, 140, :_reduce_none, - 3, 140, :_reduce_164, - 3, 139, :_reduce_165, - 1, 137, :_reduce_none, - 1, 137, :_reduce_none, - 1, 137, :_reduce_none, - 1, 137, :_reduce_none, - 1, 137, :_reduce_none, - 1, 137, :_reduce_none, - 1, 137, :_reduce_none, - 1, 137, :_reduce_173, - 1, 137, :_reduce_none, - 1, 141, :_reduce_175, - 1, 142, :_reduce_none, - 3, 142, :_reduce_177, - 2, 80, :_reduce_178, - 6, 82, :_reduce_179, - 5, 82, :_reduce_180, - 7, 83, :_reduce_181, - 6, 83, :_reduce_182, - 6, 84, :_reduce_183, - 5, 84, :_reduce_184, - 1, 106, :_reduce_185, - 1, 101, :_reduce_186, - 1, 101, :_reduce_187, - 1, 101, :_reduce_188, - 1, 145, :_reduce_none, - 3, 145, :_reduce_190, - 1, 147, :_reduce_191, - 1, 148, :_reduce_192, - 1, 148, :_reduce_193, - 1, 148, :_reduce_194, - 1, 148, :_reduce_none, - 0, 72, :_reduce_196, - 0, 149, :_reduce_197, - 1, 143, :_reduce_none, - 3, 143, :_reduce_199, - 3, 143, :_reduce_200, - 1, 150, :_reduce_none, - 3, 150, :_reduce_202, - 3, 151, :_reduce_203, - 1, 151, :_reduce_204, - 3, 151, :_reduce_205, - 1, 151, :_reduce_206, - 1, 146, :_reduce_none, - 2, 146, :_reduce_208, - 1, 144, :_reduce_none, - 2, 144, :_reduce_210, - 1, 152, :_reduce_none, - 1, 152, :_reduce_none, - 1, 94, :_reduce_213, - 3, 119, :_reduce_214, - 4, 119, :_reduce_215, - 2, 119, :_reduce_216, - 1, 127, :_reduce_none, - 1, 127, :_reduce_none, - 0, 105, :_reduce_none, - 1, 105, :_reduce_220, - 1, 133, :_reduce_221, - 3, 128, :_reduce_222, - 4, 128, :_reduce_223, - 2, 128, :_reduce_224, - 1, 153, :_reduce_none, - 3, 153, :_reduce_226, - 3, 154, :_reduce_227, - 1, 155, :_reduce_228, - 1, 155, :_reduce_229, - 4, 121, :_reduce_230, - 1, 100, :_reduce_none, - 4, 100, :_reduce_232 ] - -racc_reduce_n = 233 - -racc_shift_n = 384 +...end grammar.ra/module_eval... +##### State transition tables begin ### racc_action_table = [ 256, 257, 228, 82, 54, 72, 75, 181, 251, 48, 72, 75, 194, 205, 210, 163, 156, 348, 46, 47, 344, 184, 201, 203, 206, 209, 162, 352, 54, 182, 351, 169, 54, -168, 72, 75, 241, 242, 102, 305, 106, 158, 58, 193, 230, 60, 204, 208, 193, 306, 213, 196, 197, 198, 200, 202, 97, 207, 211, 72, 75, 72, 75, 163, 199, 59, 58, 71, 245, 60, 58, 83, 86, 60, 162, 92, 244, 72, 75, 169, 78, 100, 352, 269, 89, 351, 63, 94, 64, 59, 228, 326, 71, 59, 162, 59, 83, 86, 83, 268, 92, 65, 92, 184, 76, 78, 307, 137, 163, 89, 162, 89, 72, 75, 83, 268, 241, 242, 92, 162, 59, 163, 59, 137, 169, 62, 254, 89, 207, 211, 72, 75, 162, 308, 102, 199, 106, 169, 59, 255, 213, 196, 197, 198, -166, 162, 309, 207, 211, 83, 268, 310, 97, 92, 199, 72, 75, 355, 137, 102, -170, 106, 89, 71, 218, 356, 173, 83, 86, 220, 313, 92, -171, 59, 72, 75, 78, 100, 37, 218, 89, 249, 38, 94, 220, 246, 247, 173, 71, 11, 210, 59, 83, 86, 246, 367, 92, 271, 201, 37, -167, 78, 37, 38, 270, 89, 38, 71, 246, 247, 11, 83, 86, 11, 14, 92, 59, 72, 75, 76, 78, 102, 278, 106, 89, 277, 213, 196, 197, 198, 200, 202, 275, 207, 211, 59, 246, 274, 152, 97, 199, 37, 318, 72, 75, 127, 319, 102, -169, 106, 71, 63, 11, 14, 83, 86, -167, 37, 92, 207, 211, 127, -169, 78, 100, 97, 199, 89, 11, 14, 94, -166, 117, 72, 75, -185, 71, 82, 59, 336, 83, 86, 197, 198, 92, 231, 338, 207, 211, 78, 100, 181, 48, 89, 199, 74, 94, 240, -168, 72, 75, 241, 242, 102, 59, 106, 71, 184, 176, 37, 83, 86, 59, 38, 92, 345, 322, 175, 76, 78, 11, 97, -172, 89, -171, 72, 75, -170, 59, 102, 214, 106, 71, 64, 59, 215, 83, 86, 173, 217, 92, -23, -23, -23, -23, 78, 100, 97, 155, 89, 72, 75, 94, 122, 102, 152, 106, 82, 71, 223, 59, 122, 83, 86, 72, 75, 92, -168, 102, 225, 106, 78, 100, -166, 276, 89, 226, 117, 94, 44, 45, 41, 42, 71, -169, -167, 59, 83, 86, 72, 75, 92, 226, 102, 229, 106, 78, 71, 52, -168, 89, 83, 86, 72, 75, 92, -166, 102, -169, 106, 78, 59, 197, 198, 89, -167, -171, 207, 211, 365, 231, 152, 71, 234, 199, 59, 83, 86, 50, 210, 92, -21, -21, -21, -21, 78, 71, 201, 372, 89, 83, 86, 49, 374, 92, 72, 75, 228, -220, 78, 59, 226, 354, 89, 377, 72, 75, 40, 39, 102, 237, 106, 341, nil, 59, 213, 196, 197, 198, 200, 202, nil, 207, 211, nil, nil, nil, 97, 162, 199, nil, nil, 83, 268, nil, nil, 92, nil, 71, nil, nil, 137, 83, 86, nil, 89, 92, 44, 45, 41, 42, 78, 100, 72, 75, 89, 59, 102, 94, 106, 213, 196, 197, 198, 200, 202, 59, 207, 211, nil, 213, 196, 197, 198, 199, 97, nil, 207, 211, 72, 75, nil, nil, 102, 199, 106, 71, nil, nil, nil, 83, 86, nil, nil, 92, nil, nil, nil, nil, 78, 100, 97, nil, 89, nil, nil, 94, nil, nil, 72, 75, nil, 71, 102, 59, 106, 83, 86, nil, nil, 92, nil, nil, nil, nil, 78, 100, nil, nil, 89, nil, 97, 94, nil, nil, 72, 75, nil, nil, 102, 59, 106, 71, nil, nil, nil, 83, 86, nil, nil, 92, nil, nil, nil, nil, 78, 100, 97, nil, 89, 72, 75, 94, nil, 102, nil, 106, nil, 71, nil, 59, nil, 83, 86, 72, 75, 92, nil, 102, nil, nil, 78, 100, nil, nil, 89, nil, nil, 94, nil, nil, nil, nil, 71, nil, nil, 59, 83, 86, 72, 75, 92, nil, 102, nil, 106, 78, 71, nil, nil, 89, 83, 143, nil, nil, 92, nil, nil, nil, nil, 137, 59, nil, nil, 89, 72, 75, nil, nil, 102, nil, 106, 71, nil, nil, 59, 83, 86, nil, nil, 92, nil, nil, nil, nil, 78, nil, 97, nil, 89, nil, 72, 75, nil, nil, 102, nil, 106, 71, nil, 59, nil, 83, 86, nil, nil, 92, nil, nil, nil, nil, 78, 100, 97, nil, 89, nil, nil, 94, nil, nil, 72, 75, nil, 71, 102, 59, 106, 83, 86, nil, nil, 92, nil, nil, nil, nil, 78, 100, nil, nil, 89, nil, 97, 94, nil, nil, 72, 75, nil, nil, 102, 59, 106, 71, nil, nil, nil, 83, 86, nil, nil, 92, nil, nil, nil, nil, 78, 100, 97, nil, 89, 72, 75, 94, nil, 102, nil, 106, nil, 71, nil, 59, nil, 83, 86, nil, nil, 92, nil, nil, nil, nil, 78, 100, nil, nil, 89, 72, 75, 94, nil, 102, nil, 106, 71, nil, nil, 59, 83, 86, nil, nil, 92, nil, nil, nil, nil, 78, nil, 97, nil, 89, nil, 72, 75, nil, nil, 102, nil, 106, 71, nil, 59, nil, 83, 86, nil, nil, 92, nil, nil, 72, 75, 78, 100, 97, nil, 89, 72, 75, 94, nil, 102, nil, 106, nil, 71, nil, 59, nil, 83, 86, nil, nil, 92, nil, nil, nil, nil, 78, 100, nil, nil, 89, 162, nil, 94, nil, 83, 268, nil, 71, 92, nil, 59, 83, 86, 137, nil, 92, nil, 89, nil, nil, 78, 72, 75, nil, 89, 102, nil, 106, 59, nil, nil, nil, nil, nil, nil, 59, nil, nil, nil, nil, 72, 75, nil, 97, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 71, nil, nil, nil, 83, 86, nil, nil, 92, 177, nil, 72, 75, 78, 100, nil, nil, 89, nil, 71, 94, nil, nil, 83, 86, nil, nil, 92, 59, 72, 75, 76, 78, 102, 339, 106, 89, nil, nil, nil, nil, nil, nil, nil, 71, nil, nil, 59, 83, 86, nil, 97, 92, nil, 72, 75, 76, 78, 102, nil, 106, 89, 71, nil, 72, 75, 83, 86, nil, nil, 92, nil, 59, nil, nil, 78, 100, nil, nil, 89, 72, 75, 94, nil, nil, nil, nil, 71, nil, nil, 59, 83, 86, nil, nil, 92, nil, 162, nil, nil, 78, 83, 268, nil, 89, 92, nil, 72, 75, nil, 137, 102, nil, 162, 89, 59, nil, 83, 268, nil, nil, 92, nil, 72, 75, 59, 137, 102, nil, 106, 89, nil, nil, 72, 75, nil, nil, 102, nil, 106, 71, 59, nil, nil, 83, 268, nil, nil, 92, nil, nil, nil, nil, 137, nil, 97, 71, 89, nil, nil, 83, 86, nil, nil, 92, nil, 71, nil, 59, 78, 83, 86, nil, 89, 92, nil, nil, nil, nil, 78, 100, 72, 75, 89, 59, 102, 94, 106, 213, 196, 197, 198, 200, 202, 59, 207, 211, nil, nil, nil, 72, 75, 199, 97, 102, 189, 106, 72, 75, nil, nil, 102, nil, 106, 71, nil, nil, nil, 83, 86, nil, nil, 92, nil, nil, nil, nil, 78, 100, 72, 75, 89, nil, 71, 94, nil, nil, 83, 86, nil, 71, 92, 59, nil, 83, 86, 78, nil, 92, nil, 89, nil, nil, 78, 72, 75, nil, 89, 102, nil, 106, 59, 162, nil, nil, nil, 83, 268, 59, nil, 92, nil, 72, 75, nil, 137, 102, nil, 106, 89, nil, nil, nil, nil, nil, nil, nil, 71, nil, nil, 59, 83, 86, nil, 97, 92, nil, nil, nil, nil, 78, nil, 72, 75, 89, 71, 102, nil, 106, 83, 86, nil, nil, 92, nil, 59, nil, nil, 78, 100, nil, nil, 89, nil, 97, 94, nil, nil, 72, 75, nil, nil, 102, 59, 106, 71, nil, nil, nil, 83, 86, nil, nil, 92, nil, nil, nil, nil, 78, 100, 97, nil, 89, nil, nil, 94, nil, nil, nil, nil, nil, 71, nil, 59, nil, 83, 86, 212, nil, 92, nil, nil, nil, nil, 78, 100, 205, 210, 89, nil, nil, 94, nil, nil, nil, 201, 203, 206, 209, 59, nil, 205, 210, nil, nil, nil, nil, nil, nil, nil, 201, 203, 206, 209, nil, nil, nil, nil, nil, 204, 208, nil, nil, 213, 196, 197, 198, 200, 202, nil, 207, 211, nil, nil, 204, 208, nil, 199, 213, 196, 197, 198, 200, 202, nil, 207, 211, 205, 210, nil, nil, nil, 199, nil, nil, nil, 201, 203, 206, 209, nil, nil, 205, 210, nil, nil, nil, nil, nil, nil, nil, 201, 203, 206, 209, nil, nil, nil, nil, nil, 204, 208, nil, nil, 213, 196, 197, 198, 200, 202, nil, 207, 211, nil, nil, 204, 208, nil, 199, 213, 196, 197, 198, 200, 202, nil, 207, 211, 205, 210, nil, nil, nil, 199, nil, nil, nil, 201, 203, 206, 209, nil, nil, 205, 210, nil, nil, nil, nil, nil, nil, 273, 201, 203, 206, 209, nil, nil, nil, nil, nil, nil, 208, nil, nil, 213, 196, 197, 198, 200, 202, nil, 207, 211, nil, nil, 204, 208, nil, 199, 213, 196, 197, 198, 200, 202, nil, 207, 211, 205, 210, nil, nil, nil, 199, nil, nil, nil, 201, 203, 206, 209, nil, nil, 26, 210, 33, 1, nil, 7, 12, nil, 17, 201, 23, nil, 29, nil, 3, nil, nil, 11, 14, nil, 210, nil, 213, 196, 197, 198, 200, 202, 201, 207, 211, nil, nil, nil, nil, nil, 199, 213, 196, 197, 198, 200, 202, nil, 207, 211, nil, nil, 324, nil, nil, 199, nil, nil, nil, nil, 213, 196, 197, 198, 200, 202, nil, 207, 211, nil, nil, 379, nil, 26, 199, 33, 1, nil, 7, 12, nil, 17, nil, 23, nil, 29, nil, 3, nil, nil, 11, 14, 26, 382, 33, 1, nil, 7, 12, nil, 17, nil, 23, nil, 29, nil, 3, nil, nil, 11, 14, nil, 296, nil, 26, nil, 33, 1, nil, 7, 12, nil, 17, nil, 23, nil, 29, nil, 3, nil, nil, 11, 14, 26, 364, 33, 1, nil, 7, 12, nil, 17, nil, 23, nil, 29, nil, 3, nil, nil, 11, 14, nil, 381, nil, 26, nil, 33, 1, nil, 7, 12, nil, 17, nil, 23, nil, 29, nil, 3, nil, nil, 11, 14, 26, 383, 33, 1, nil, 7, 12, nil, 17, nil, 23, nil, 29, nil, 3, nil, nil, 11, 14, nil, 357, nil, 26, nil, 33, 1, nil, 7, 12, nil, 17, nil, 23, nil, 29, nil, 3, nil, nil, 11, 14, 26, 363, 33, 1, nil, 7, 12, nil, 17, nil, 23, nil, 29, nil, 3, nil, nil, 11, 14, nil, 375, nil, 26, nil, 33, 1, nil, 7, 12, nil, 17, nil, 23, nil, 29, nil, 3, nil, nil, 11, 14, 26, 304, 33, 1, nil, 7, 12, nil, 17, nil, 23, nil, 29, nil, 3, nil, nil, 11, 14, nil, 349, nil, 26, nil, 33, 1, nil, 7, 12, nil, 17, nil, 23, nil, 29, nil, 3, nil, nil, 11, 14, 26, nil, 33, 1, nil, 7, 12, nil, 17, nil, 23, nil, 29, nil, 3, nil, nil, 11, 14, 26, nil, 33, 1, nil, 7, 12, nil, 17, nil, 23, nil, 29, nil, 3, nil, nil, 11, 14 ] racc_action_check = [ 180, 180, 152, 86, 156, 106, 106, 272, 174, 7, 277, 277, 106, 180, 180, 65, 55, 277, 7, 7, 272, 86, 180, 180, 180, 180, 65, 296, 17, 80, 296, 65, 158, 95, 202, 202, 174, 174, 202, 218, 202, 55, 156, 106, 152, 156, 180, 180, 277, 219, 180, 180, 180, 180, 180, 180, 202, 180, 180, 181, 181, 368, 368, 239, 180, 156, 17, 202, 165, 17, 158, 202, 202, 158, 239, 202, 165, 182, 182, 239, 202, 202, 349, 182, 202, 349, 22, 202, 22, 17, 143, 243, 181, 158, 368, 202, 181, 181, 368, 368, 181, 22, 368, 143, 181, 181, 220, 368, 163, 181, 182, 368, 355, 355, 182, 182, 243, 243, 182, 163, 181, 62, 368, 182, 163, 22, 178, 182, 281, 281, 351, 351, 62, 221, 351, 281, 351, 62, 182, 178, 285, 285, 285, 285, 101, 355, 221, 285, 285, 355, 355, 224, 351, 355, 285, 341, 341, 300, 355, 341, 91, 341, 355, 351, 308, 300, 226, 351, 351, 308, 227, 351, 90, 355, 184, 184, 351, 351, 12, 122, 351, 171, 12, 351, 122, 171, 171, 229, 341, 12, 286, 351, 341, 341, 343, 343, 341, 184, 286, 1, 87, 341, 30, 1, 183, 341, 30, 184, 183, 183, 1, 184, 184, 30, 30, 184, 341, 196, 196, 184, 184, 196, 195, 196, 184, 195, 286, 286, 286, 286, 286, 286, 188, 286, 286, 184, 188, 188, 231, 196, 286, 120, 232, 197, 197, 120, 233, 197, 103, 197, 196, 85, 120, 120, 196, 196, 105, 43, 196, 280, 280, 43, 84, 196, 196, 197, 280, 196, 43, 43, 196, 81, 215, 23, 23, 78, 197, 23, 196, 250, 197, 197, 279, 279, 197, 252, 253, 279, 279, 197, 197, 77, 71, 197, 279, 23, 197, 160, 68, 26, 26, 160, 160, 26, 197, 26, 23, 268, 67, 234, 23, 23, 211, 234, 23, 274, 234, 66, 23, 23, 234, 26, 107, 23, 108, 198, 198, 109, 207, 198, 114, 198, 26, 115, 23, 119, 26, 26, 64, 121, 26, 35, 35, 35, 35, 26, 26, 198, 52, 26, 29, 29, 26, 51, 29, 50, 29, 127, 198, 132, 26, 36, 198, 198, 307, 307, 198, 133, 307, 136, 307, 198, 198, 138, 192, 198, 139, 33, 198, 34, 34, 34, 34, 29, 140, 142, 198, 29, 29, 305, 305, 29, 315, 305, 144, 305, 29, 307, 16, 327, 29, 307, 307, 199, 199, 307, 328, 199, 330, 199, 307, 29, 297, 297, 307, 331, 332, 297, 297, 337, 153, 175, 305, 154, 297, 307, 305, 305, 9, 288, 305, 28, 28, 28, 28, 305, 199, 288, 352, 305, 199, 199, 8, 356, 199, 298, 298, 173, 367, 199, 305, 172, 298, 199, 369, 200, 200, 3, 2, 200, 157, 200, 263, nil, 199, 288, 288, 288, 288, 288, 288, nil, 288, 288, nil, nil, nil, 200, 298, 288, nil, nil, 298, 298, nil, nil, 298, nil, 200, nil, nil, 298, 200, 200, nil, 298, 200, 4, 4, 4, 4, 200, 200, 39, 39, 200, 298, 39, 200, 39, 293, 293, 293, 293, 293, 293, 200, 293, 293, nil, 283, 283, 283, 283, 293, 39, nil, 283, 283, 201, 201, nil, nil, 201, 283, 201, 39, nil, nil, nil, 39, 39, nil, nil, 39, nil, nil, nil, nil, 39, 39, 201, nil, 39, nil, nil, 39, nil, nil, 46, 46, nil, 201, 46, 39, 46, 201, 201, nil, nil, 201, nil, nil, nil, nil, 201, 201, nil, nil, 201, nil, 46, 201, nil, nil, 47, 47, nil, nil, 47, 201, 47, 46, nil, nil, nil, 46, 46, nil, nil, 46, nil, nil, nil, nil, 46, 46, 47, nil, 46, 48, 48, 46, nil, 48, nil, 48, nil, 47, nil, 46, nil, 47, 47, 49, 49, 47, nil, 49, nil, nil, 47, 47, nil, nil, 47, nil, nil, 47, nil, nil, nil, nil, 48, nil, nil, 47, 48, 48, 176, 176, 48, nil, 176, nil, 176, 48, 49, nil, nil, 48, 49, 49, nil, nil, 49, nil, nil, nil, nil, 49, 48, nil, nil, 49, 203, 203, nil, nil, 203, nil, 203, 176, nil, nil, 49, 176, 176, nil, nil, 176, nil, nil, nil, nil, 176, nil, 203, nil, 176, nil, 204, 204, nil, nil, 204, nil, 204, 203, nil, 176, nil, 203, 203, nil, nil, 203, nil, nil, nil, nil, 203, 203, 204, nil, 203, nil, nil, 203, nil, nil, 205, 205, nil, 204, 205, 203, 205, 204, 204, nil, nil, 204, nil, nil, nil, nil, 204, 204, nil, nil, 204, nil, 205, 204, nil, nil, 100, 100, nil, nil, 100, 204, 100, 205, nil, nil, nil, 205, 205, nil, nil, 205, nil, nil, nil, nil, 205, 205, 100, nil, 205, 63, 63, 205, nil, 63, nil, 63, nil, 100, nil, 205, nil, 100, 100, nil, nil, 100, nil, nil, nil, nil, 100, 100, nil, nil, 100, 208, 208, 100, nil, 208, nil, 208, 63, nil, nil, 100, 63, 63, nil, nil, 63, nil, nil, nil, nil, 63, nil, 208, nil, 63, nil, 209, 209, nil, nil, 209, nil, 209, 208, nil, 63, nil, 208, 208, nil, nil, 208, nil, nil, 269, 269, 208, 208, 209, nil, 208, 276, 276, 208, nil, 276, nil, 276, nil, 209, nil, 208, nil, 209, 209, nil, nil, 209, nil, nil, nil, nil, 209, 209, nil, nil, 209, 269, nil, 209, nil, 269, 269, nil, 276, 269, nil, 209, 276, 276, 269, nil, 276, nil, 269, nil, nil, 276, 256, 256, nil, 276, 256, nil, 256, 269, nil, nil, nil, nil, nil, nil, 276, nil, nil, nil, nil, 74, 74, nil, 256, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 256, nil, nil, nil, 256, 256, nil, nil, 256, 74, nil, 254, 254, 256, 256, nil, nil, 256, nil, 74, 256, nil, nil, 74, 74, nil, nil, 74, 256, 75, 75, 74, 74, 75, 254, 75, 74, nil, nil, nil, nil, nil, nil, nil, 254, nil, nil, 74, 254, 254, nil, 75, 254, nil, 248, 248, 254, 254, 248, nil, 248, 254, 75, nil, 245, 245, 75, 75, nil, nil, 75, nil, 254, nil, nil, 75, 75, nil, nil, 75, 244, 244, 75, nil, nil, nil, nil, 248, nil, nil, 75, 248, 248, nil, nil, 248, nil, 245, nil, nil, 248, 245, 245, nil, 248, 245, nil, 225, 225, nil, 245, 225, nil, 244, 245, 248, nil, 244, 244, nil, nil, 244, nil, 82, 82, 245, 244, 82, nil, 82, 244, nil, nil, 210, 210, nil, nil, 210, nil, 210, 225, 244, nil, nil, 225, 225, nil, nil, 225, nil, nil, nil, nil, 225, nil, 210, 82, 225, nil, nil, 82, 82, nil, nil, 82, nil, 210, nil, 225, 82, 210, 210, nil, 82, 210, nil, nil, nil, nil, 210, 210, 213, 213, 210, 82, 213, 210, 213, 284, 284, 284, 284, 284, 284, 210, 284, 284, nil, nil, nil, 102, 102, 284, 213, 102, 102, 102, 230, 230, nil, nil, 230, nil, 230, 213, nil, nil, nil, 213, 213, nil, nil, 213, nil, nil, nil, nil, 213, 213, 214, 214, 213, nil, 102, 213, nil, nil, 102, 102, nil, 230, 102, 213, nil, 230, 230, 102, nil, 230, nil, 102, nil, nil, 230, 228, 228, nil, 230, 228, nil, 228, 102, 214, nil, nil, nil, 214, 214, 230, nil, 214, nil, 94, 94, nil, 214, 94, nil, 94, 214, nil, nil, nil, nil, nil, nil, nil, 228, nil, nil, 214, 228, 228, nil, 94, 228, nil, nil, nil, nil, 228, nil, 97, 97, 228, 94, 97, nil, 97, 94, 94, nil, nil, 94, nil, 228, nil, nil, 94, 94, nil, nil, 94, nil, 97, 94, nil, nil, 206, 206, nil, nil, 206, 94, 206, 97, nil, nil, nil, 97, 97, nil, nil, 97, nil, nil, nil, nil, 97, 97, 206, nil, 97, nil, nil, 97, nil, nil, nil, nil, nil, 206, nil, 97, nil, 206, 206, 111, nil, 206, nil, nil, nil, nil, 206, 206, 111, 111, 206, nil, nil, 206, nil, nil, nil, 111, 111, 111, 111, 206, nil, 124, 124, nil, nil, nil, nil, nil, nil, nil, 124, 124, 124, 124, nil, nil, nil, nil, nil, 111, 111, nil, nil, 111, 111, 111, 111, 111, 111, nil, 111, 111, nil, nil, 124, 124, nil, 111, 124, 124, 124, 124, 124, 124, nil, 124, 124, 130, 130, nil, nil, nil, 124, nil, nil, nil, 130, 130, 130, 130, nil, nil, 131, 131, nil, nil, nil, nil, nil, nil, nil, 131, 131, 131, 131, nil, nil, nil, nil, nil, 130, 130, nil, nil, 130, 130, 130, 130, 130, 130, nil, 130, 130, nil, nil, 131, 131, nil, 130, 131, 131, 131, 131, 131, 131, nil, 131, 131, 287, 287, nil, nil, nil, 131, nil, nil, nil, 287, 287, 287, 287, nil, nil, 186, 186, nil, nil, nil, nil, nil, nil, 186, 186, 186, 186, 186, nil, nil, nil, nil, nil, nil, 287, nil, nil, 287, 287, 287, 287, 287, 287, nil, 287, 287, nil, nil, 186, 186, nil, 287, 186, 186, 186, 186, 186, 186, nil, 186, 186, 291, 291, nil, nil, nil, 186, nil, nil, nil, 291, 291, 291, 291, nil, nil, 19, 292, 19, 19, nil, 19, 19, nil, 19, 292, 19, nil, 19, nil, 19, nil, nil, 19, 19, nil, 289, nil, 291, 291, 291, 291, 291, 291, 289, 291, 291, nil, nil, nil, nil, nil, 291, 292, 292, 292, 292, 292, 292, nil, 292, 292, nil, nil, 237, nil, nil, 292, nil, nil, nil, nil, 289, 289, 289, 289, 289, 289, nil, 289, 289, nil, nil, 372, nil, 237, 289, 237, 237, nil, 237, 237, nil, 237, nil, 237, nil, 237, nil, 237, nil, nil, 237, 237, 372, 378, 372, 372, nil, 372, 372, nil, 372, nil, 372, nil, 372, nil, 372, nil, nil, 372, 372, nil, 212, nil, 378, nil, 378, 378, nil, 378, 378, nil, 378, nil, 378, nil, 378, nil, 378, nil, nil, 378, 378, 212, 323, 212, 212, nil, 212, 212, nil, 212, nil, 212, nil, 212, nil, 212, nil, nil, 212, 212, nil, 374, nil, 323, nil, 323, 323, nil, 323, 323, nil, 323, nil, 323, nil, 323, nil, 323, nil, nil, 323, 323, 374, 380, 374, 374, nil, 374, 374, nil, 374, nil, 374, nil, 374, nil, 374, nil, nil, 374, 374, nil, 303, nil, 380, nil, 380, 380, nil, 380, 380, nil, 380, nil, 380, nil, 380, nil, 380, nil, nil, 380, 380, 303, 319, 303, 303, nil, 303, 303, nil, 303, nil, 303, nil, 303, nil, 303, nil, nil, 303, 303, nil, 362, nil, 319, nil, 319, 319, nil, 319, 319, nil, 319, nil, 319, nil, 319, nil, 319, nil, nil, 319, 319, 362, 217, 362, 362, nil, 362, 362, nil, 362, nil, 362, nil, 362, nil, 362, nil, nil, 362, 362, nil, 295, nil, 217, nil, 217, 217, nil, 217, 217, nil, 217, nil, 217, nil, 217, nil, 217, nil, nil, 217, 217, 295, nil, 295, 295, nil, 295, 295, nil, 295, nil, 295, nil, 295, nil, 295, nil, nil, 295, 295, 0, nil, 0, 0, nil, 0, 0, nil, 0, nil, 0, nil, 0, nil, 0, nil, nil, 0, 0 ] racc_action_pointer = [ 1795, 163, 443, 413, 433, nil, nil, 3, 434, 420, nil, nil, 142, nil, nil, nil, 398, 26, nil, 1483, nil, nil, 80, 271, nil, nil, 297, nil, 367, 348, 166, nil, nil, 375, 315, 277, 337, nil, nil, 501, nil, nil, nil, 221, nil, nil, 557, 583, 608, 622, 315, 329, 348, nil, nil, 4, nil, nil, nil, nil, nil, nil, 97, 780, 298, -9, 309, 302, 275, nil, nil, 286, nil, nil, 923, 966, nil, 279, 269, nil, 6, 248, 1060, nil, 239, 245, -3, 177, nil, nil, 149, 137, nil, nil, 1209, 10, nil, 1239, nil, nil, 755, 121, 1137, 225, nil, 233, 3, 299, 301, 304, nil, 1298, nil, nil, 322, 325, nil, nil, nil, 323, 205, 331, 144, nil, 1313, nil, nil, 351, nil, nil, 1359, 1374, 352, 344, nil, nil, 328, nil, 350, 364, 361, nil, 362, 79, 374, nil, nil, nil, nil, nil, nil, nil, -9, 408, 386, nil, 2, 452, 30, nil, 251, nil, nil, 84, nil, 50, nil, nil, nil, nil, nil, 174, 439, 436, -14, 381, 647, nil, 114, nil, -4, 57, 75, 197, 172, nil, 1435, nil, 225, nil, nil, nil, 363, nil, nil, 213, 215, 241, 323, 401, 453, 527, 32, 673, 699, 729, 1265, 265, 806, 832, 1070, 249, 1612, 1118, 1166, 270, nil, 1757, 24, 24, 91, 121, nil, nil, 142, 1044, 126, 161, 1191, 147, 1144, 198, 233, 238, 273, nil, nil, 1552, nil, 39, nil, nil, nil, 66, 1017, 1001, nil, nil, 991, nil, 270, nil, 273, 279, 948, nil, 904, nil, nil, nil, nil, nil, nil, 451, nil, nil, nil, nil, 283, 850, nil, nil, -5, nil, 308, nil, 857, 8, nil, 226, 198, 67, nil, 466, 1073, 86, 172, 1420, 411, 1515, nil, 1481, 1496, 456, nil, 1776, -4, 356, 443, nil, 145, nil, nil, 1694, nil, 387, nil, 362, 129, nil, nil, nil, nil, nil, nil, 380, nil, nil, nil, 1716, nil, nil, nil, 1634, nil, nil, nil, 376, 383, nil, 385, 392, 393, nil, nil, nil, nil, 410, nil, nil, nil, 153, nil, 183, nil, nil, nil, nil, nil, 51, nil, 128, 430, nil, nil, 110, 435, nil, nil, nil, nil, nil, 1735, nil, nil, nil, nil, 439, 59, 445, nil, nil, 1571, nil, 1653, nil, nil, nil, 1593, nil, 1675, nil, nil, nil ] racc_action_default = [ -196, -233, -233, -50, -233, -8, -9, -233, -233, -22, -10, -187, -188, -11, -185, -12, -233, -233, -13, -1, -14, -2, -233, -186, -15, -3, -233, -16, -5, -233, -233, -17, -6, -233, -18, -7, -196, -188, -186, -233, -51, -26, -27, -233, -24, -25, -233, -233, -233, -85, -92, -196, -233, -195, -193, -196, -189, -191, -192, -221, -194, -4, -196, -233, -85, -196, -53, -231, -42, -174, -43, -213, -117, -33, -233, -233, -44, -31, -74, -32, -233, -36, -233, -122, -37, -233, -73, -38, -172, -72, -39, -40, -173, -41, -233, -103, -111, -233, -132, -112, -233, -104, -233, -108, -110, -105, -233, -114, -106, -113, -109, -233, -125, -107, -233, -233, -49, -175, -176, -178, -233, -233, -197, -198, -83, -19, -22, -186, -21, -23, -82, -84, -233, -75, -86, -81, -70, -74, -76, -219, -79, -68, -77, -73, -233, -171, -170, -80, -78, -90, -91, -93, -233, -219, -196, 384, -233, -233, -233, -207, -233, -57, -213, -196, -59, -233, -66, -65, -56, -73, -95, -233, -219, -233, -233, -92, -233, -30, -233, -118, -233, -233, -233, -233, -233, -142, -233, -149, -233, -216, -229, -225, -233, -228, -224, -233, -233, -233, -233, -233, -233, -233, -233, -233, -233, -233, -233, -233, -233, -233, -233, -233, -233, -233, -233, -233, -20, -233, -206, -233, -204, -233, -201, -230, -233, -71, -220, -233, -233, -85, -233, -220, -233, -233, -233, -209, -190, -233, -208, -233, -54, -62, -61, -233, -233, -233, -217, -218, -233, -124, -233, -55, -219, -233, -233, -28, -233, -120, -119, -35, -34, -168, -166, -233, -169, -160, -167, -161, -73, -233, -123, -116, -233, -152, -218, -214, -233, -233, -222, -137, -139, -138, -133, -140, -144, -141, -146, -151, -148, -145, -134, -150, -147, -143, -135, -233, -128, -136, -233, -154, -233, -158, -177, -233, -180, -233, -199, -233, -233, -200, -45, -69, -87, -46, -88, -219, -89, -94, -48, -233, -211, -210, -212, -233, -184, -58, -60, -97, -98, -63, -102, -99, -100, -101, -64, -96, -47, -233, -232, -29, -121, -233, -163, -219, -115, -215, -227, -226, -223, -128, -127, -233, -233, -155, -153, -233, -233, -179, -205, -203, -202, -67, -233, -182, -183, -52, -165, -218, -233, -233, -126, -129, -233, -159, -233, -181, -164, -162, -233, -131, -233, -157, -130, -156 ] racc_goto_table = [ 22, 9, 68, 112, 53, 118, 61, 36, 91, 222, 19, 267, 70, 93, 2, 227, 139, 191, 51, 22, 9, 179, 77, 56, 73, 149, 21, 141, 133, 232, 115, 172, 153, 2, 146, 263, 125, 116, 135, 148, 147, 299, 129, 22, 126, 260, 160, 350, 250, 174, 128, 171, 43, 68, 121, 329, 334, 298, 368, 91, 258, 265, 123, 70, 93, 317, 343, 301, 136, 154, 183, 119, 224, 178, 233, 73, 55, 123, 157, 66, 238, 159, 120, 219, 221, 190, 325, 321, 195, 16, 188, nil, nil, nil, nil, nil, nil, nil, 342, nil, 370, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 216, nil, nil, nil, nil, 260, 129, 22, 126, 263, nil, nil, 353, nil, 128, 337, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 81, nil, nil, nil, 53, nil, 53, nil, 243, nil, nil, 149, 301, nil, nil, nil, nil, nil, 252, nil, nil, 68, 261, 236, 68, nil, 138, 91, 146, nil, 91, 70, 93, nil, 70, 93, nil, nil, nil, 166, nil, 235, 166, 259, 272, nil, 73, nil, 302, 347, nil, 81, 361, nil, 261, 290, 360, 315, 376, 294, 146, nil, 312, 340, 311, 133, nil, 149, nil, 373, nil, 146, nil, 22, 9, 135, 148, 147, 22, 9, 369, nil, 263, 295, 327, 327, nil, 2, 303, nil, 146, 146, 2, nil, 68, 333, 333, nil, 22, 9, 91, 320, 88, nil, 70, 93, nil, nil, 323, 261, nil, nil, 2, nil, nil, 146, 259, 190, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 88, nil, nil, nil, nil, nil, nil, nil, 87, nil, 261, nil, 166, nil, nil, 61, 146, nil, nil, nil, nil, nil, nil, 61, nil, 88, nil, nil, 22, 9, 81, 262, nil, 81, 142, nil, 22, 9, nil, nil, nil, nil, 2, 61, nil, nil, nil, nil, nil, nil, 2, nil, 22, 9, nil, nil, 22, 9, nil, 87, nil, 371, 362, 262, nil, nil, 2, 261, nil, nil, 2, nil, nil, 146, 138, nil, nil, nil, nil, nil, 261, nil, 61, nil, nil, nil, 146, nil, 166, nil, nil, nil, nil, 328, 328, 22, 9, 114, 61, nil, 61, nil, 84, 81, nil, 22, 9, 22, 9, 2, 90, 22, 9, 22, 9, 378, 132, 380, 262, 2, nil, 2, nil, nil, nil, 2, nil, 2, 140, nil, nil, 170, 88, 88, nil, 88, 145, nil, nil, nil, nil, 167, nil, nil, 167, nil, nil, 262, nil, nil, 170, nil, nil, 84, nil, nil, nil, nil, nil, nil, nil, 90, nil, nil, nil, 88, 87, 266, nil, 87, 170, nil, nil, nil, nil, nil, 88, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 88, 88, nil, nil, 266, nil, nil, nil, nil, 262, 88, nil, nil, nil, nil, 142, nil, nil, nil, nil, nil, nil, 262, nil, nil, 88, nil, nil, nil, nil, nil, nil, nil, nil, 331, 331, nil, nil, nil, nil, nil, nil, nil, nil, 87, nil, nil, 167, nil, 253, nil, nil, nil, nil, 88, nil, nil, nil, nil, 266, nil, nil, nil, nil, nil, 84, 264, nil, 84, nil, nil, nil, 282, 90, 145, nil, 90, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 266, nil, nil, nil, nil, nil, nil, nil, nil, nil, 264, nil, nil, 314, nil, 316, nil, 124, 145, nil, nil, 140, nil, 88, 130, 131, nil, nil, nil, 145, nil, nil, nil, 335, nil, 167, 88, nil, nil, nil, 330, 330, nil, nil, nil, nil, nil, nil, 332, 332, 84, nil, nil, 180, nil, nil, nil, 266, 90, nil, nil, 346, nil, nil, nil, 264, nil, nil, nil, nil, 266, nil, 185, 145, nil, 186, nil, nil, 187, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 358, nil, 359, nil, 264, nil, nil, nil, nil, nil, nil, nil, 145, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 366, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 264, nil, nil, nil, nil, nil, nil, nil, 145, nil, nil, nil, nil, 264, nil, nil, nil, nil, nil, nil, nil, 145, nil, 279, 280, 281, nil, 283, 284, 285, 286, 287, 288, 289, nil, 291, 292, 293, nil, nil, 297, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 180 ] racc_goto_check = [ 37, 21, 30, 62, 64, 72, 4, 32, 28, 82, 2, 70, 31, 29, 52, 36, 35, 85, 32, 37, 21, 60, 22, 78, 21, 53, 3, 47, 30, 36, 37, 35, 38, 52, 28, 68, 19, 5, 31, 29, 50, 66, 7, 37, 21, 23, 41, 63, 36, 41, 5, 57, 20, 30, 74, 46, 46, 65, 58, 28, 61, 69, 3, 31, 29, 56, 71, 68, 33, 74, 57, 73, 34, 22, 75, 21, 76, 3, 77, 40, 79, 3, 20, 80, 81, 30, 42, 83, 84, 1, 57, nil, nil, nil, nil, nil, nil, nil, 70, nil, 63, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 19, nil, nil, nil, nil, 23, 7, 37, 21, 68, nil, nil, 66, nil, 5, 36, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 24, nil, nil, nil, 64, nil, 64, nil, 41, nil, nil, 53, 68, nil, nil, nil, nil, nil, 38, nil, nil, 30, 30, 78, 30, nil, 24, 28, 28, nil, 28, 31, 29, nil, 31, 29, nil, nil, nil, 24, nil, 3, 24, 21, 22, nil, 21, nil, 72, 85, nil, 24, 36, nil, 30, 64, 82, 35, 70, 64, 28, nil, 53, 60, 47, 30, nil, 53, nil, 68, nil, 28, nil, 37, 21, 31, 29, 50, 37, 21, 36, nil, 68, 2, 30, 30, nil, 52, 2, nil, 28, 28, 52, nil, 30, 29, 29, nil, 37, 21, 28, 32, 49, nil, 31, 29, nil, nil, 2, 30, nil, nil, 52, nil, nil, 28, 21, 30, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 49, nil, nil, nil, nil, nil, nil, nil, 26, nil, 30, nil, 24, nil, nil, 4, 28, nil, nil, nil, nil, nil, nil, 4, nil, 49, nil, nil, 37, 21, 24, 24, nil, 24, 26, nil, 37, 21, nil, nil, nil, nil, 52, 4, nil, nil, nil, nil, nil, nil, 52, nil, 37, 21, nil, nil, 37, 21, nil, 26, nil, 62, 2, 24, nil, nil, 52, 30, nil, nil, 52, nil, nil, 28, 24, nil, nil, nil, nil, nil, 30, nil, 4, nil, nil, nil, 28, nil, 24, nil, nil, nil, nil, 24, 24, 37, 21, 54, 4, nil, 4, nil, 25, 24, nil, 37, 21, 37, 21, 52, 27, 37, 21, 37, 21, 2, 54, 2, 24, 52, nil, 52, nil, nil, nil, 52, nil, 52, 25, nil, nil, 54, 49, 49, nil, 49, 27, nil, nil, nil, nil, 25, nil, nil, 25, nil, nil, 24, nil, nil, 54, nil, nil, 25, nil, nil, nil, nil, nil, nil, nil, 27, nil, nil, nil, 49, 26, 26, nil, 26, 54, nil, nil, nil, nil, nil, 49, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 49, 49, nil, nil, 26, nil, nil, nil, nil, 24, 49, nil, nil, nil, nil, 26, nil, nil, nil, nil, nil, nil, 24, nil, nil, 49, nil, nil, nil, nil, nil, nil, nil, nil, 26, 26, nil, nil, nil, nil, nil, nil, nil, nil, 26, nil, nil, 25, nil, 54, nil, nil, nil, nil, 49, nil, nil, nil, nil, 26, nil, nil, nil, nil, nil, 25, 25, nil, 25, nil, nil, nil, 54, 27, 27, nil, 27, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 26, nil, nil, nil, nil, nil, nil, nil, nil, nil, 25, nil, nil, 54, nil, 54, nil, 51, 27, nil, nil, 25, nil, 49, 51, 51, nil, nil, nil, 27, nil, nil, nil, 54, nil, 25, 49, nil, nil, nil, 25, 25, nil, nil, nil, nil, nil, nil, 27, 27, 25, nil, nil, 51, nil, nil, nil, 26, 27, nil, nil, 54, nil, nil, nil, 25, nil, nil, nil, nil, 26, nil, 51, 27, nil, 51, nil, nil, 51, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 54, nil, 54, nil, 25, nil, nil, nil, nil, nil, nil, nil, 27, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 54, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 25, nil, nil, nil, nil, nil, nil, nil, 27, nil, nil, nil, nil, 25, nil, nil, nil, nil, nil, nil, nil, 27, nil, 51, 51, 51, nil, 51, 51, 51, 51, 51, 51, 51, nil, 51, 51, 51, nil, nil, 51, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 51 ] racc_goto_pointer = [ nil, 89, 10, 26, -13, 7, nil, -1, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, -7, 48, 1, -1, -136, 116, 346, 252, 354, -15, -10, -21, -11, 6, 19, -64, -33, -124, 0, -18, nil, 57, -16, -153, nil, nil, nil, -189, -22, nil, 218, -9, 528, 14, -25, 335, nil, -166, -12, -285, nil, -54, -120, -23, -249, -13, -157, -173, nil, -147, -121, -171, -203, -28, 38, 18, -80, 59, 23, 6, -78, -39, -38, -113, -147, -18, -89, nil ] racc_goto_default = [ nil, nil, nil, 168, 25, 28, 32, 35, 5, 6, 10, 13, 15, 18, 20, 24, 27, 31, 34, 4, nil, 99, nil, 79, 101, 103, 105, 108, 109, 113, 95, 96, 8, nil, nil, nil, nil, 85, nil, 30, nil, nil, 161, 239, 164, 165, nil, nil, 144, 107, 110, 111, 67, 134, 98, 150, 151, nil, 248, 104, nil, nil, nil, nil, 69, nil, nil, 300, 80, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 57, nil, nil, nil, nil, nil, nil, 192 ] -racc_token_table = { - false => 0, - Object.new => 1, - :STRING => 2, - :DQPRE => 3, - :DQMID => 4, - :DQPOST => 5, - :LBRACK => 6, - :RBRACK => 7, - :LBRACE => 8, - :RBRACE => 9, - :SYMBOL => 10, - :FARROW => 11, - :COMMA => 12, - :TRUE => 13, - :FALSE => 14, - :EQUALS => 15, - :APPENDS => 16, - :LESSEQUAL => 17, - :NOTEQUAL => 18, - :DOT => 19, - :COLON => 20, - :LLCOLLECT => 21, - :RRCOLLECT => 22, - :QMARK => 23, - :LPAREN => 24, - :RPAREN => 25, - :ISEQUAL => 26, - :GREATEREQUAL => 27, - :GREATERTHAN => 28, - :LESSTHAN => 29, - :IF => 30, - :ELSE => 31, - :IMPORT => 32, - :DEFINE => 33, - :ELSIF => 34, - :VARIABLE => 35, - :CLASS => 36, - :INHERITS => 37, - :NODE => 38, - :BOOLEAN => 39, - :NAME => 40, - :SEMIC => 41, - :CASE => 42, - :DEFAULT => 43, - :AT => 44, - :LCOLLECT => 45, - :RCOLLECT => 46, - :CLASSNAME => 47, - :CLASSREF => 48, - :NOT => 49, - :OR => 50, - :AND => 51, - :UNDEF => 52, - :PARROW => 53, - :PLUS => 54, - :MINUS => 55, - :TIMES => 56, - :DIV => 57, - :LSHIFT => 58, - :RSHIFT => 59, - :UMINUS => 60, - :MATCH => 61, - :NOMATCH => 62, - :REGEX => 63, - :IN_EDGE => 64, - :OUT_EDGE => 65, - :IN_EDGE_SUB => 66, - :OUT_EDGE_SUB => 67, - :IN => 68 } +racc_reduce_table = [ + 0, 0, :racc_error, + 1, 70, :_reduce_1, + 1, 70, :_reduce_none, + 1, 71, :_reduce_3, + 2, 71, :_reduce_4, + 1, 73, :_reduce_none, + 1, 73, :_reduce_none, + 1, 73, :_reduce_none, + 1, 73, :_reduce_none, + 1, 73, :_reduce_none, + 1, 73, :_reduce_none, + 1, 73, :_reduce_none, + 1, 73, :_reduce_none, + 1, 73, :_reduce_none, + 1, 73, :_reduce_none, + 1, 73, :_reduce_none, + 1, 73, :_reduce_none, + 1, 73, :_reduce_none, + 1, 73, :_reduce_none, + 3, 87, :_reduce_19, + 3, 87, :_reduce_20, + 1, 88, :_reduce_none, + 1, 88, :_reduce_none, + 1, 88, :_reduce_none, + 1, 89, :_reduce_none, + 1, 89, :_reduce_none, + 1, 89, :_reduce_none, + 1, 89, :_reduce_none, + 4, 81, :_reduce_28, + 5, 81, :_reduce_29, + 3, 81, :_reduce_30, + 2, 81, :_reduce_31, + 1, 91, :_reduce_none, + 1, 91, :_reduce_none, + 3, 91, :_reduce_34, + 3, 91, :_reduce_35, + 1, 92, :_reduce_none, + 1, 92, :_reduce_none, + 1, 92, :_reduce_none, + 1, 92, :_reduce_none, + 1, 92, :_reduce_none, + 1, 92, :_reduce_none, + 1, 92, :_reduce_none, + 1, 92, :_reduce_none, + 1, 92, :_reduce_44, + 5, 74, :_reduce_45, + 5, 74, :_reduce_46, + 5, 74, :_reduce_47, + 5, 85, :_reduce_48, + 2, 75, :_reduce_49, + 1, 108, :_reduce_50, + 2, 108, :_reduce_51, + 6, 76, :_reduce_52, + 2, 76, :_reduce_53, + 3, 109, :_reduce_54, + 3, 109, :_reduce_55, + 1, 110, :_reduce_none, + 1, 110, :_reduce_none, + 3, 110, :_reduce_58, + 1, 111, :_reduce_none, + 3, 111, :_reduce_60, + 1, 112, :_reduce_61, + 1, 112, :_reduce_62, + 3, 113, :_reduce_63, + 3, 113, :_reduce_64, + 1, 114, :_reduce_none, + 1, 114, :_reduce_none, + 4, 116, :_reduce_67, + 1, 102, :_reduce_none, + 3, 102, :_reduce_69, + 0, 103, :_reduce_none, + 1, 103, :_reduce_none, + 1, 118, :_reduce_72, + 1, 93, :_reduce_73, + 1, 95, :_reduce_74, + 1, 117, :_reduce_none, + 1, 117, :_reduce_none, + 1, 117, :_reduce_none, + 1, 117, :_reduce_none, + 1, 117, :_reduce_none, + 1, 117, :_reduce_none, + 1, 117, :_reduce_none, + 3, 77, :_reduce_82, + 3, 77, :_reduce_83, + 3, 86, :_reduce_84, + 0, 104, :_reduce_85, + 1, 104, :_reduce_86, + 3, 104, :_reduce_87, + 3, 122, :_reduce_88, + 3, 124, :_reduce_89, + 1, 125, :_reduce_none, + 1, 125, :_reduce_none, + 0, 107, :_reduce_92, + 1, 107, :_reduce_93, + 3, 107, :_reduce_94, + 1, 126, :_reduce_none, + 3, 126, :_reduce_96, + 1, 115, :_reduce_none, + 1, 115, :_reduce_none, + 1, 115, :_reduce_none, + 1, 115, :_reduce_none, + 1, 115, :_reduce_none, + 1, 115, :_reduce_none, + 1, 123, :_reduce_none, + 1, 123, :_reduce_none, + 1, 123, :_reduce_none, + 1, 123, :_reduce_none, + 1, 123, :_reduce_none, + 1, 123, :_reduce_none, + 1, 123, :_reduce_none, + 1, 123, :_reduce_none, + 1, 123, :_reduce_none, + 1, 123, :_reduce_none, + 1, 123, :_reduce_none, + 1, 123, :_reduce_none, + 4, 97, :_reduce_115, + 3, 97, :_reduce_116, + 1, 99, :_reduce_117, + 2, 99, :_reduce_118, + 2, 129, :_reduce_119, + 1, 130, :_reduce_120, + 2, 130, :_reduce_121, + 1, 96, :_reduce_122, + 4, 90, :_reduce_123, + 4, 90, :_reduce_124, + 2, 79, :_reduce_125, + 5, 131, :_reduce_126, + 4, 131, :_reduce_127, + 0, 132, :_reduce_none, + 2, 132, :_reduce_129, + 4, 132, :_reduce_130, + 3, 132, :_reduce_131, + 1, 120, :_reduce_none, + 3, 120, :_reduce_133, + 3, 120, :_reduce_134, + 3, 120, :_reduce_135, + 3, 120, :_reduce_136, + 3, 120, :_reduce_137, + 3, 120, :_reduce_138, + 3, 120, :_reduce_139, + 3, 120, :_reduce_140, + 3, 120, :_reduce_141, + 2, 120, :_reduce_142, + 3, 120, :_reduce_143, + 3, 120, :_reduce_144, + 3, 120, :_reduce_145, + 3, 120, :_reduce_146, + 3, 120, :_reduce_147, + 3, 120, :_reduce_148, + 2, 120, :_reduce_149, + 3, 120, :_reduce_150, + 3, 120, :_reduce_151, + 3, 120, :_reduce_152, + 5, 78, :_reduce_153, + 1, 134, :_reduce_none, + 2, 134, :_reduce_155, + 5, 135, :_reduce_156, + 4, 135, :_reduce_157, + 1, 136, :_reduce_none, + 3, 136, :_reduce_159, + 3, 98, :_reduce_160, + 1, 138, :_reduce_none, + 4, 138, :_reduce_162, + 1, 140, :_reduce_none, + 3, 140, :_reduce_164, + 3, 139, :_reduce_165, + 1, 137, :_reduce_none, + 1, 137, :_reduce_none, + 1, 137, :_reduce_none, + 1, 137, :_reduce_none, + 1, 137, :_reduce_none, + 1, 137, :_reduce_none, + 1, 137, :_reduce_none, + 1, 137, :_reduce_173, + 1, 137, :_reduce_none, + 1, 141, :_reduce_175, + 1, 142, :_reduce_none, + 3, 142, :_reduce_177, + 2, 80, :_reduce_178, + 6, 82, :_reduce_179, + 5, 82, :_reduce_180, + 7, 83, :_reduce_181, + 6, 83, :_reduce_182, + 6, 84, :_reduce_183, + 5, 84, :_reduce_184, + 1, 106, :_reduce_185, + 1, 101, :_reduce_186, + 1, 101, :_reduce_187, + 1, 101, :_reduce_188, + 1, 145, :_reduce_189, + 3, 145, :_reduce_190, + 1, 147, :_reduce_191, + 1, 148, :_reduce_192, + 1, 148, :_reduce_193, + 1, 148, :_reduce_194, + 1, 148, :_reduce_none, + 0, 72, :_reduce_196, + 0, 149, :_reduce_197, + 1, 143, :_reduce_none, + 3, 143, :_reduce_199, + 3, 143, :_reduce_200, + 1, 150, :_reduce_none, + 3, 150, :_reduce_202, + 3, 151, :_reduce_203, + 1, 151, :_reduce_204, + 3, 151, :_reduce_205, + 1, 151, :_reduce_206, + 1, 146, :_reduce_none, + 2, 146, :_reduce_208, + 1, 144, :_reduce_none, + 2, 144, :_reduce_210, + 1, 152, :_reduce_none, + 1, 152, :_reduce_none, + 1, 94, :_reduce_213, + 3, 119, :_reduce_214, + 4, 119, :_reduce_215, + 2, 119, :_reduce_216, + 1, 127, :_reduce_none, + 1, 127, :_reduce_none, + 0, 105, :_reduce_none, + 1, 105, :_reduce_220, + 1, 133, :_reduce_221, + 3, 128, :_reduce_222, + 4, 128, :_reduce_223, + 2, 128, :_reduce_224, + 1, 153, :_reduce_none, + 3, 153, :_reduce_226, + 3, 154, :_reduce_227, + 1, 155, :_reduce_228, + 1, 155, :_reduce_229, + 4, 121, :_reduce_230, + 1, 100, :_reduce_none, + 4, 100, :_reduce_232 ] -racc_use_result_var = true +racc_reduce_n = 233 + +racc_shift_n = 384 + +racc_token_table = { + false => 0, + :error => 1, + :STRING => 2, + :DQPRE => 3, + :DQMID => 4, + :DQPOST => 5, + :LBRACK => 6, + :RBRACK => 7, + :LBRACE => 8, + :RBRACE => 9, + :SYMBOL => 10, + :FARROW => 11, + :COMMA => 12, + :TRUE => 13, + :FALSE => 14, + :EQUALS => 15, + :APPENDS => 16, + :LESSEQUAL => 17, + :NOTEQUAL => 18, + :DOT => 19, + :COLON => 20, + :LLCOLLECT => 21, + :RRCOLLECT => 22, + :QMARK => 23, + :LPAREN => 24, + :RPAREN => 25, + :ISEQUAL => 26, + :GREATEREQUAL => 27, + :GREATERTHAN => 28, + :LESSTHAN => 29, + :IF => 30, + :ELSE => 31, + :IMPORT => 32, + :DEFINE => 33, + :ELSIF => 34, + :VARIABLE => 35, + :CLASS => 36, + :INHERITS => 37, + :NODE => 38, + :BOOLEAN => 39, + :NAME => 40, + :SEMIC => 41, + :CASE => 42, + :DEFAULT => 43, + :AT => 44, + :LCOLLECT => 45, + :RCOLLECT => 46, + :CLASSNAME => 47, + :CLASSREF => 48, + :NOT => 49, + :OR => 50, + :AND => 51, + :UNDEF => 52, + :PARROW => 53, + :PLUS => 54, + :MINUS => 55, + :TIMES => 56, + :DIV => 57, + :LSHIFT => 58, + :RSHIFT => 59, + :UMINUS => 60, + :MATCH => 61, + :NOMATCH => 62, + :REGEX => 63, + :IN_EDGE => 64, + :OUT_EDGE => 65, + :IN_EDGE_SUB => 66, + :OUT_EDGE_SUB => 67, + :IN => 68 } racc_nt_base = 69 +racc_use_result_var = true + Racc_arg = [ - racc_action_table, - racc_action_check, - racc_action_default, - racc_action_pointer, - racc_goto_table, - racc_goto_check, - racc_goto_default, - racc_goto_pointer, - racc_nt_base, - racc_reduce_table, - racc_token_table, - racc_shift_n, - racc_reduce_n, - racc_use_result_var ] + racc_action_table, + racc_action_check, + racc_action_default, + racc_action_pointer, + racc_goto_table, + racc_goto_check, + racc_goto_default, + racc_goto_pointer, + racc_nt_base, + racc_reduce_table, + racc_token_table, + racc_shift_n, + racc_reduce_n, + racc_use_result_var ] Racc_token_to_s_table = [ -'$end', -'error', -'STRING', -'DQPRE', -'DQMID', -'DQPOST', -'LBRACK', -'RBRACK', -'LBRACE', -'RBRACE', -'SYMBOL', -'FARROW', -'COMMA', -'TRUE', -'FALSE', -'EQUALS', -'APPENDS', -'LESSEQUAL', -'NOTEQUAL', -'DOT', -'COLON', -'LLCOLLECT', -'RRCOLLECT', -'QMARK', -'LPAREN', -'RPAREN', -'ISEQUAL', -'GREATEREQUAL', -'GREATERTHAN', -'LESSTHAN', -'IF', -'ELSE', -'IMPORT', -'DEFINE', -'ELSIF', -'VARIABLE', -'CLASS', -'INHERITS', -'NODE', -'BOOLEAN', -'NAME', -'SEMIC', -'CASE', -'DEFAULT', -'AT', -'LCOLLECT', -'RCOLLECT', -'CLASSNAME', -'CLASSREF', -'NOT', -'OR', -'AND', -'UNDEF', -'PARROW', -'PLUS', -'MINUS', -'TIMES', -'DIV', -'LSHIFT', -'RSHIFT', -'UMINUS', -'MATCH', -'NOMATCH', -'REGEX', -'IN_EDGE', -'OUT_EDGE', -'IN_EDGE_SUB', -'OUT_EDGE_SUB', -'IN', -'$start', -'program', -'statements', -'nil', -'statement', -'resource', -'virtualresource', -'collection', -'assignment', -'casestatement', -'ifstatement_begin', -'import', -'fstatement', -'definition', -'hostclass', -'nodedef', -'resourceoverride', -'append', -'relationship', -'relationship_side', -'edge', -'resourceref', -'funcvalues', -'namestring', -'name', -'variable', -'type', -'boolean', -'funcrvalue', -'selector', -'quotedtext', -'hasharrayaccesses', -'classname', -'resourceinstances', -'endsemi', -'params', -'endcomma', -'classref', -'anyparams', -'at', -'collectrhand', -'collstatements', -'collstatement', -'colljoin', -'collexpr', -'colllval', -'simplervalue', -'resourceinst', -'resourcename', -'undef', -'array', -'expression', -'hasharrayaccess', -'param', -'rvalue', -'addparam', -'anyparam', -'rvalues', -'comma', -'hash', -'dqrval', -'dqtail', -'ifstatement', -'else', -'regex', -'caseopts', -'caseopt', -'casevalues', -'selectlhand', -'svalues', -'selectval', -'sintvalues', -'string', -'strings', -'argumentlist', -'classparent', -'hostnames', -'nodeparent', -'nodename', -'hostname', -'nothing', -'arguments', -'argument', -'classnameordefault', -'hashpairs', -'hashpair', -'key'] + "$end", + "error", + "STRING", + "DQPRE", + "DQMID", + "DQPOST", + "LBRACK", + "RBRACK", + "LBRACE", + "RBRACE", + "SYMBOL", + "FARROW", + "COMMA", + "TRUE", + "FALSE", + "EQUALS", + "APPENDS", + "LESSEQUAL", + "NOTEQUAL", + "DOT", + "COLON", + "LLCOLLECT", + "RRCOLLECT", + "QMARK", + "LPAREN", + "RPAREN", + "ISEQUAL", + "GREATEREQUAL", + "GREATERTHAN", + "LESSTHAN", + "IF", + "ELSE", + "IMPORT", + "DEFINE", + "ELSIF", + "VARIABLE", + "CLASS", + "INHERITS", + "NODE", + "BOOLEAN", + "NAME", + "SEMIC", + "CASE", + "DEFAULT", + "AT", + "LCOLLECT", + "RCOLLECT", + "CLASSNAME", + "CLASSREF", + "NOT", + "OR", + "AND", + "UNDEF", + "PARROW", + "PLUS", + "MINUS", + "TIMES", + "DIV", + "LSHIFT", + "RSHIFT", + "UMINUS", + "MATCH", + "NOMATCH", + "REGEX", + "IN_EDGE", + "OUT_EDGE", + "IN_EDGE_SUB", + "OUT_EDGE_SUB", + "IN", + "$start", + "program", + "statements", + "nil", + "statement", + "resource", + "virtualresource", + "collection", + "assignment", + "casestatement", + "ifstatement_begin", + "import", + "fstatement", + "definition", + "hostclass", + "nodedef", + "resourceoverride", + "append", + "relationship", + "relationship_side", + "edge", + "resourceref", + "funcvalues", + "namestring", + "name", + "variable", + "type", + "boolean", + "funcrvalue", + "selector", + "quotedtext", + "hasharrayaccesses", + "classname", + "resourceinstances", + "endsemi", + "params", + "endcomma", + "classref", + "anyparams", + "at", + "collectrhand", + "collstatements", + "collstatement", + "colljoin", + "collexpr", + "colllval", + "simplervalue", + "resourceinst", + "resourcename", + "undef", + "array", + "expression", + "hasharrayaccess", + "param", + "rvalue", + "addparam", + "anyparam", + "rvalues", + "comma", + "hash", + "dqrval", + "dqtail", + "ifstatement", + "else", + "regex", + "caseopts", + "caseopt", + "casevalues", + "selectlhand", + "svalues", + "selectval", + "sintvalues", + "string", + "strings", + "argumentlist", + "classparent", + "hostnames", + "nodeparent", + "nodename", + "hostname", + "nothing", + "arguments", + "argument", + "classnameordefault", + "hashpairs", + "hashpair", + "key" ] Racc_debug_parser = false -##### racc system variables end ##### - - # reduce 0 omitted - -module_eval <<'.,.,', 'grammar.ra', 46 - def _reduce_1( val, _values, result ) - if val[0] - # Make sure we always return an array. - if val[0].is_a?(AST::ASTArray) - if val[0].children.empty? - result = nil - else - result = val[0] - end - else - result = aryfy(val[0]) - end - else - result = nil - end - result +##### State transition tables end ##### + +# reduce 0 omitted + +module_eval(<<'.,.,', 'grammar.ra', 31) + def _reduce_1(val, _values, result) + val[0].is_a_namespace = true + result = val[0] + + result end .,., - # reduce 2 omitted +# reduce 2 omitted - # reduce 3 omitted +module_eval(<<'.,.,', 'grammar.ra', 37) + def _reduce_3(val, _values, result) + result = ast AST::ASTArray, :children => [val[0]] + + result + end +.,., -module_eval <<'.,.,', 'grammar.ra', 62 - def _reduce_4( val, _values, result ) - if val[0] and val[1] - if val[0].instance_of?(AST::ASTArray) - val[0].push(val[1]) - result = val[0] - else - result = ast AST::ASTArray, :children => [val[0],val[1]] - end - elsif obj = (val[0] || val[1]) - result = obj - else result = nil - end - result +module_eval(<<'.,.,', 'grammar.ra', 40) + def _reduce_4(val, _values, result) + val[0].push(val[1]) + result = val[0] + + result end .,., - # reduce 5 omitted +# reduce 5 omitted - # reduce 6 omitted +# reduce 6 omitted - # reduce 7 omitted +# reduce 7 omitted - # reduce 8 omitted +# reduce 8 omitted - # reduce 9 omitted +# reduce 9 omitted - # reduce 10 omitted +# reduce 10 omitted - # reduce 11 omitted +# reduce 11 omitted - # reduce 12 omitted +# reduce 12 omitted - # reduce 13 omitted +# reduce 13 omitted - # reduce 14 omitted +# reduce 14 omitted - # reduce 15 omitted +# reduce 15 omitted - # reduce 16 omitted +# reduce 16 omitted - # reduce 17 omitted +# reduce 17 omitted - # reduce 18 omitted +# reduce 18 omitted -module_eval <<'.,.,', 'grammar.ra', 82 - def _reduce_19( val, _values, result ) - result = AST::Relationship.new(val[0], val[2], val[1][:value], ast_context) - result +module_eval(<<'.,.,', 'grammar.ra', 61) + def _reduce_19(val, _values, result) + result = AST::Relationship.new(val[0], val[2], val[1][:value], ast_context) + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 85 - def _reduce_20( val, _values, result ) - result = AST::Relationship.new(val[0], val[2], val[1][:value], ast_context) - result +module_eval(<<'.,.,', 'grammar.ra', 64) + def _reduce_20(val, _values, result) + result = AST::Relationship.new(val[0], val[2], val[1][:value], ast_context) + + result end .,., - # reduce 21 omitted +# reduce 21 omitted - # reduce 22 omitted +# reduce 22 omitted - # reduce 23 omitted +# reduce 23 omitted - # reduce 24 omitted +# reduce 24 omitted - # reduce 25 omitted +# reduce 25 omitted - # reduce 26 omitted +# reduce 26 omitted - # reduce 27 omitted +# reduce 27 omitted -module_eval <<'.,.,', 'grammar.ra', 98 - def _reduce_28( val, _values, result ) - args = aryfy(val[2]) - result = ast AST::Function, - :name => val[0][:value], - :line => val[0][:line], - :arguments => args, - :ftype => :statement - result +module_eval(<<'.,.,', 'grammar.ra', 72) + def _reduce_28(val, _values, result) + args = aryfy(val[2]) + result = ast AST::Function, + :name => val[0][:value], + :line => val[0][:line], + :arguments => args, + :ftype => :statement + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 106 - def _reduce_29( val, _values, result ) - args = aryfy(val[2]) - result = ast AST::Function, - :name => val[0][:value], - :line => val[0][:line], - :arguments => args, - :ftype => :statement - result +module_eval(<<'.,.,', 'grammar.ra', 80) + def _reduce_29(val, _values, result) + args = aryfy(val[2]) + result = ast AST::Function, + :name => val[0][:value], + :line => val[0][:line], + :arguments => args, + :ftype => :statement + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 112 - def _reduce_30( val, _values, result ) - result = ast AST::Function, - :name => val[0][:value], - :line => val[0][:line], - :arguments => AST::ASTArray.new({}), - :ftype => :statement - result +module_eval(<<'.,.,', 'grammar.ra', 87) + def _reduce_30(val, _values, result) + result = ast AST::Function, + :name => val[0][:value], + :line => val[0][:line], + :arguments => AST::ASTArray.new({}), + :ftype => :statement + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 120 - def _reduce_31( val, _values, result ) - args = aryfy(val[1]) +module_eval(<<'.,.,', 'grammar.ra', 94) + def _reduce_31(val, _values, result) + args = aryfy(val[1]) result = ast AST::Function, - :name => val[0][:value], - :line => val[0][:line], - :arguments => args, - :ftype => :statement - result + :name => val[0][:value], + :line => val[0][:line], + :arguments => args, + :ftype => :statement + + result end .,., - # reduce 32 omitted +# reduce 32 omitted - # reduce 33 omitted +# reduce 33 omitted -module_eval <<'.,.,', 'grammar.ra', 128 - def _reduce_34( val, _values, result ) - result = aryfy(val[0], val[2]) +module_eval(<<'.,.,', 'grammar.ra', 105) + def _reduce_34(val, _values, result) + result = aryfy(val[0], val[2]) result.line = @lexer.line result.file = @lexer.file - result + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 137 - def _reduce_35( val, _values, result ) - unless val[0].is_a?(AST::ASTArray) - val[0] = aryfy(val[0]) - end +module_eval(<<'.,.,', 'grammar.ra', 110) + def _reduce_35(val, _values, result) + unless val[0].is_a?(AST::ASTArray) + val[0] = aryfy(val[0]) + end - val[0].push(val[2]) + val[0].push(val[2]) - result = val[0] - result + result = val[0] + + result end .,., - # reduce 36 omitted +# reduce 36 omitted - # reduce 37 omitted +# reduce 37 omitted - # reduce 38 omitted +# reduce 38 omitted - # reduce 39 omitted +# reduce 39 omitted - # reduce 40 omitted +# reduce 40 omitted - # reduce 41 omitted +# reduce 41 omitted - # reduce 42 omitted +# reduce 42 omitted - # reduce 43 omitted +# reduce 43 omitted -module_eval <<'.,.,', 'grammar.ra', 151 - def _reduce_44( val, _values, result ) - result = ast AST::Name, :value => val[0][:value] - result +module_eval(<<'.,.,', 'grammar.ra', 130) + def _reduce_44(val, _values, result) + result = ast AST::Name, :value => val[0][:value] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 173 - def _reduce_45( val, _values, result ) - @lexer.commentpop - array = val[2] - if array.instance_of?(AST::ResourceInstance) - array = [array] - end - result = ast AST::ASTArray +module_eval(<<'.,.,', 'grammar.ra', 134) + def _reduce_45(val, _values, result) + @lexer.commentpop + array = val[2] + array = [array] if array.instance_of?(AST::ResourceInstance) + result = ast AST::ASTArray + + # this iterates across each specified resourceinstance + array.each { |instance| + raise Puppet::Dev, "Got something that isn't an instance" unless instance.instance_of?(AST::ResourceInstance) + # now, i need to somehow differentiate between those things with + # arrays in their names, and normal things + + result.push ast( + AST::Resource, + :type => val[0], + :title => instance[0], + + :parameters => instance[1]) + } - # this iterates across each specified resourceinstance - array.each { |instance| - unless instance.instance_of?(AST::ResourceInstance) - raise Puppet::Dev, "Got something that isn't an instance" - end - # now, i need to somehow differentiate between those things with - # arrays in their names, and normal things - result.push ast(AST::Resource, - :type => val[0], - :title => instance[0], - :parameters => instance[1]) - } - result + result end .,., -module_eval <<'.,.,', 'grammar.ra', 176 - def _reduce_46( val, _values, result ) - # This is a deprecated syntax. - error "All resource specifications require names" - result +module_eval(<<'.,.,', 'grammar.ra', 153) + def _reduce_46(val, _values, result) + # This is a deprecated syntax. + error "All resource specifications require names" + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 180 - def _reduce_47( val, _values, result ) - # a defaults setting for a type - @lexer.commentpop - result = ast(AST::ResourceDefaults, :type => val[0], :parameters => val[2]) - result +module_eval(<<'.,.,', 'grammar.ra', 156) + def _reduce_47(val, _values, result) + # a defaults setting for a type + @lexer.commentpop + result = ast(AST::ResourceDefaults, :type => val[0], :parameters => val[2]) + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 186 - def _reduce_48( val, _values, result ) - @lexer.commentpop - result = ast AST::ResourceOverride, :object => val[0], :parameters => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 163) + def _reduce_48(val, _values, result) + @lexer.commentpop + result = ast AST::ResourceOverride, :object => val[0], :parameters => val[2] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 213 - def _reduce_49( val, _values, result ) - type = val[0] +module_eval(<<'.,.,', 'grammar.ra', 170) + def _reduce_49(val, _values, result) + type = val[0] - if (type == :exported and ! Puppet[:storeconfigs]) and ! Puppet[:parseonly] - Puppet.warning addcontext("You cannot collect without storeconfigs being set") - end + if (type == :exported and ! Puppet[:storeconfigs]) and ! Puppet[:parseonly] + Puppet.warning addcontext("You cannot collect without storeconfigs being set") + end - if val[1].is_a? AST::ResourceDefaults - error "Defaults are not virtualizable" - end + error "Defaults are not virtualizable" if val[1].is_a? AST::ResourceDefaults - method = type.to_s + "=" + method = type.to_s + "=" - # Just mark our resources as exported and pass them through. - if val[1].instance_of?(AST::ASTArray) - val[1].each do |obj| - obj.send(method, true) - end - else - val[1].send(method, true) + # Just mark our resources as exported and pass them through. + if val[1].instance_of?(AST::ASTArray) + val[1].each do |obj| + obj.send(method, true) end + else + val[1].send(method, true) + end - result = val[1] - result + result = val[1] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 214 - def _reduce_50( val, _values, result ) - result = :virtual - result +module_eval(<<'.,.,', 'grammar.ra', 192) + def _reduce_50(val, _values, result) + result = :virtual + result end .,., -module_eval <<'.,.,', 'grammar.ra', 215 - def _reduce_51( val, _values, result ) - result = :exported - result +module_eval(<<'.,.,', 'grammar.ra', 193) + def _reduce_51(val, _values, result) + result = :exported + result end .,., -module_eval <<'.,.,', 'grammar.ra', 240 - def _reduce_52( val, _values, result ) - @lexer.commentpop - if val[0] =~ /^[a-z]/ - Puppet.warning addcontext("Collection names must now be capitalized") - end - type = val[0].downcase - args = {:type => type} - - if val[1].is_a?(AST::CollExpr) - args[:query] = val[1] - args[:query].type = type - args[:form] = args[:query].form - else - args[:form] = val[1] - end - if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly] - Puppet.warning addcontext("You cannot collect exported resources without storeconfigs being set; the collection will be ignored") - end - args[:override] = val[3] - result = ast AST::Collection, args - result +module_eval(<<'.,.,', 'grammar.ra', 198) + def _reduce_52(val, _values, result) + @lexer.commentpop + Puppet.warning addcontext("Collection names must now be capitalized") if val[0] =~ /^[a-z]/ + type = val[0].downcase + args = {:type => type} + + if val[1].is_a?(AST::CollExpr) + args[:query] = val[1] + args[:query].type = type + args[:form] = args[:query].form + else + args[:form] = val[1] + end + if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly] + Puppet.warning addcontext("You cannot collect exported resources without storeconfigs being set; the collection will be ignored") + end + args[:override] = val[3] + result = ast AST::Collection, args + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 259 - def _reduce_53( val, _values, result ) - if val[0] =~ /^[a-z]/ - Puppet.warning addcontext("Collection names must now be capitalized") - end - type = val[0].downcase - args = {:type => type } - - if val[1].is_a?(AST::CollExpr) - args[:query] = val[1] - args[:query].type = type - args[:form] = args[:query].form - else - args[:form] = val[1] - end - if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly] - Puppet.warning addcontext("You cannot collect exported resources without storeconfigs being set; the collection will be ignored") - end - result = ast AST::Collection, args - result +module_eval(<<'.,.,', 'grammar.ra', 217) + def _reduce_53(val, _values, result) + if val[0] =~ /^[a-z]/ + Puppet.warning addcontext("Collection names must now be capitalized") + end + type = val[0].downcase + args = {:type => type } + + if val[1].is_a?(AST::CollExpr) + args[:query] = val[1] + args[:query].type = type + args[:form] = args[:query].form + else + args[:form] = val[1] + end + if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly] + Puppet.warning addcontext("You cannot collect exported resources without storeconfigs being set; the collection will be ignored") + end + result = ast AST::Collection, args + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 269 - def _reduce_54( val, _values, result ) - if val[1] - result = val[1] - result.form = :virtual - else - result = :virtual - end - result +module_eval(<<'.,.,', 'grammar.ra', 238) + def _reduce_54(val, _values, result) + if val[1] + result = val[1] + result.form = :virtual + else + result = :virtual + end + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 277 - def _reduce_55( val, _values, result ) - if val[1] - result = val[1] - result.form = :exported - else - result = :exported - end - result +module_eval(<<'.,.,', 'grammar.ra', 246) + def _reduce_55(val, _values, result) + if val[1] + result = val[1] + result.form = :exported + else + result = :exported + end + + result end .,., - # reduce 56 omitted +# reduce 56 omitted + +# reduce 57 omitted - # reduce 57 omitted +module_eval(<<'.,.,', 'grammar.ra', 259) + def _reduce_58(val, _values, result) + result = ast AST::CollExpr, :test1 => val[0], :oper => val[1], :test2 => val[2] -module_eval <<'.,.,', 'grammar.ra', 285 - def _reduce_58( val, _values, result ) - result = ast AST::CollExpr, :test1 => val[0], :oper => val[1], :test2 => val[2] - result + result end .,., - # reduce 59 omitted +# reduce 59 omitted -module_eval <<'.,.,', 'grammar.ra', 291 - def _reduce_60( val, _values, result ) - result = val[1] +module_eval(<<'.,.,', 'grammar.ra', 264) + def _reduce_60(val, _values, result) + result = val[1] result.parens = true - result + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 292 - def _reduce_61( val, _values, result ) - result=val[0][:value] - result +module_eval(<<'.,.,', 'grammar.ra', 268) + def _reduce_61(val, _values, result) + result=val[0][:value] + result end .,., -module_eval <<'.,.,', 'grammar.ra', 293 - def _reduce_62( val, _values, result ) - result=val[0][:value] - result +module_eval(<<'.,.,', 'grammar.ra', 269) + def _reduce_62(val, _values, result) + result=val[0][:value] + result end .,., -module_eval <<'.,.,', 'grammar.ra', 300 - def _reduce_63( val, _values, result ) - result = ast AST::CollExpr, :test1 => val[0], :oper => val[1][:value], :test2 => val[2] - #result = ast AST::CollExpr - #result.push *val - result +module_eval(<<'.,.,', 'grammar.ra', 272) + def _reduce_63(val, _values, result) + result = ast AST::CollExpr, :test1 => val[0], :oper => val[1][:value], :test2 => val[2] + #result = ast AST::CollExpr + #result.push *val + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 305 - def _reduce_64( val, _values, result ) - result = ast AST::CollExpr, :test1 => val[0], :oper => val[1][:value], :test2 => val[2] +module_eval(<<'.,.,', 'grammar.ra', 277) + def _reduce_64(val, _values, result) + result = ast AST::CollExpr, :test1 => val[0], :oper => val[1][:value], :test2 => val[2] #result = ast AST::CollExpr #result.push *val - result + + result end .,., - # reduce 65 omitted +# reduce 65 omitted - # reduce 66 omitted +# reduce 66 omitted -module_eval <<'.,.,', 'grammar.ra', 312 - def _reduce_67( val, _values, result ) - result = ast AST::ResourceInstance, :children => [val[0],val[2]] - result +module_eval(<<'.,.,', 'grammar.ra', 286) + def _reduce_67(val, _values, result) + result = ast AST::ResourceInstance, :children => [val[0],val[2]] + + result end .,., - # reduce 68 omitted +# reduce 68 omitted -module_eval <<'.,.,', 'grammar.ra', 322 - def _reduce_69( val, _values, result ) - if val[0].instance_of?(AST::ResourceInstance) - result = ast AST::ASTArray, :children => [val[0],val[2]] - else - val[0].push val[2] - result = val[0] - end - result +module_eval(<<'.,.,', 'grammar.ra', 291) + def _reduce_69(val, _values, result) + if val[0].instance_of?(AST::ResourceInstance) + result = ast AST::ASTArray, :children => [val[0],val[2]] + else + val[0].push val[2] + result = val[0] + end + + result end .,., - # reduce 70 omitted +# reduce 70 omitted - # reduce 71 omitted +# reduce 71 omitted -module_eval <<'.,.,', 'grammar.ra', 329 - def _reduce_72( val, _values, result ) - result = ast AST::Undef, :value => :undef - result +module_eval(<<'.,.,', 'grammar.ra', 303) + def _reduce_72(val, _values, result) + result = ast AST::Undef, :value => :undef + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 333 - def _reduce_73( val, _values, result ) - result = ast AST::Name, :value => val[0][:value], :line => val[0][:line] - result +module_eval(<<'.,.,', 'grammar.ra', 307) + def _reduce_73(val, _values, result) + result = ast AST::Name, :value => val[0][:value], :line => val[0][:line] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 337 - def _reduce_74( val, _values, result ) - result = ast AST::Type, :value => val[0][:value], :line => val[0][:line] - result +module_eval(<<'.,.,', 'grammar.ra', 311) + def _reduce_74(val, _values, result) + result = ast AST::Type, :value => val[0][:value], :line => val[0][:line] + + result end .,., - # reduce 75 omitted +# reduce 75 omitted - # reduce 76 omitted +# reduce 76 omitted - # reduce 77 omitted +# reduce 77 omitted - # reduce 78 omitted +# reduce 78 omitted - # reduce 79 omitted +# reduce 79 omitted - # reduce 80 omitted +# reduce 80 omitted - # reduce 81 omitted +# reduce 81 omitted -module_eval <<'.,.,', 'grammar.ra', 354 - def _reduce_82( val, _values, result ) - if val[0][:value] =~ /::/ - raise Puppet::ParseError, "Cannot assign to variables in other namespaces" - end - # this is distinct from referencing a variable - variable = ast AST::Name, :value => val[0][:value], :line => val[0][:line] - result = ast AST::VarDef, :name => variable, :value => val[2], :line => val[0][:line] - result +module_eval(<<'.,.,', 'grammar.ra', 323) + def _reduce_82(val, _values, result) + raise Puppet::ParseError, "Cannot assign to variables in other namespaces" if val[0][:value] =~ /::/ + # this is distinct from referencing a variable + variable = ast AST::Name, :value => val[0][:value], :line => val[0][:line] + result = ast AST::VarDef, :name => variable, :value => val[2], :line => val[0][:line] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 357 - def _reduce_83( val, _values, result ) - result = ast AST::VarDef, :name => val[0], :value => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 329) + def _reduce_83(val, _values, result) + result = ast AST::VarDef, :name => val[0], :value => val[2] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 362 - def _reduce_84( val, _values, result ) - variable = ast AST::Name, :value => val[0][:value], :line => val[0][:line] - result = ast AST::VarDef, :name => variable, :value => val[2], :append => true, :line => val[0][:line] - result +module_eval(<<'.,.,', 'grammar.ra', 333) + def _reduce_84(val, _values, result) + variable = ast AST::Name, :value => val[0][:value], :line => val[0][:line] + result = ast AST::VarDef, :name => variable, :value => val[2], :append => true, :line => val[0][:line] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 367 - def _reduce_85( val, _values, result ) - result = ast AST::ASTArray - result +module_eval(<<'.,.,', 'grammar.ra', 339) + def _reduce_85(val, _values, result) + result = ast AST::ASTArray + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 367 - def _reduce_86( val, _values, result ) - result = val[0] - result +module_eval(<<'.,.,', 'grammar.ra', 341) + def _reduce_86(val, _values, result) + result = val[0] + result end .,., -module_eval <<'.,.,', 'grammar.ra', 376 - def _reduce_87( val, _values, result ) - if val[0].instance_of?(AST::ASTArray) - val[0].push(val[2]) - result = val[0] - else - result = ast AST::ASTArray, :children => [val[0],val[2]] - end - result +module_eval(<<'.,.,', 'grammar.ra', 343) + def _reduce_87(val, _values, result) + if val[0].instance_of?(AST::ASTArray) + val[0].push(val[2]) + result = val[0] + else + result = ast AST::ASTArray, :children => [val[0],val[2]] + end + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 380 - def _reduce_88( val, _values, result ) - result = ast AST::ResourceParam, :param => val[0][:value], :line => val[0][:line], :value => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 352) + def _reduce_88(val, _values, result) + result = ast AST::ResourceParam, :param => val[0][:value], :line => val[0][:line], :value => val[2] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 385 - def _reduce_89( val, _values, result ) - result = ast AST::ResourceParam, :param => val[0][:value], :line => val[0][:line], :value => val[2], - :add => true - result +module_eval(<<'.,.,', 'grammar.ra', 356) + def _reduce_89(val, _values, result) + result = ast AST::ResourceParam, :param => val[0][:value], :line => val[0][:line], :value => val[2], + :add => true + + result end .,., - # reduce 90 omitted +# reduce 90 omitted - # reduce 91 omitted +# reduce 91 omitted -module_eval <<'.,.,', 'grammar.ra', 393 - def _reduce_92( val, _values, result ) - result = ast AST::ASTArray - result +module_eval(<<'.,.,', 'grammar.ra', 365) + def _reduce_92(val, _values, result) + result = ast AST::ASTArray + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 393 - def _reduce_93( val, _values, result ) - result = val[0] - result +module_eval(<<'.,.,', 'grammar.ra', 367) + def _reduce_93(val, _values, result) + result = val[0] + result end .,., -module_eval <<'.,.,', 'grammar.ra', 402 - def _reduce_94( val, _values, result ) - if val[0].instance_of?(AST::ASTArray) - val[0].push(val[2]) - result = val[0] - else - result = ast AST::ASTArray, :children => [val[0],val[2]] - end - result +module_eval(<<'.,.,', 'grammar.ra', 369) + def _reduce_94(val, _values, result) + if val[0].instance_of?(AST::ASTArray) + val[0].push(val[2]) + result = val[0] + else + result = ast AST::ASTArray, :children => [val[0],val[2]] + end + + result end .,., - # reduce 95 omitted +# reduce 95 omitted -module_eval <<'.,.,', 'grammar.ra', 411 - def _reduce_96( val, _values, result ) - if val[0].instance_of?(AST::ASTArray) - result = val[0].push(val[2]) - else - result = ast AST::ASTArray, :children => [val[0],val[2]] - end - result +module_eval(<<'.,.,', 'grammar.ra', 379) + def _reduce_96(val, _values, result) + if val[0].instance_of?(AST::ASTArray) + result = val[0].push(val[2]) + else + result = ast AST::ASTArray, :children => [val[0],val[2]] + end + + result end .,., - # reduce 97 omitted +# reduce 97 omitted - # reduce 98 omitted +# reduce 98 omitted - # reduce 99 omitted +# reduce 99 omitted - # reduce 100 omitted +# reduce 100 omitted - # reduce 101 omitted +# reduce 101 omitted - # reduce 102 omitted +# reduce 102 omitted - # reduce 103 omitted +# reduce 103 omitted - # reduce 104 omitted +# reduce 104 omitted - # reduce 105 omitted +# reduce 105 omitted - # reduce 106 omitted +# reduce 106 omitted - # reduce 107 omitted +# reduce 107 omitted - # reduce 108 omitted +# reduce 108 omitted - # reduce 109 omitted +# reduce 109 omitted - # reduce 110 omitted +# reduce 110 omitted - # reduce 111 omitted +# reduce 111 omitted - # reduce 112 omitted +# reduce 112 omitted - # reduce 113 omitted +# reduce 113 omitted - # reduce 114 omitted +# reduce 114 omitted -module_eval <<'.,.,', 'grammar.ra', 440 - def _reduce_115( val, _values, result ) - args = aryfy(val[2]) - result = ast AST::Function, - :name => val[0][:value], :line => val[0][:line], - :arguments => args, - :ftype => :rvalue - result +module_eval(<<'.,.,', 'grammar.ra', 408) + def _reduce_115(val, _values, result) + args = aryfy(val[2]) + result = ast AST::Function, + :name => val[0][:value], :line => val[0][:line], + :arguments => args, + :ftype => :rvalue + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 445 - def _reduce_116( val, _values, result ) - result = ast AST::Function, - :name => val[0][:value], :line => val[0][:line], - :arguments => AST::ASTArray.new({}), - :ftype => :rvalue - result +module_eval(<<'.,.,', 'grammar.ra', 414) + def _reduce_116(val, _values, result) + result = ast AST::Function, + :name => val[0][:value], :line => val[0][:line], + :arguments => AST::ASTArray.new({}), + :ftype => :rvalue + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 446 - def _reduce_117( val, _values, result ) - result = ast AST::String, :value => val[0][:value], :line => val[0][:line] - result +module_eval(<<'.,.,', 'grammar.ra', 420) + def _reduce_117(val, _values, result) + result = ast AST::String, :value => val[0][:value], :line => val[0][:line] + result end .,., -module_eval <<'.,.,', 'grammar.ra', 447 - def _reduce_118( val, _values, result ) - result = ast AST::Concat, :value => [ast(AST::String,val[0])]+val[1], :line => val[0][:line] - result +module_eval(<<'.,.,', 'grammar.ra', 421) + def _reduce_118(val, _values, result) + result = ast AST::Concat, :value => [ast(AST::String,val[0])]+val[1], :line => val[0][:line] + result end .,., -module_eval <<'.,.,', 'grammar.ra', 449 - def _reduce_119( val, _values, result ) - result = [val[0]] + val[1] - result +module_eval(<<'.,.,', 'grammar.ra', 423) + def _reduce_119(val, _values, result) + result = [val[0]] + val[1] + result end .,., -module_eval <<'.,.,', 'grammar.ra', 451 - def _reduce_120( val, _values, result ) - result = [ast(AST::String,val[0])] - result +module_eval(<<'.,.,', 'grammar.ra', 425) + def _reduce_120(val, _values, result) + result = [ast(AST::String,val[0])] + result end .,., -module_eval <<'.,.,', 'grammar.ra', 452 - def _reduce_121( val, _values, result ) - result = [ast(AST::String,val[0])] + val[1] - result +module_eval(<<'.,.,', 'grammar.ra', 426) + def _reduce_121(val, _values, result) + result = [ast(AST::String,val[0])] + val[1] + result end .,., -module_eval <<'.,.,', 'grammar.ra', 457 - def _reduce_122( val, _values, result ) - result = ast AST::Boolean, :value => val[0][:value], :line => val[0][:line] - result +module_eval(<<'.,.,', 'grammar.ra', 429) + def _reduce_122(val, _values, result) + result = ast AST::Boolean, :value => val[0][:value], :line => val[0][:line] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 462 - def _reduce_123( val, _values, result ) - Puppet.warning addcontext("Deprecation notice: Resource references should now be capitalized") - result = ast AST::ResourceReference, :type => val[0][:value], :line => val[0][:line], :title => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 433) + def _reduce_123(val, _values, result) + Puppet.warning addcontext("Deprecation notice: Resource references should now be capitalized") + result = ast AST::ResourceReference, :type => val[0][:value], :line => val[0][:line], :title => val[2] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 464 - def _reduce_124( val, _values, result ) - result = ast AST::ResourceReference, :type => val[0], :title => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 436) + def _reduce_124(val, _values, result) + result = ast AST::ResourceReference, :type => val[0], :title => val[2] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 468 - def _reduce_125( val, _values, result ) - result = val[1] - result +module_eval(<<'.,.,', 'grammar.ra', 440) + def _reduce_125(val, _values, result) + result = val[1] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 482 - def _reduce_126( val, _values, result ) - @lexer.commentpop - args = { - :test => val[0], - :statements => val[2] - } +module_eval(<<'.,.,', 'grammar.ra', 444) + def _reduce_126(val, _values, result) + @lexer.commentpop + args = { + :test => val[0], + :statements => val[2] + } - if val[4] - args[:else] = val[4] - end + args[:else] = val[4] if val[4] - result = ast AST::IfStatement, args - result + result = ast AST::IfStatement, args + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 495 - def _reduce_127( val, _values, result ) - @lexer.commentpop +module_eval(<<'.,.,', 'grammar.ra', 455) + def _reduce_127(val, _values, result) + @lexer.commentpop args = { - :test => val[0], - :statements => ast(AST::Nop) - } + :test => val[0], + :statements => ast(AST::Nop) + } - if val[3] - args[:else] = val[3] - end + args[:else] = val[3] if val[3] - result = ast AST::IfStatement, args - result + result = ast AST::IfStatement, args + + result end .,., - # reduce 128 omitted +# reduce 128 omitted + +module_eval(<<'.,.,', 'grammar.ra', 468) + def _reduce_129(val, _values, result) + result = ast AST::Else, :statements => val[1] -module_eval <<'.,.,', 'grammar.ra', 501 - def _reduce_129( val, _values, result ) - #@lexer.commentpop - result = ast AST::Else, :statements => val[1] - result + result end .,., -module_eval <<'.,.,', 'grammar.ra', 505 - def _reduce_130( val, _values, result ) - @lexer.commentpop +module_eval(<<'.,.,', 'grammar.ra', 471) + def _reduce_130(val, _values, result) + @lexer.commentpop result = ast AST::Else, :statements => val[2] - result + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 509 - def _reduce_131( val, _values, result ) - @lexer.commentpop +module_eval(<<'.,.,', 'grammar.ra', 475) + def _reduce_131(val, _values, result) + @lexer.commentpop result = ast AST::Else, :statements => ast(AST::Nop) - result + + result end .,., - # reduce 132 omitted +# reduce 132 omitted -module_eval <<'.,.,', 'grammar.ra', 526 - def _reduce_133( val, _values, result ) - result = ast AST::InOperator, :lval => val[0], :rval => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 493) + def _reduce_133(val, _values, result) + result = ast AST::InOperator, :lval => val[0], :rval => val[2] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 529 - def _reduce_134( val, _values, result ) - result = ast AST::MatchOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 496) + def _reduce_134(val, _values, result) + result = ast AST::MatchOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 532 - def _reduce_135( val, _values, result ) - result = ast AST::MatchOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 499) + def _reduce_135(val, _values, result) + result = ast AST::MatchOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 535 - def _reduce_136( val, _values, result ) - result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 502) + def _reduce_136(val, _values, result) + result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 538 - def _reduce_137( val, _values, result ) - result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 505) + def _reduce_137(val, _values, result) + result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 541 - def _reduce_138( val, _values, result ) - result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 508) + def _reduce_138(val, _values, result) + result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 544 - def _reduce_139( val, _values, result ) - result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 511) + def _reduce_139(val, _values, result) + result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 547 - def _reduce_140( val, _values, result ) - result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 514) + def _reduce_140(val, _values, result) + result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 550 - def _reduce_141( val, _values, result ) - result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 517) + def _reduce_141(val, _values, result) + result = ast AST::ArithmeticOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 553 - def _reduce_142( val, _values, result ) - result = ast AST::Minus, :value => val[1] - result +module_eval(<<'.,.,', 'grammar.ra', 520) + def _reduce_142(val, _values, result) + result = ast AST::Minus, :value => val[1] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 556 - def _reduce_143( val, _values, result ) - result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 523) + def _reduce_143(val, _values, result) + result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 559 - def _reduce_144( val, _values, result ) - result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 526) + def _reduce_144(val, _values, result) + result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 562 - def _reduce_145( val, _values, result ) - result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 529) + def _reduce_145(val, _values, result) + result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 565 - def _reduce_146( val, _values, result ) - result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 532) + def _reduce_146(val, _values, result) + result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 568 - def _reduce_147( val, _values, result ) - result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 535) + def _reduce_147(val, _values, result) + result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 571 - def _reduce_148( val, _values, result ) - result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 538) + def _reduce_148(val, _values, result) + result = ast AST::ComparisonOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 574 - def _reduce_149( val, _values, result ) - result = ast AST::Not, :value => val[1] - result +module_eval(<<'.,.,', 'grammar.ra', 541) + def _reduce_149(val, _values, result) + result = ast AST::Not, :value => val[1] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 577 - def _reduce_150( val, _values, result ) - result = ast AST::BooleanOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 544) + def _reduce_150(val, _values, result) + result = ast AST::BooleanOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 580 - def _reduce_151( val, _values, result ) - result = ast AST::BooleanOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 547) + def _reduce_151(val, _values, result) + result = ast AST::BooleanOperator, :operator => val[1][:value], :lval => val[0], :rval => val[2] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 583 - def _reduce_152( val, _values, result ) - result = val[1] - result +module_eval(<<'.,.,', 'grammar.ra', 550) + def _reduce_152(val, _values, result) + result = val[1] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 592 - def _reduce_153( val, _values, result ) - @lexer.commentpop - options = val[3] - unless options.instance_of?(AST::ASTArray) - options = ast AST::ASTArray, :children => [val[3]] - end - result = ast AST::CaseStatement, :test => val[1], :options => options - result +module_eval(<<'.,.,', 'grammar.ra', 554) + def _reduce_153(val, _values, result) + @lexer.commentpop + options = val[3] + options = ast AST::ASTArray, :children => [val[3]] unless options.instance_of?(AST::ASTArray) + result = ast AST::CaseStatement, :test => val[1], :options => options + + result end .,., - # reduce 154 omitted +# reduce 154 omitted -module_eval <<'.,.,', 'grammar.ra', 602 - def _reduce_155( val, _values, result ) - if val[0].instance_of?(AST::ASTArray) - val[0].push val[1] - result = val[0] - else - result = ast AST::ASTArray, :children => [val[0], val[1]] - end - result +module_eval(<<'.,.,', 'grammar.ra', 562) + def _reduce_155(val, _values, result) + if val[0].instance_of?(AST::ASTArray) + val[0].push val[1] + result = val[0] + else + result = ast AST::ASTArray, :children => [val[0], val[1]] + end + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 607 - def _reduce_156( val, _values, result ) - @lexer.commentpop - result = ast AST::CaseOpt, :value => val[0], :statements => val[3] - result +module_eval(<<'.,.,', 'grammar.ra', 571) + def _reduce_156(val, _values, result) + @lexer.commentpop + result = ast AST::CaseOpt, :value => val[0], :statements => val[3] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 613 - def _reduce_157( val, _values, result ) - @lexer.commentpop - result = ast(AST::CaseOpt, - :value => val[0], - :statements => ast(AST::ASTArray) - ) - result +module_eval(<<'.,.,', 'grammar.ra', 574) + def _reduce_157(val, _values, result) + @lexer.commentpop + + result = ast( + AST::CaseOpt, + :value => val[0], + + :statements => ast(AST::ASTArray) + ) + + result end .,., - # reduce 158 omitted +# reduce 158 omitted -module_eval <<'.,.,', 'grammar.ra', 623 - def _reduce_159( val, _values, result ) - if val[0].instance_of?(AST::ASTArray) - val[0].push(val[2]) - result = val[0] - else - result = ast AST::ASTArray, :children => [val[0],val[2]] - end - result +module_eval(<<'.,.,', 'grammar.ra', 586) + def _reduce_159(val, _values, result) + if val[0].instance_of?(AST::ASTArray) + val[0].push(val[2]) + result = val[0] + else + result = ast AST::ASTArray, :children => [val[0],val[2]] + end + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 627 - def _reduce_160( val, _values, result ) - result = ast AST::Selector, :param => val[0], :values => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 595) + def _reduce_160(val, _values, result) + result = ast AST::Selector, :param => val[0], :values => val[2] + + result end .,., - # reduce 161 omitted +# reduce 161 omitted -module_eval <<'.,.,', 'grammar.ra', 633 - def _reduce_162( val, _values, result ) - @lexer.commentpop +module_eval(<<'.,.,', 'grammar.ra', 600) + def _reduce_162(val, _values, result) + @lexer.commentpop result = val[1] - result + + result end .,., - # reduce 163 omitted +# reduce 163 omitted -module_eval <<'.,.,', 'grammar.ra', 643 - def _reduce_164( val, _values, result ) - if val[0].instance_of?(AST::ASTArray) - val[0].push(val[2]) - result = val[0] - else - result = ast AST::ASTArray, :children => [val[0],val[2]] - end - result +module_eval(<<'.,.,', 'grammar.ra', 606) + def _reduce_164(val, _values, result) + if val[0].instance_of?(AST::ASTArray) + val[0].push(val[2]) + result = val[0] + else + result = ast AST::ASTArray, :children => [val[0],val[2]] + end + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 647 - def _reduce_165( val, _values, result ) - result = ast AST::ResourceParam, :param => val[0], :value => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 615) + def _reduce_165(val, _values, result) + result = ast AST::ResourceParam, :param => val[0], :value => val[2] + + result end .,., - # reduce 166 omitted +# reduce 166 omitted + +# reduce 167 omitted - # reduce 167 omitted +# reduce 168 omitted - # reduce 168 omitted +# reduce 169 omitted - # reduce 169 omitted +# reduce 170 omitted - # reduce 170 omitted +# reduce 171 omitted - # reduce 171 omitted +# reduce 172 omitted - # reduce 172 omitted +module_eval(<<'.,.,', 'grammar.ra', 626) + def _reduce_173(val, _values, result) + result = ast AST::Default, :value => val[0][:value], :line => val[0][:line] -module_eval <<'.,.,', 'grammar.ra', 658 - def _reduce_173( val, _values, result ) - result = ast AST::Default, :value => val[0][:value], :line => val[0][:line] - result + result end .,., - # reduce 174 omitted +# reduce 174 omitted -module_eval <<'.,.,', 'grammar.ra', 661 - def _reduce_175( val, _values, result ) - result = [val[0][:value]] - result +module_eval(<<'.,.,', 'grammar.ra', 631) + def _reduce_175(val, _values, result) + result = [val[0][:value]] + result end .,., - # reduce 176 omitted +# reduce 176 omitted -module_eval <<'.,.,', 'grammar.ra', 663 - def _reduce_177( val, _values, result ) - result = val[0] += val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 633) + def _reduce_177(val, _values, result) + result = val[0] += val[2] + result end .,., -module_eval <<'.,.,', 'grammar.ra', 672 - def _reduce_178( val, _values, result ) - val[1].each do |file| - import(file) - end +module_eval(<<'.,.,', 'grammar.ra', 636) + def _reduce_178(val, _values, result) + val[1].each do |file| + import(file) + end - result = AST::ASTArray.new(:children => []) - result + result = AST::ASTArray.new(:children => []) + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 683 - def _reduce_179( val, _values, result ) - @lexer.commentpop - newdefine classname(val[1]), :arguments => val[2], :code => val[4], :line => val[0][:line] - @lexer.indefine = false - result = nil +module_eval(<<'.,.,', 'grammar.ra', 646) + def _reduce_179(val, _values, result) + @lexer.commentpop + result = Puppet::Parser::AST::Definition.new(classname(val[1]), + ast_context(true).merge(:arguments => val[2], :code => val[4], + :line => val[0][:line])) + @lexer.indefine = false #} | DEFINE NAME argumentlist parent LBRACE RBRACE { - result + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 688 - def _reduce_180( val, _values, result ) - @lexer.commentpop - newdefine classname(val[1]), :arguments => val[2], :line => val[0][:line] - @lexer.indefine = false - result = nil - result +module_eval(<<'.,.,', 'grammar.ra', 654) + def _reduce_180(val, _values, result) + @lexer.commentpop + result = Puppet::Parser::AST::Definition.new(classname(val[1]), + ast_context(true).merge(:arguments => val[2], :line => val[0][:line])) + @lexer.indefine = false + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 697 - def _reduce_181( val, _values, result ) - @lexer.commentpop - # Our class gets defined in the parent namespace, not our own. - @lexer.namepop - newclass classname(val[1]), :arguments => val[2], :parent => val[3], :code => val[5], :line => val[0][:line] - result = nil - result +module_eval(<<'.,.,', 'grammar.ra', 662) + def _reduce_181(val, _values, result) + @lexer.commentpop + # Our class gets defined in the parent namespace, not our own. + @lexer.namepop + val[5].is_a_namespace = true + result = Puppet::Parser::AST::Hostclass.new(classname(val[1]), + ast_context(true).merge(:arguments => val[2], :parent => val[3], + :code => val[5], :line => val[0][:line])) + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 703 - def _reduce_182( val, _values, result ) - @lexer.commentpop - # Our class gets defined in the parent namespace, not our own. - @lexer.namepop - newclass classname(val[1]), :arguments => val[2], :parent => val[3], :line => val[0][:line] - result = nil - result +module_eval(<<'.,.,', 'grammar.ra', 670) + def _reduce_182(val, _values, result) + @lexer.commentpop + # Our class gets defined in the parent namespace, not our own. + @lexer.namepop + result = Puppet::Parser::AST::Hostclass.new(classname(val[1]), + ast_context(true).merge(:arguments => val[2], :parent => val[3], + :line => val[0][:line])) + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 709 - def _reduce_183( val, _values, result ) - @lexer.commentpop - newnode val[1], :parent => val[2], :code => val[4], :line => val[0][:line] - result = nil - result +module_eval(<<'.,.,', 'grammar.ra', 679) + def _reduce_183(val, _values, result) + @lexer.commentpop + result = Puppet::Parser::AST::Node.new(val[1], + ast_context(true).merge(:parent => val[2], :code => val[4], + :line => val[0][:line])) + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 713 - def _reduce_184( val, _values, result ) - @lexer.commentpop - newnode val[1], :parent => val[2], :line => val[0][:line] - result = nil - result +module_eval(<<'.,.,', 'grammar.ra', 684) + def _reduce_184(val, _values, result) + @lexer.commentpop + result = Puppet::Parser::AST::Node.new(val[1], ast_context(true).merge(:parent => val[2], :line => val[0][:line])) + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 714 - def _reduce_185( val, _values, result ) - result = val[0][:value] - result +module_eval(<<'.,.,', 'grammar.ra', 688) + def _reduce_185(val, _values, result) + result = val[0][:value] + result end .,., -module_eval <<'.,.,', 'grammar.ra', 716 - def _reduce_186( val, _values, result ) - result = val[0][:value] - result +module_eval(<<'.,.,', 'grammar.ra', 690) + def _reduce_186(val, _values, result) + result = val[0][:value] + result end .,., -module_eval <<'.,.,', 'grammar.ra', 717 - def _reduce_187( val, _values, result ) - result = val[0][:value] - result +module_eval(<<'.,.,', 'grammar.ra', 691) + def _reduce_187(val, _values, result) + result = val[0][:value] + result end .,., -module_eval <<'.,.,', 'grammar.ra', 718 - def _reduce_188( val, _values, result ) - result = "class" - result +module_eval(<<'.,.,', 'grammar.ra', 692) + def _reduce_188(val, _values, result) + result = "class" + result end .,., - # reduce 189 omitted +module_eval(<<'.,.,', 'grammar.ra', 697) + def _reduce_189(val, _values, result) + result = [result] -module_eval <<'.,.,', 'grammar.ra', 728 - def _reduce_190( val, _values, result ) - result = val[0] - result = [result] unless result.is_a?(Array) + result + end +.,., + +module_eval(<<'.,.,', 'grammar.ra', 700) + def _reduce_190(val, _values, result) + result = val[0] result << val[2] - result + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 732 - def _reduce_191( val, _values, result ) - result = ast AST::HostName, :value => val[0] - result +module_eval(<<'.,.,', 'grammar.ra', 705) + def _reduce_191(val, _values, result) + result = ast AST::HostName, :value => val[0] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 733 - def _reduce_192( val, _values, result ) - result = val[0][:value] - result +module_eval(<<'.,.,', 'grammar.ra', 708) + def _reduce_192(val, _values, result) + result = val[0][:value] + result end .,., -module_eval <<'.,.,', 'grammar.ra', 734 - def _reduce_193( val, _values, result ) - result = val[0][:value] - result +module_eval(<<'.,.,', 'grammar.ra', 709) + def _reduce_193(val, _values, result) + result = val[0][:value] + result end .,., -module_eval <<'.,.,', 'grammar.ra', 735 - def _reduce_194( val, _values, result ) - result = val[0][:value] - result +module_eval(<<'.,.,', 'grammar.ra', 710) + def _reduce_194(val, _values, result) + result = val[0][:value] + result end .,., - # reduce 195 omitted +# reduce 195 omitted + +module_eval(<<'.,.,', 'grammar.ra', 714) + def _reduce_196(val, _values, result) + result = nil -module_eval <<'.,.,', 'grammar.ra', 741 - def _reduce_196( val, _values, result ) - result = nil - result + result end .,., -module_eval <<'.,.,', 'grammar.ra', 745 - def _reduce_197( val, _values, result ) - result = ast AST::ASTArray, :children => [] - result +module_eval(<<'.,.,', 'grammar.ra', 718) + def _reduce_197(val, _values, result) + result = ast AST::ASTArray, :children => [] + + result end .,., - # reduce 198 omitted +# reduce 198 omitted + +module_eval(<<'.,.,', 'grammar.ra', 723) + def _reduce_199(val, _values, result) + result = nil -module_eval <<'.,.,', 'grammar.ra', 750 - def _reduce_199( val, _values, result ) - result = nil - result + result end .,., -module_eval <<'.,.,', 'grammar.ra', 754 - def _reduce_200( val, _values, result ) - result = val[1] +module_eval(<<'.,.,', 'grammar.ra', 726) + def _reduce_200(val, _values, result) + result = val[1] result = [result] unless result[0].is_a?(Array) - result + + result end .,., - # reduce 201 omitted +# reduce 201 omitted -module_eval <<'.,.,', 'grammar.ra', 761 - def _reduce_202( val, _values, result ) - result = val[0] +module_eval(<<'.,.,', 'grammar.ra', 732) + def _reduce_202(val, _values, result) + result = val[0] result = [result] unless result[0].is_a?(Array) result << val[2] - result + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 766 - def _reduce_203( val, _values, result ) - Puppet.warning addcontext("Deprecation notice: must now include '$' in prototype") - result = [val[0][:value], val[2]] - result +module_eval(<<'.,.,', 'grammar.ra', 738) + def _reduce_203(val, _values, result) + Puppet.warning addcontext("Deprecation notice: must now include '$' in prototype") + result = [val[0][:value], val[2]] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 770 - def _reduce_204( val, _values, result ) - Puppet.warning addcontext("Deprecation notice: must now include '$' in prototype") +module_eval(<<'.,.,', 'grammar.ra', 742) + def _reduce_204(val, _values, result) + Puppet.warning addcontext("Deprecation notice: must now include '$' in prototype") result = [val[0][:value]] - result + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 772 - def _reduce_205( val, _values, result ) - result = [val[0][:value], val[2]] - result +module_eval(<<'.,.,', 'grammar.ra', 745) + def _reduce_205(val, _values, result) + result = [val[0][:value], val[2]] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 774 - def _reduce_206( val, _values, result ) - result = [val[0][:value]] - result +module_eval(<<'.,.,', 'grammar.ra', 747) + def _reduce_206(val, _values, result) + result = [val[0][:value]] + + result end .,., - # reduce 207 omitted +# reduce 207 omitted -module_eval <<'.,.,', 'grammar.ra', 779 - def _reduce_208( val, _values, result ) - result = val[1] - result +module_eval(<<'.,.,', 'grammar.ra', 752) + def _reduce_208(val, _values, result) + result = val[1] + + result end .,., - # reduce 209 omitted +# reduce 209 omitted -module_eval <<'.,.,', 'grammar.ra', 784 - def _reduce_210( val, _values, result ) - result = val[1] - result +module_eval(<<'.,.,', 'grammar.ra', 757) + def _reduce_210(val, _values, result) + result = val[1] + + result end .,., - # reduce 211 omitted +# reduce 211 omitted - # reduce 212 omitted +# reduce 212 omitted -module_eval <<'.,.,', 'grammar.ra', 790 - def _reduce_213( val, _values, result ) - result = ast AST::Variable, :value => val[0][:value], :line => val[0][:line] - result +module_eval(<<'.,.,', 'grammar.ra', 763) + def _reduce_213(val, _values, result) + result = ast AST::Variable, :value => val[0][:value], :line => val[0][:line] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 798 - def _reduce_214( val, _values, result ) - if val[1].instance_of?(AST::ASTArray) - result = val[1] - else - result = ast AST::ASTArray, :children => [val[1]] - end - result +module_eval(<<'.,.,', 'grammar.ra', 767) + def _reduce_214(val, _values, result) + if val[1].instance_of?(AST::ASTArray) + result = val[1] + else + result = ast AST::ASTArray, :children => [val[1]] + end + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 805 - def _reduce_215( val, _values, result ) - if val[1].instance_of?(AST::ASTArray) - result = val[1] - else - result = ast AST::ASTArray, :children => [val[1]] - end - result +module_eval(<<'.,.,', 'grammar.ra', 774) + def _reduce_215(val, _values, result) + if val[1].instance_of?(AST::ASTArray) + result = val[1] + else + result = ast AST::ASTArray, :children => [val[1]] + end + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 807 - def _reduce_216( val, _values, result ) - result = ast AST::ASTArray - result +module_eval(<<'.,.,', 'grammar.ra', 780) + def _reduce_216(val, _values, result) + result = ast AST::ASTArray + + result end .,., - # reduce 217 omitted +# reduce 217 omitted - # reduce 218 omitted +# reduce 218 omitted - # reduce 219 omitted +# reduce 219 omitted -module_eval <<'.,.,', 'grammar.ra', 812 - def _reduce_220( val, _values, result ) - result = nil - result +module_eval(<<'.,.,', 'grammar.ra', 787) + def _reduce_220(val, _values, result) + result = nil + result end .,., -module_eval <<'.,.,', 'grammar.ra', 817 - def _reduce_221( val, _values, result ) - result = ast AST::Regex, :value => val[0][:value] - result +module_eval(<<'.,.,', 'grammar.ra', 790) + def _reduce_221(val, _values, result) + result = ast AST::Regex, :value => val[0][:value] + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 825 - def _reduce_222( val, _values, result ) - if val[1].instance_of?(AST::ASTHash) - result = val[1] - else - result = ast AST::ASTHash, { :value => val[1] } - end - result +module_eval(<<'.,.,', 'grammar.ra', 794) + def _reduce_222(val, _values, result) + if val[1].instance_of?(AST::ASTHash) + result = val[1] + else + result = ast AST::ASTHash, { :value => val[1] } end -.,., -module_eval <<'.,.,', 'grammar.ra', 832 - def _reduce_223( val, _values, result ) - if val[1].instance_of?(AST::ASTHash) - result = val[1] - else - result = ast AST::ASTHash, { :value => val[1] } - end - result + result end .,., -module_eval <<'.,.,', 'grammar.ra', 834 - def _reduce_224( val, _values, result ) - result = ast AST::ASTHash - result +module_eval(<<'.,.,', 'grammar.ra', 801) + def _reduce_223(val, _values, result) + if val[1].instance_of?(AST::ASTHash) + result = val[1] + else + result = ast AST::ASTHash, { :value => val[1] } + end + + result end .,., - # reduce 225 omitted +module_eval(<<'.,.,', 'grammar.ra', 807) + def _reduce_224(val, _values, result) + result = ast AST::ASTHash -module_eval <<'.,.,', 'grammar.ra', 844 - def _reduce_226( val, _values, result ) - if val[0].instance_of?(AST::ASTHash) - result = val[0].merge(val[2]) - else - result = ast AST::ASTHash, :value => val[0] - result.merge(val[2]) - end - result + result end .,., -module_eval <<'.,.,', 'grammar.ra', 848 - def _reduce_227( val, _values, result ) - result = ast AST::ASTHash, { :value => { val[0] => val[2] } } - result +# reduce 225 omitted + +module_eval(<<'.,.,', 'grammar.ra', 812) + def _reduce_226(val, _values, result) + if val[0].instance_of?(AST::ASTHash) + result = val[0].merge(val[2]) + else + result = ast AST::ASTHash, :value => val[0] + result.merge(val[2]) + end + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 849 - def _reduce_228( val, _values, result ) - result = val[0][:value] - result +module_eval(<<'.,.,', 'grammar.ra', 821) + def _reduce_227(val, _values, result) + result = ast AST::ASTHash, { :value => { val[0] => val[2] } } + + result end .,., -module_eval <<'.,.,', 'grammar.ra', 850 - def _reduce_229( val, _values, result ) - result = val[0] - result +module_eval(<<'.,.,', 'grammar.ra', 824) + def _reduce_228(val, _values, result) + result = val[0][:value] + result end .,., -module_eval <<'.,.,', 'grammar.ra', 855 - def _reduce_230( val, _values, result ) - result = ast AST::HashOrArrayAccess, :variable => val[0][:value], :key => val[2] - result +module_eval(<<'.,.,', 'grammar.ra', 825) + def _reduce_229(val, _values, result) + result = val[0] + result end .,., - # reduce 231 omitted +module_eval(<<'.,.,', 'grammar.ra', 828) + def _reduce_230(val, _values, result) + result = ast AST::HashOrArrayAccess, :variable => val[0][:value], :key => val[2] -module_eval <<'.,.,', 'grammar.ra', 860 - def _reduce_232( val, _values, result ) - result = ast AST::HashOrArrayAccess, :variable => val[0], :key => val[2] - result + result end .,., - def _reduce_none( val, _values, result ) - result - end +# reduce 231 omitted - end # class Parser +module_eval(<<'.,.,', 'grammar.ra', 833) + def _reduce_232(val, _values, result) + result = ast AST::HashOrArrayAccess, :variable => val[0], :key => val[2] + + result + end +.,., - end # module Parser +def _reduce_none(val, _values, result) + val[0] +end -end # module Puppet + end # class Parser + end # module Parser + end # module Puppet diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb index 97d985cfb..859897a16 100644 --- a/lib/puppet/parser/parser_support.rb +++ b/lib/puppet/parser/parser_support.rb @@ -1,235 +1,216 @@ # I pulled this into a separate file, because I got # tired of rebuilding the parser.rb file all the time. class Puppet::Parser::Parser require 'puppet/parser/functions' require 'puppet/parser/files' require 'puppet/resource/type_collection' require 'puppet/resource/type_collection_helper' require 'puppet/resource/type' require 'monitor' AST = Puppet::Parser::AST include Puppet::Resource::TypeCollectionHelper attr_reader :version, :environment attr_accessor :files attr_accessor :lexer # Add context to a message; useful for error messages and such. def addcontext(message, obj = nil) obj ||= @lexer message += " on line #{obj.line}" if file = obj.file message += " in file #{file}" end message end # Create an AST array out of all of the args def aryfy(*args) if args[0].instance_of?(AST::ASTArray) result = args.shift args.each { |arg| result.push arg } else result = ast AST::ASTArray, :children => args end result end # Create an AST object, and automatically add the file and line information if # available. def ast(klass, hash = {}) klass.new ast_context(klass.use_docs).merge(hash) end def ast_context(include_docs = false) result = { :line => lexer.line, :file => lexer.file } result[:doc] = lexer.getcomment(result[:line]) if include_docs result end # The fully qualifed name, with the full namespace. def classname(name) [@lexer.namespace, name].join("::").sub(/^::/, '') end def clear initvars end # Raise a Parse error. def error(message) if brace = @lexer.expected message += "; expected '%s'" end except = Puppet::ParseError.new(message) except.line = @lexer.line except.file = @lexer.file if @lexer.file raise except end def file @lexer.file end def file=(file) unless FileTest.exist?(file) unless file =~ /\.pp$/ file = file + ".pp" end raise Puppet::Error, "Could not find file #{file}" unless FileTest.exist?(file) end raise Puppet::AlreadyImportedError, "Import loop detected" if known_resource_types.watching_file?(file) watch_file(file) @lexer.file = file end [:hostclass, :definition, :node, :nodes?].each do |method| define_method(method) do |*args| known_resource_types.send(method, *args) end end def find_hostclass(namespace, name) known_resource_types.find_hostclass(namespace, name) end def find_definition(namespace, name) known_resource_types.find_definition(namespace, name) end def import(file) known_resource_types.loader.import_if_possible(file, @lexer.file) end def initialize(env) # The environment is needed to know how to find the resource type collection. @environment = env.is_a?(String) ? Puppet::Node::Environment.new(env) : env initvars end # Initialize or reset all of our variables. def initvars @lexer = Puppet::Parser::Lexer.new end # Split an fq name into a namespace and name def namesplit(fullname) ary = fullname.split("::") n = ary.pop || "" ns = ary.join("::") return ns, n end - # Create a new class, or merge with an existing class. - def newclass(name, options = {}) - known_resource_types.add Puppet::Resource::Type.new(:hostclass, name, ast_context(true).merge(options)) - end - - # Create a new definition. - def newdefine(name, options = {}) - known_resource_types.add Puppet::Resource::Type.new(:definition, name, ast_context(true).merge(options)) - end - - # Create a new node. Nodes are special, because they're stored in a global - # table, not according to namespaces. - def newnode(names, options = {}) - names = [names] unless names.instance_of?(Array) - context = ast_context(true) - names.collect do |name| - known_resource_types.add(Puppet::Resource::Type.new(:node, name, context.merge(options))) - end - end - def on_error(token,value,stack) if token == 0 # denotes end of file value = 'end of file' else value = "'#{value[:value]}'" end error = "Syntax error at #{value}" if brace = @lexer.expected error += "; expected '#{brace}'" end except = Puppet::ParseError.new(error) except.line = @lexer.line except.file = @lexer.file if @lexer.file raise except end # how should I do error handling here? def parse(string = nil) - return parse_ruby_file if self.file =~ /\.rb$/ - self.string = string if string - begin - @yydebug = false - main = yyparse(@lexer,:scan) - rescue Racc::ParseError => except - error = Puppet::ParseError.new(except) - error.line = @lexer.line - error.file = @lexer.file - error.set_backtrace except.backtrace - raise error - rescue Puppet::ParseError => except - except.line ||= @lexer.line - except.file ||= @lexer.file - raise except - rescue Puppet::Error => except - # and this is a framework error - except.line ||= @lexer.line - except.file ||= @lexer.file - raise except - rescue Puppet::DevError => except - except.line ||= @lexer.line - except.file ||= @lexer.file - raise except - rescue => except - error = Puppet::DevError.new(except.message) - error.line = @lexer.line - error.file = @lexer.file - error.set_backtrace except.backtrace - raise error - end - if main - # Store the results as the top-level class. - newclass("", :code => main) + if self.file =~ /\.rb$/ + parse_ruby_file + main = nil + else + self.string = string if string + begin + @yydebug = false + main = yyparse(@lexer,:scan) + rescue Racc::ParseError => except + error = Puppet::ParseError.new(except) + error.line = @lexer.line + error.file = @lexer.file + error.set_backtrace except.backtrace + raise error + rescue Puppet::ParseError => except + except.line ||= @lexer.line + except.file ||= @lexer.file + raise except + rescue Puppet::Error => except + # and this is a framework error + except.line ||= @lexer.line + except.file ||= @lexer.file + raise except + rescue Puppet::DevError => except + except.line ||= @lexer.line + except.file ||= @lexer.file + raise except + rescue => except + error = Puppet::DevError.new(except.message) + error.line = @lexer.line + error.file = @lexer.file + error.set_backtrace except.backtrace + raise error + end end - return known_resource_types + # Store the results as the top-level class. + return Puppet::Parser::AST::Hostclass.new('', :code => main) ensure @lexer.clear end def parse_ruby_file require self.file end def string=(string) @lexer.string = string end def version known_resource_types.version end # Add a new file to be checked when we're checking to see if we should be # reparsed. This is basically only used by the TemplateWrapper to let the # parser know about templates that should be parsed. def watch_file(filename) known_resource_types.watch_file(filename) end end diff --git a/lib/puppet/parser/type_loader.rb b/lib/puppet/parser/type_loader.rb index 516c1e32b..8a183f493 100644 --- a/lib/puppet/parser/type_loader.rb +++ b/lib/puppet/parser/type_loader.rb @@ -1,140 +1,145 @@ require 'puppet/node/environment' class Puppet::Parser::TypeLoader include Puppet::Node::Environment::Helper class Helper < Hash include MonitorMixin def done_with(item) synchronize do delete(item)[:busy].signal if self.has_key?(item) and self[item][:loader] == Thread.current end end def owner_of(item) synchronize do if !self.has_key? item self[item] = { :loader => Thread.current, :busy => self.new_cond} :nobody elsif self[item][:loader] == Thread.current :this_thread else flag = self[item][:busy] flag.wait flag.signal :another_thread end end end end # Import our files. def import(file, current_file = nil) return if Puppet[:ignoreimport] # use a path relative to the file doing the importing if current_file dir = current_file.sub(%r{[^/]+$},'').sub(/\/$/, '') else dir = "." end if dir == "" dir = "." end pat = file modname, files = Puppet::Parser::Files.find_manifests(pat, :cwd => dir, :environment => environment) if files.size == 0 raise Puppet::ImportError.new("No file(s) found for import of '#{pat}'") end + loaded_asts = [] files.each do |file| unless file =~ /^#{File::SEPARATOR}/ file = File.join(dir, file) end unless imported? file @imported[file] = true - parse_file(file) + loaded_asts << parse_file(file) end end - - modname + loaded_asts.inject([]) do |loaded_types, ast| + loaded_types + known_resource_types.import_ast(ast, modname) + end end def imported?(file) @imported.has_key?(file) end def known_resource_types environment.known_resource_types end def initialize(env) self.environment = env @loaded = {} @loading = Helper.new @imported = {} end - # Try to load the object with the given fully qualified name. For - # each file that was actually loaded, yield(filename, modname). - def try_load_fqname(fqname) + # Try to load the object with the given fully qualified name. + def try_load_fqname(type, fqname) return nil if fqname == "" # special-case main. name2files(fqname).each do |filename| if not loaded?(filename) - modname = begin - import_if_possible(filename) + begin + imported_types = import_if_possible(filename) + if result = imported_types.find { |t| t.type == type and t.name == fqname } + Puppet.debug "Automatically imported #{fqname} from #{filename} into #{environment}" + return result + end rescue Puppet::ImportError => detail # We couldn't load the item # I'm not convienced we should just drop these errors, but this # preserves existing behaviours. - nil end - yield(filename, modname) end end + # Nothing found. + return nil end def loaded?(name) @loaded.include?(name) end def parse_file(file) Puppet.debug("importing '#{file}' in environment #{environment}") parser = Puppet::Parser::Parser.new(environment) parser.file = file - parser.parse + return parser.parse end # Utility method factored out of load for handling thread-safety. # This isn't tested in the specs, because that's basically impossible. def import_if_possible(file, current_file = nil) @loaded[file] || begin case @loading.owner_of(file) when :this_thread nil when :another_thread import_if_possible(file,current_file) when :nobody @loaded[file] = import(file,current_file) end ensure @loading.done_with(file) end end private # Return a list of all file basenames that should be tried in order # to load the object with the given fully qualified name. def name2files(fqname) result = [] ary = fqname.split("::") while ary.length > 0 result << ary.join(File::SEPARATOR) ary.pop end return result end end diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb index 6296d26e5..57ccba58b 100644 --- a/lib/puppet/resource/type.rb +++ b/lib/puppet/resource/type.rb @@ -1,328 +1,330 @@ require 'puppet/parser/parser' require 'puppet/util/warnings' require 'puppet/util/errors' require 'puppet/util/inline_docs' require 'puppet/parser/ast/leaf' require 'puppet/dsl' class Puppet::Resource::Type Puppet::ResourceType = self include Puppet::Util::InlineDocs include Puppet::Util::Warnings include Puppet::Util::Errors RESOURCE_SUPERTYPES = [:hostclass, :node, :definition] - attr_accessor :file, :line, :doc, :code, :ruby_code, :parent, :resource_type_collection, :module_name - attr_reader :type, :namespace, :arguments, :behaves_like + attr_accessor :file, :line, :doc, :code, :ruby_code, :parent, :resource_type_collection + attr_reader :type, :namespace, :arguments, :behaves_like, :module_name RESOURCE_SUPERTYPES.each do |t| define_method("#{t}?") { self.type == t } end require 'puppet/indirector' extend Puppet::Indirector indirects :resource_type, :terminus_class => :parser def self.from_pson(data) name = data.delete('name') or raise ArgumentError, "Resource Type names must be specified" type = data.delete('type') || "definition" data = data.inject({}) { |result, ary| result[ary[0].intern] = ary[1]; result } new(type, name, data) end def to_pson_data_hash data = [:code, :doc, :line, :file, :parent].inject({}) do |hash, param| next hash unless value = self.send(param) hash[param.to_s] = value hash end data['arguments'] = arguments.dup data['name'] = name data['type'] = type data end def to_pson(*args) to_pson_data_hash.to_pson(*args) end # Are we a child of the passed class? Do a recursive search up our # parentage tree to figure it out. def child_of?(klass) return false unless parent return(klass == parent_type ? true : parent_type.child_of?(klass)) end # Now evaluate the code associated with this class or definition. def evaluate_code(resource) scope = resource.scope if tmp = evaluate_parent_type(resource) scope = tmp end scope = subscope(scope, resource) unless resource.title == :main set_resource_parameters(resource, scope) code.safeevaluate(scope) if code evaluate_ruby_code(resource, scope) if ruby_code end def initialize(type, name, options = {}) @type = type.to_s.downcase.to_sym raise ArgumentError, "Invalid resource supertype '#{type}'" unless RESOURCE_SUPERTYPES.include?(@type) name = convert_from_ast(name) if name.is_a?(Puppet::Parser::AST::HostName) set_name_and_namespace(name) [:code, :doc, :line, :file, :parent].each do |param| next unless value = options[param] send(param.to_s + "=", value) end set_arguments(options[:arguments]) + + @module_name = options[:module_name] end # This is only used for node names, and really only when the node name # is a regexp. def match(string) return string.to_s.downcase == name unless name_is_regex? @name =~ string end # Add code from a new instance to our code. def merge(other) fail "#{name} is not a class; cannot add code to it" unless type == :hostclass fail "#{other.name} is not a class; cannot add code from it" unless other.type == :hostclass fail "Cannot have code outside of a class/node/define because 'freeze_main' is enabled" if name == "" and Puppet.settings[:freeze_main] if parent and other.parent and parent != other.parent fail "Cannot merge classes with different parent classes (#{name} => #{parent} vs. #{other.name} => #{other.parent})" end # We know they're either equal or only one is set, so keep whichever parent is specified. self.parent ||= other.parent if other.doc self.doc ||= "" self.doc += other.doc end # This might just be an empty, stub class. return unless other.code unless self.code self.code = other.code return end array_class = Puppet::Parser::AST::ASTArray self.code = array_class.new(:children => [self.code]) unless self.code.is_a?(array_class) if other.code.is_a?(array_class) code.children += other.code.children else code.children << other.code end end # Make an instance of our resource type. This is only possible # for those classes and nodes that don't have any arguments, and is # only useful for things like the 'include' function. def mk_plain_resource(scope) type == :definition and raise ArgumentError, "Cannot create resources for defined resource types" resource_type = type == :hostclass ? :class : :node # Make sure our parent class has been evaluated, if we have one. if parent parent_resource = scope.catalog.resource(resource_type, parent) unless parent_resource parent_type(scope).mk_plain_resource(scope) end end # Do nothing if the resource already exists; this makes sure we don't # get multiple copies of the class resource, which helps provide the # singleton nature of classes. if resource = scope.catalog.resource(resource_type, name) return resource end resource = Puppet::Parser::Resource.new(resource_type, name, :scope => scope, :source => self) scope.compiler.add_resource(scope, resource) scope.catalog.tag(*resource.tags) resource end def name return @name unless @name.is_a?(Regexp) @name.source.downcase.gsub(/[^-\w:.]/,'').sub(/^\.+/,'') end def name_is_regex? @name.is_a?(Regexp) end # MQR TODO: # # The change(s) introduced by the fix for #4270 are mostly silly & should be # removed, though we didn't realize it at the time. If it can be established/ # ensured that nodes never call parent_type and that resource_types are always # (as they should be) members of exactly one resource_type_collection the # following method could / should be replaced with: # # def parent_type # @parent_type ||= parent && ( # resource_type_collection.find_or_load([name],parent,type.to_sym) || # fail Puppet::ParseError, "Could not find parent resource type '#{parent}' of type #{type} in #{resource_type_collection.environment}" # ) # end # # ...and then the rest of the changes around passing in scope reverted. # def parent_type(scope = nil) return nil unless parent unless @parent_type raise "Must pass scope to parent_type when called first time" unless scope unless @parent_type = scope.environment.known_resource_types.send("find_#{type}", [name], parent) fail Puppet::ParseError, "Could not find parent resource type '#{parent}' of type #{type} in #{scope.environment}" end end @parent_type end # Set any arguments passed by the resource as variables in the scope. def set_resource_parameters(resource, scope) set = {} resource.to_hash.each do |param, value| param = param.to_sym fail Puppet::ParseError, "#{resource.ref} does not accept attribute #{param}" unless valid_parameter?(param) exceptwrap { scope.setvar(param.to_s, value) } set[param] = true end # Verify that all required arguments are either present or # have been provided with defaults. arguments.each do |param, default| param = param.to_sym next if set.include?(param) # Even if 'default' is a false value, it's an AST value, so this works fine fail Puppet::ParseError, "Must pass #{param} to #{resource.ref}" unless default value = default.safeevaluate(scope) scope.setvar(param.to_s, value) # Set it in the resource, too, so the value makes it to the client. resource[param] = value end scope.setvar("title", resource.title) unless set.include? :title scope.setvar("name", resource.name) unless set.include? :name scope.setvar("module_name", module_name) if module_name and ! set.include? :module_name if caller_name = scope.parent_module_name and ! set.include?(:caller_module_name) scope.setvar("caller_module_name", caller_name) end scope.class_set(self.name,scope) if hostclass? or node? end # Create a new subscope in which to evaluate our code. def subscope(scope, resource) scope.newscope :resource => resource, :namespace => self.namespace, :source => self end # Check whether a given argument is valid. def valid_parameter?(param) param = param.to_s return true if param == "name" return true if Puppet::Type.metaparam?(param) return false unless defined?(@arguments) return(arguments.include?(param) ? true : false) end def set_arguments(arguments) @arguments = {} return if arguments.nil? arguments.each do |arg, default| arg = arg.to_s warn_if_metaparam(arg, default) @arguments[arg] = default end end private def convert_from_ast(name) value = name.value if value.is_a?(Puppet::Parser::AST::Regex) name = value.value else name = value end end def evaluate_parent_type(resource) return unless klass = parent_type(resource.scope) and parent_resource = resource.scope.compiler.catalog.resource(:class, klass.name) || resource.scope.compiler.catalog.resource(:node, klass.name) parent_resource.evaluate unless parent_resource.evaluated? parent_scope(resource.scope, klass) end def evaluate_ruby_code(resource, scope) Puppet::DSL::ResourceAPI.new(resource, scope, ruby_code).evaluate end # Split an fq name into a namespace and name def namesplit(fullname) ary = fullname.split("::") n = ary.pop || "" ns = ary.join("::") return ns, n end def parent_scope(scope, klass) scope.class_scope(klass) || raise(Puppet::DevError, "Could not find scope for #{klass.name}") end def set_name_and_namespace(name) if name.is_a?(Regexp) @name = name @namespace = "" else @name = name.to_s.downcase # Note we're doing something somewhat weird here -- we're setting # the class's namespace to its fully qualified name. This means # anything inside that class starts looking in that namespace first. @namespace, ignored_shortname = @type == :hostclass ? [@name, ''] : namesplit(@name) end end def warn_if_metaparam(param, default) return unless Puppet::Type.metaparamclass(param) if default warnonce "#{param} is a metaparam; this value will inherit to all contained resources" else raise Puppet::ParseError, "#{param} is a metaparameter; please choose another parameter name in the #{self.name} definition" end end end diff --git a/lib/puppet/resource/type_collection.rb b/lib/puppet/resource/type_collection.rb index 4254b037e..a96927613 100644 --- a/lib/puppet/resource/type_collection.rb +++ b/lib/puppet/resource/type_collection.rb @@ -1,205 +1,204 @@ class Puppet::Resource::TypeCollection attr_reader :environment def clear @hostclasses.clear @definitions.clear @nodes.clear end def initialize(env) @environment = env.is_a?(String) ? Puppet::Node::Environment.new(env) : env @hostclasses = {} @definitions = {} @nodes = {} # So we can keep a list and match the first-defined regex @node_list = [] @watched_files = {} end + def import_ast(ast, modname) + ast.instantiate(modname).each do |instance| + add(instance) + end + end + def <<(thing) add(thing) self end def add(instance) if instance.type == :hostclass and other = @hostclasses[instance.name] and other.type == :hostclass other.merge(instance) return other end method = "add_#{instance.type}" send(method, instance) instance.resource_type_collection = self instance end def add_hostclass(instance) dupe_check(instance, @hostclasses) { |dupe| "Class '#{instance.name}' is already defined#{dupe.error_context}; cannot redefine" } dupe_check(instance, @definitions) { |dupe| "Definition '#{instance.name}' is already defined#{dupe.error_context}; cannot be redefined as a class" } @hostclasses[instance.name] = instance instance end def hostclass(name) @hostclasses[munge_name(name)] end def add_node(instance) dupe_check(instance, @nodes) { |dupe| "Node '#{instance.name}' is already defined#{dupe.error_context}; cannot redefine" } @node_list << instance @nodes[instance.name] = instance instance end def loader require 'puppet/parser/type_loader' @loader ||= Puppet::Parser::TypeLoader.new(environment) end def node(name) name = munge_name(name) if node = @nodes[name] return node end @node_list.each do |node| next unless node.name_is_regex? return node if node.match(name) end nil end def node_exists?(name) @nodes[munge_name(name)] end def nodes? @nodes.length > 0 end def add_definition(instance) dupe_check(instance, @hostclasses) { |dupe| "'#{instance.name}' is already defined#{dupe.error_context} as a class; cannot redefine as a definition" } dupe_check(instance, @definitions) { |dupe| "Definition '#{instance.name}' is already defined#{dupe.error_context}; cannot be redefined" } @definitions[instance.name] = instance end def definition(name) @definitions[munge_name(name)] end def find_node(namespaces, name) @nodes[munge_name(name)] end def find_hostclass(namespaces, name) find_or_load(namespaces, name, :hostclass) end def find_definition(namespaces, name) find_or_load(namespaces, name, :definition) end [:hostclasses, :nodes, :definitions].each do |m| define_method(m) do instance_variable_get("@#{m}").dup end end def stale? @watched_files.values.detect { |file| file.changed? } end def version return @version if defined?(@version) if environment[:config_version] == "" @version = Time.now.to_i return @version end @version = Puppet::Util.execute([environment[:config_version]]).strip rescue Puppet::ExecutionFailure => e raise Puppet::ParseError, "Unable to set config_version: #{e.message}" end def watch_file(file) @watched_files[file] = Puppet::Util::LoadedFile.new(file) end def watching_file?(file) @watched_files.include?(file) end private # Return a list of all possible fully-qualified names that might be # meant by the given name, in the context of namespaces. def resolve_namespaces(namespaces, name) name = name.downcase if name =~ /^::/ # name is explicitly fully qualified, so just return it, sans # initial "::". return [name.sub(/^::/, '')] end if name == "" # The name "" has special meaning--it always refers to a "main" # hostclass which contains all toplevel resources. return [""] end namespaces = [namespaces] unless namespaces.is_a?(Array) namespaces = namespaces.collect { |ns| ns.downcase } result = [] namespaces.each do |namespace| ary = namespace.split("::") # Search each namespace nesting in innermost-to-outermost order. while ary.length > 0 result << "#{ary.join("::")}::#{name}" ary.pop end # Finally, search the toplevel namespace. result << name end return result.uniq end # Resolve namespaces and find the given object. Autoload it if # necessary. def find_or_load(namespaces, name, type) resolve_namespaces(namespaces, name).each do |fqname| - if result = send(type, fqname) + if result = send(type, fqname) || loader.try_load_fqname(type, fqname) return result end - loader.try_load_fqname(fqname) do |filename, modname| - if result = send(type, fqname) - Puppet.debug "Automatically imported #{name} from #{filename} into #{environment}" - result.module_name = modname if modname and result.respond_to?(:module_name=) - return result - end - end end # Nothing found. return nil end def munge_name(name) name.to_s.downcase end def dupe_check(instance, hash) return unless dupe = hash[instance.name] message = yield dupe instance.fail Puppet::ParseError, message end end diff --git a/lib/puppet/util/rdoc/parser.rb b/lib/puppet/util/rdoc/parser.rb index 63df38ab9..30da607d9 100644 --- a/lib/puppet/util/rdoc/parser.rb +++ b/lib/puppet/util/rdoc/parser.rb @@ -1,477 +1,481 @@ # Puppet "parser" for the rdoc system # The parser uses puppet parser and traverse the AST to instruct RDoc about # our current structures. It also parses ruby files that could contain # either custom facts or puppet plugins (functions, types...) # rdoc mandatory includes require "rdoc/code_objects" require "puppet/util/rdoc/code_objects" require "rdoc/tokenstream" require "rdoc/markup/simple_markup/preprocess" require "rdoc/parsers/parserfactory" module RDoc class Parser extend ParserFactory SITE = "__site__" - attr_accessor :ast, :input_file_name, :top_level + attr_accessor :input_file_name, :top_level # parser registration into RDoc parse_files_matching(/\.(rb|pp)$/) # called with the top level file def initialize(top_level, file_name, content, options, stats) @options = options @stats = stats @input_file_name = file_name @top_level = PuppetTopLevel.new(top_level) @progress = $stderr unless options.quiet end # main entry point def scan Puppet.info "rdoc: scanning #{@input_file_name}" if @input_file_name =~ /\.pp$/ @parser = Puppet::Parser::Parser.new(Puppet[:environment]) + environment = @parser.environment @parser.file = @input_file_name - @ast = @parser.parse + @known_resource_types = environment.known_resource_types + @parser.parse.instantiate('').each do |type| + @known_resource_types.add type + end end scan_top_level(@top_level) @top_level end # Due to a bug in RDoc, we need to roll our own find_module_named # The issue is that RDoc tries harder by asking the parent for a class/module # of the name. But by doing so, it can mistakenly use a module of same name # but from which we are not descendant. def find_object_named(container, name) return container if container.name == name container.each_classmodule do |m| return m if m.name == name end nil end # walk down the namespace and lookup/create container as needed def get_class_or_module(container, name) # class ::A -> A is in the top level if name =~ /^::/ container = @top_level end names = name.split('::') final_name = names.pop names.each do |name| prev_container = container container = find_object_named(container, name) container ||= prev_container.add_class(PuppetClass, name, nil) end [container, final_name] end # split_module tries to find if +path+ belongs to the module path # if it does, it returns the module name, otherwise if we are sure # it is part of the global manifest path, "__site__" is returned. # And finally if this path couldn't be mapped anywhere, nil is returned. def split_module(path) # find a module fullpath = File.expand_path(path) Puppet.debug "rdoc: testing #{fullpath}" if fullpath =~ /(.*)\/([^\/]+)\/(?:manifests|plugins|lib)\/.+\.(pp|rb)$/ modpath = $1 name = $2 Puppet.debug "rdoc: module #{name} into #{modpath} ?" Puppet::Module.modulepath.each do |mp| if File.identical?(modpath,mp) Puppet.debug "rdoc: found module #{name}" return name end end end if fullpath =~ /\.(pp|rb)$/ # there can be paths we don't want to scan under modules # imagine a ruby or manifest that would be distributed as part as a module # but we don't want those to be hosted under Puppet::Module.modulepath.each do |mp| # check that fullpath is a descendant of mp dirname = fullpath while (dirname = File.dirname(dirname)) != '/' return nil if File.identical?(dirname,mp) end end end # we are under a global manifests Puppet.debug "rdoc: global manifests" SITE end # create documentation for the top level +container+ def scan_top_level(container) # use the module README as documentation for the module comment = "" readme = File.join(File.dirname(File.dirname(@input_file_name)), "README") comment = File.open(readme,"r") { |f| f.read } if FileTest.readable?(readme) look_for_directives_in(container, comment) unless comment.empty? # infer module name from directory name = split_module(@input_file_name) if name.nil? # skip .pp files that are not in manifests directories as we can't guarantee they're part # of a module or the global configuration. container.document_self = false return end Puppet.debug "rdoc: scanning for #{name}" container.module_name = name container.global=true if name == SITE @stats.num_modules += 1 container, name = get_class_or_module(container,name) mod = container.add_module(PuppetModule, name) mod.record_location(@top_level) mod.comment = comment if @input_file_name =~ /\.pp$/ parse_elements(mod) elsif @input_file_name =~ /\.rb$/ parse_plugins(mod) end end # create documentation for include statements we can find in +code+ # and associate it with +container+ def scan_for_include_or_require(container, code) code = [code] unless code.is_a?(Array) code.each do |stmt| scan_for_include_or_require(container,stmt.children) if stmt.is_a?(Puppet::Parser::AST::ASTArray) if stmt.is_a?(Puppet::Parser::AST::Function) and ['include','require'].include?(stmt.name) stmt.arguments.each do |included| Puppet.debug "found #{stmt.name}: #{included.value}" container.send("add_#{stmt.name}",Include.new(included.value, stmt.doc)) end end end end # create documentation for realize statements we can find in +code+ # and associate it with +container+ def scan_for_realize(container, code) code = [code] unless code.is_a?(Array) code.each do |stmt| scan_for_realize(container,stmt.children) if stmt.is_a?(Puppet::Parser::AST::ASTArray) if stmt.is_a?(Puppet::Parser::AST::Function) and stmt.name == 'realize' stmt.arguments.each do |realized| Puppet.debug "found #{stmt.name}: #{realized}" container.add_realize(Include.new(realized.to_s, stmt.doc)) end end end end # create documentation for global variables assignements we can find in +code+ # and associate it with +container+ def scan_for_vardef(container, code) code = [code] unless code.is_a?(Array) code.each do |stmt| scan_for_vardef(container,stmt.children) if stmt.is_a?(Puppet::Parser::AST::ASTArray) if stmt.is_a?(Puppet::Parser::AST::VarDef) Puppet.debug "rdoc: found constant: #{stmt.name} = #{stmt.value}" container.add_constant(Constant.new(stmt.name.to_s, stmt.value.to_s, stmt.doc)) end end end # create documentation for resources we can find in +code+ # and associate it with +container+ def scan_for_resource(container, code) code = [code] unless code.is_a?(Array) code.each do |stmt| scan_for_resource(container,stmt.children) if stmt.is_a?(Puppet::Parser::AST::ASTArray) if stmt.is_a?(Puppet::Parser::AST::Resource) and !stmt.type.nil? begin type = stmt.type.split("::").collect { |s| s.capitalize }.join("::") title = stmt.title.is_a?(Puppet::Parser::AST::ASTArray) ? stmt.title.to_s.gsub(/\[(.*)\]/,'\1') : stmt.title.to_s Puppet.debug "rdoc: found resource: #{type}[#{title}]" param = [] stmt.params.children.each do |p| res = {} res["name"] = p.param res["value"] = "#{p.value.to_s}" unless p.value.nil? param << res end container.add_resource(PuppetResource.new(type, title, stmt.doc, param)) rescue => detail raise Puppet::ParseError, "impossible to parse resource in #{stmt.file} at line #{stmt.line}: #{detail}" end end end end def resource_stmt_to_ref(stmt) type = stmt.type.split("::").collect { |s| s.capitalize }.join("::") title = stmt.title.is_a?(Puppet::Parser::AST::ASTArray) ? stmt.title.to_s.gsub(/\[(.*)\]/,'\1') : stmt.title.to_s param = stmt.params.children.collect do |p| {"name" => p.param, "value" => p.value.to_s} end PuppetResource.new(type, title, stmt.doc, param) end # create documentation for a class named +name+ def document_class(name, klass, container) Puppet.debug "rdoc: found new class #{name}" container, name = get_class_or_module(container, name) superclass = klass.parent superclass = "" if superclass.nil? or superclass.empty? @stats.num_classes += 1 comment = klass.doc look_for_directives_in(container, comment) unless comment.empty? cls = container.add_class(PuppetClass, name, superclass) # it is possible we already encountered this class, while parsing some namespaces # from other classes of other files. But at that time we couldn't know this class superclass # so, now we know it and force it. cls.superclass = superclass cls.record_location(@top_level) # scan class code for include code = klass.code.children if klass.code.is_a?(Puppet::Parser::AST::ASTArray) code ||= klass.code unless code.nil? scan_for_include_or_require(cls, code) scan_for_realize(cls, code) scan_for_resource(cls, code) if Puppet.settings[:document_all] end cls.comment = comment rescue => detail raise Puppet::ParseError, "impossible to parse class '#{name}' in #{klass.file} at line #{klass.line}: #{detail}" end # create documentation for a node def document_node(name, node, container) Puppet.debug "rdoc: found new node #{name}" superclass = node.parent superclass = "" if superclass.nil? or superclass.empty? comment = node.doc look_for_directives_in(container, comment) unless comment.empty? n = container.add_node(name, superclass) n.record_location(@top_level) code = node.code.children if node.code.is_a?(Puppet::Parser::AST::ASTArray) code ||= node.code unless code.nil? scan_for_include_or_require(n, code) scan_for_realize(n, code) scan_for_vardef(n, code) scan_for_resource(n, code) if Puppet.settings[:document_all] end n.comment = comment rescue => detail raise Puppet::ParseError, "impossible to parse node '#{name}' in #{node.file} at line #{node.line}: #{detail}" end # create documentation for a define def document_define(name, define, container) Puppet.debug "rdoc: found new definition #{name}" # find superclas if any @stats.num_methods += 1 # find the parent # split define name by :: to find the complete module hierarchy container, name = get_class_or_module(container,name) # build up declaration declaration = "" define.arguments.each do |arg,value| declaration << "\$#{arg}" unless value.nil? declaration << " => " case value when Puppet::Parser::AST::Leaf declaration << "'#{value.value}'" when Puppet::Parser::AST::ASTArray declaration << "[#{value.children.collect { |v| "'#{v}'" }.join(", ")}]" else declaration << "#{value.to_s}" end end declaration << ", " end declaration.chop!.chop! if declaration.size > 1 # register method into the container meth = AnyMethod.new(declaration, name) meth.comment = define.doc container.add_method(meth) look_for_directives_in(container, meth.comment) unless meth.comment.empty? meth.params = "( #{declaration} )" meth.visibility = :public meth.document_self = true meth.singleton = false rescue => detail raise Puppet::ParseError, "impossible to parse definition '#{name}' in #{define.file} at line #{define.line}: #{detail}" end # Traverse the AST tree and produce code-objects node # that contains the documentation def parse_elements(container) Puppet.debug "rdoc: scanning manifest" - @ast.hostclasses.values.sort { |a,b| a.name <=> b.name }.each do |klass| + @known_resource_types.hostclasses.values.sort { |a,b| a.name <=> b.name }.each do |klass| name = klass.name if klass.file == @input_file_name unless name.empty? document_class(name,klass,container) else # on main class document vardefs code = klass.code.children if klass.code.is_a?(Puppet::Parser::AST::ASTArray) code ||= klass.code scan_for_vardef(container, code) unless code.nil? end end end - @ast.definitions.each do |name, define| + @known_resource_types.definitions.each do |name, define| if define.file == @input_file_name document_define(name,define,container) end end - @ast.nodes.each do |name, node| + @known_resource_types.nodes.each do |name, node| if node.file == @input_file_name document_node(name.to_s,node,container) end end end # create documentation for plugins def parse_plugins(container) Puppet.debug "rdoc: scanning plugin or fact" if @input_file_name =~ /\/facter\/[^\/]+\.rb$/ parse_fact(container) else parse_puppet_plugin(container) end end # this is a poor man custom fact parser :-) def parse_fact(container) comments = "" current_fact = nil File.open(@input_file_name) do |of| of.each do |line| # fetch comments if line =~ /^[ \t]*# ?(.*)$/ comments += $1 + "\n" elsif line =~ /^[ \t]*Facter.add\(['"](.*?)['"]\)/ current_fact = Fact.new($1,{}) look_for_directives_in(container, comments) unless comments.empty? current_fact.comment = comments container.add_fact(current_fact) current_fact.record_location(@top_level) comments = "" Puppet.debug "rdoc: found custom fact #{current_fact.name}" elsif line =~ /^[ \t]*confine[ \t]*:(.*?)[ \t]*=>[ \t]*(.*)$/ current_fact.confine = { :type => $1, :value => $2 } unless current_fact.nil? else # unknown line type comments ="" end end end end # this is a poor man puppet plugin parser :-) # it doesn't extract doc nor desc :-( def parse_puppet_plugin(container) comments = "" current_plugin = nil File.open(@input_file_name) do |of| of.each do |line| # fetch comments if line =~ /^[ \t]*# ?(.*)$/ comments += $1 + "\n" elsif line =~ /^[ \t]*newfunction[ \t]*\([ \t]*:(.*?)[ \t]*,[ \t]*:type[ \t]*=>[ \t]*(:rvalue|:lvalue)\)/ current_plugin = Plugin.new($1, "function") container.add_plugin(current_plugin) look_for_directives_in(container, comments) unless comments.empty? current_plugin.comment = comments current_plugin.record_location(@top_level) comments = "" Puppet.debug "rdoc: found new function plugins #{current_plugin.name}" elsif line =~ /^[ \t]*Puppet::Type.newtype[ \t]*\([ \t]*:(.*?)\)/ current_plugin = Plugin.new($1, "type") container.add_plugin(current_plugin) look_for_directives_in(container, comments) unless comments.empty? current_plugin.comment = comments current_plugin.record_location(@top_level) comments = "" Puppet.debug "rdoc: found new type plugins #{current_plugin.name}" elsif line =~ /module Puppet::Parser::Functions/ # skip else # unknown line type comments ="" end end end end # look_for_directives_in scans the current +comment+ for RDoc directives def look_for_directives_in(context, comment) preprocess = SM::PreProcess.new(@input_file_name, @options.rdoc_include) preprocess.handle(comment) do |directive, param| case directive when "stopdoc" context.stop_doc "" when "startdoc" context.start_doc context.force_documentation = true "" when "enddoc" #context.done_documenting = true #"" throw :enddoc when "main" options = Options.instance options.main_page = param "" when "title" options = Options.instance options.title = param "" when "section" context.set_current_section(param, comment) comment.replace("") # 1.8 doesn't support #clear break else warn "Unrecognized directive '#{directive}'" break end end remove_private_comments(comment) end def remove_private_comments(comment) comment.gsub!(/^#--.*?^#\+\+/m, '') comment.sub!(/^#--.*/m, '') end end end diff --git a/spec/integration/parser/collector_spec.rb b/spec/integration/parser/collector_spec.rb index 73273c909..b1cfc51c7 100755 --- a/spec/integration/parser/collector_spec.rb +++ b/spec/integration/parser/collector_spec.rb @@ -1,38 +1,38 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/parser/collector' describe Puppet::Parser::Collector do before do @scope = Puppet::Parser::Scope.new(:compiler => Puppet::Parser::Compiler.new(Puppet::Node.new("mynode"))) @resource = Puppet::Parser::Resource.new("file", "/tmp/testing", :scope => @scope, :source => "fakesource") {:owner => "root", :group => "bin", :mode => "644"}.each do |param, value| @resource[param] = value end end def query(text) code = "File <| #{text} |>" parser = Puppet::Parser::Parser.new(@scope.compiler) - parser.parse(code).hostclass("").code[0].query + return parser.parse(code).code[0].query end {true => [%{title == "/tmp/testing"}, %{(title == "/tmp/testing")}, %{group == bin}, %{title == "/tmp/testing" and group == bin}, %{title == bin or group == bin}, %{title == "/tmp/testing" or title == bin}, %{title == "/tmp/testing"}, %{(title == "/tmp/testing" or title == bin) and group == bin}], false => [%{title == bin}, %{title == bin or (title == bin and group == bin)}, %{title != "/tmp/testing"}, %{title != "/tmp/testing" and group != bin}] }.each do |result, ary| ary.each do |string| it "should return '#{result}' when collecting resources with '#{string}'" do str, code = query(string).evaluate @scope code.should be_instance_of(Proc) code.call(@resource).should == result end end end end diff --git a/spec/integration/parser/compiler_spec.rb b/spec/integration/parser/compiler_spec.rb index 67e8e5e62..266347c60 100755 --- a/spec/integration/parser/compiler_spec.rb +++ b/spec/integration/parser/compiler_spec.rb @@ -1,83 +1,94 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../spec_helper' describe Puppet::Parser::Compiler do before :each do @node = Puppet::Node.new "testnode" @scope_resource = stub 'scope_resource', :builtin? => true, :finish => nil, :ref => 'Class[main]' @scope = stub 'scope', :resource => @scope_resource, :source => mock("source") end after do Puppet.settings.clear end it "should be able to determine the configuration version from a local version control repository" do # This should always work, because we should always be # in the puppet repo when we run this. version = %x{git rev-parse HEAD}.chomp Puppet.settings[:config_version] = 'git rev-parse HEAD' @parser = Puppet::Parser::Parser.new "development" @compiler = Puppet::Parser::Compiler.new(@node) @compiler.catalog.version.should == version end describe "when resolving class references" do it "should favor local scope, even if there's an included class in topscope" do Puppet[:code] = <<-PP class experiment { class baz { } notify {"x" : require => Class[Baz] } } class baz { } include baz include experiment include experiment::baz PP catalog = Puppet::Parser::Compiler.compile(Puppet::Node.new("mynode")) notify_resource = catalog.resource( "Notify[x]" ) notify_resource[:require].title.should == "Experiment::Baz" end it "should favor local scope, even if there's an unincluded class in topscope" do Puppet[:code] = <<-PP class experiment { class baz { } notify {"x" : require => Class[Baz] } } class baz { } include experiment include experiment::baz PP catalog = Puppet::Parser::Compiler.compile(Puppet::Node.new("mynode")) notify_resource = catalog.resource( "Notify[x]" ) notify_resource[:require].title.should == "Experiment::Baz" end end it "should recompute the version after input files are re-parsed" do Puppet[:code] = 'class foo { }' Time.stubs(:now).returns(1) node = Puppet::Node.new('mynode') Puppet::Parser::Compiler.compile(node).version.should == 1 Time.stubs(:now).returns(2) Puppet::Parser::Compiler.compile(node).version.should == 1 # no change because files didn't change Puppet::Resource::TypeCollection.any_instance.stubs(:stale?).returns(true).then.returns(false) # pretend change Puppet::Parser::Compiler.compile(node).version.should == 2 end + + it "should not allow classes inside conditional constructs" do + Puppet[:code] = <<-PP + if true { + class foo { + } + } + PP + + lambda { Puppet::Parser::Compiler.compile(Puppet::Node.new("mynode")) }.should raise_error(Puppet::Error) + end end diff --git a/spec/integration/parser/parser_spec.rb b/spec/integration/parser/parser_spec.rb index 7b85bcacb..0d9aa51e1 100755 --- a/spec/integration/parser/parser_spec.rb +++ b/spec/integration/parser/parser_spec.rb @@ -1,113 +1,115 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../spec_helper' describe Puppet::Parser::Parser do module ParseMatcher class ParseAs def initialize(klass) @parser = Puppet::Parser::Parser.new "development" @class = klass end def result_instance - @result.hostclass("").code[0] + @result.code[0] end def matches?(string) @string = string @result = @parser.parse(string) result_instance.instance_of?(@class) end def description "parse as a #{@class}" end def failure_message " expected #{@string} to parse as #{@class} but was #{result_instance.class}" end def negative_failure_message " expected #{@string} not to parse as #{@class}" end end def parse_as(klass) ParseAs.new(klass) end class ParseWith def initialize(block) @parser = Puppet::Parser::Parser.new "development" @block = block end def result_instance - @result.hostclass("").code[0] + @result.code[0] end def matches?(string) @string = string @result = @parser.parse(string) @block.call(result_instance) end def description "parse with the block evaluating to true" end def failure_message " expected #{@string} to parse with a true result in the block" end def negative_failure_message " expected #{@string} not to parse with a true result in the block" end end def parse_with(&block) ParseWith.new(block) end end include ParseMatcher before :each do @resource_type_collection = Puppet::Resource::TypeCollection.new("env") @parser = Puppet::Parser::Parser.new "development" end describe "when parsing comments before statement" do it "should associate the documentation to the statement AST node" do ast = @parser.parse(""" # comment class test {} """) - ast.hostclass("test").doc.should == "comment\n" + ast.code[0].should be_a(Puppet::Parser::AST::Hostclass) + ast.code[0].name.should == 'test' + ast.code[0].instantiate('')[0].doc.should == "comment\n" end end describe "when parsing" do it "should be able to parse normal left to right relationships" do "Notify[foo] -> Notify[bar]".should parse_as(Puppet::Parser::AST::Relationship) end it "should be able to parse right to left relationships" do "Notify[foo] <- Notify[bar]".should parse_as(Puppet::Parser::AST::Relationship) end it "should be able to parse normal left to right subscriptions" do "Notify[foo] ~> Notify[bar]".should parse_as(Puppet::Parser::AST::Relationship) end it "should be able to parse right to left subscriptions" do "Notify[foo] <~ Notify[bar]".should parse_as(Puppet::Parser::AST::Relationship) end it "should correctly set the arrow type of a relationship" do "Notify[foo] <~ Notify[bar]".should parse_with { |rel| rel.arrow == "<~" } end end end diff --git a/spec/unit/dsl/resource_type_api_spec.rb b/spec/unit/dsl/resource_type_api_spec.rb index 5abe79ea7..4b8ccf5a7 100755 --- a/spec/unit/dsl/resource_type_api_spec.rb +++ b/spec/unit/dsl/resource_type_api_spec.rb @@ -1,46 +1,44 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/dsl/resource_type_api' class DSLAPITester include Puppet::DSL::ResourceTypeAPI end describe Puppet::DSL::ResourceTypeAPI do before do @api = DSLAPITester.new end [:definition, :node, :hostclass].each do |type| method = type == :definition ? "define" : type it "should be able to create a #{type}" do - newtype = Puppet::Resource::Type.new(:hostclass, "foo") - Puppet::Resource::Type.expects(:new).with { |t, n, args| t == type }.returns newtype - @api.send(method, "myname") + newtype = @api.send(method, "myname") + newtype.should be_a(Puppet::Resource::Type) + newtype.type.should == type end it "should use the provided name when creating a #{type}" do - type = Puppet::Resource::Type.new(:hostclass, "foo") - Puppet::Resource::Type.expects(:new).with { |t, n, args| n == "myname" }.returns type - @api.send(method, "myname") + newtype = @api.send(method, "myname") + newtype.name.should == "myname" end unless type == :definition - it "should pass in any provided options" do - type = Puppet::Resource::Type.new(:hostclass, "foo") - Puppet::Resource::Type.expects(:new).with { |t, n, args| args == {:myarg => :myvalue} }.returns type - @api.send(method, "myname", :myarg => :myvalue) + it "should pass in any provided options when creating a #{type}" do + newtype = @api.send(method, "myname", :line => 200) + newtype.line.should == 200 end end it "should set any provided block as the type's ruby code" it "should add the type to the current environment's known resource types" end describe "when creating a definition" do it "should use the provided options to define valid arguments for the resource type" end end diff --git a/spec/unit/node/environment_spec.rb b/spec/unit/node/environment_spec.rb index e495d30a6..be2980879 100755 --- a/spec/unit/node/environment_spec.rb +++ b/spec/unit/node/environment_spec.rb @@ -1,328 +1,328 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/node/environment' require 'puppet/util/execution' describe Puppet::Node::Environment do after do Puppet::Node::Environment.clear end it "should include the Cacher module" do Puppet::Node::Environment.ancestors.should be_include(Puppet::Util::Cacher) end it "should use the filetimeout for the ttl for the modulepath" do Puppet::Node::Environment.attr_ttl(:modulepath).should == Integer(Puppet[:filetimeout]) end it "should use the filetimeout for the ttl for the module list" do Puppet::Node::Environment.attr_ttl(:modules).should == Integer(Puppet[:filetimeout]) end it "should use the filetimeout for the ttl for the manifestdir" do Puppet::Node::Environment.attr_ttl(:manifestdir).should == Integer(Puppet[:filetimeout]) end it "should use the default environment if no name is provided while initializing an environment" do Puppet.settings.expects(:value).with(:environment).returns("one") Puppet::Node::Environment.new.name.should == :one end it "should treat environment instances as singletons" do Puppet::Node::Environment.new("one").should equal(Puppet::Node::Environment.new("one")) end it "should treat an environment specified as names or strings as equivalent" do Puppet::Node::Environment.new(:one).should equal(Puppet::Node::Environment.new("one")) end it "should return its name when converted to a string" do Puppet::Node::Environment.new(:one).to_s.should == "one" end it "should just return any provided environment if an environment is provided as the name" do one = Puppet::Node::Environment.new(:one) Puppet::Node::Environment.new(one).should equal(one) end describe "when managing known resource types" do before do @env = Puppet::Node::Environment.new("dev") @collection = Puppet::Resource::TypeCollection.new(@env) - @env.stubs(:perform_initial_import) + @env.stubs(:perform_initial_import).returns(Puppet::Parser::AST::Hostclass.new('')) Thread.current[:known_resource_types] = nil end it "should create a resource type collection if none exists" do Puppet::Resource::TypeCollection.expects(:new).with(@env).returns @collection @env.known_resource_types.should equal(@collection) end it "should reuse any existing resource type collection" do @env.known_resource_types.should equal(@env.known_resource_types) end it "should perform the initial import when creating a new collection" do @env = Puppet::Node::Environment.new("dev") - @env.expects(:perform_initial_import) + @env.expects(:perform_initial_import).returns(Puppet::Parser::AST::Hostclass.new('')) @env.known_resource_types end it "should return the same collection even if stale if it's the same thread" do Puppet::Resource::TypeCollection.stubs(:new).returns @collection @env.known_resource_types.stubs(:stale?).returns true @env.known_resource_types.should equal(@collection) end it "should return the current thread associated collection if there is one" do Thread.current[:known_resource_types] = @collection @env.known_resource_types.should equal(@collection) end it "should give to all threads the same collection if it didn't change" do Puppet::Resource::TypeCollection.expects(:new).with(@env).returns @collection @env.known_resource_types t = Thread.new { @env.known_resource_types.should equal(@collection) } t.join end it "should give to new threads a new collection if it isn't stale" do Puppet::Resource::TypeCollection.expects(:new).with(@env).returns @collection @env.known_resource_types.expects(:stale?).returns(true) Puppet::Resource::TypeCollection.expects(:new).returns @collection t = Thread.new { @env.known_resource_types.should equal(@collection) } t.join end end [:modulepath, :manifestdir].each do |setting| it "should validate the #{setting} directories" do path = %w{/one /two}.join(File::PATH_SEPARATOR) env = Puppet::Node::Environment.new("testing") env.stubs(:[]).with(setting).returns path env.expects(:validate_dirs).with(%w{/one /two}) env.send(setting) end it "should return the validated dirs for #{setting}" do path = %w{/one /two}.join(File::PATH_SEPARATOR) env = Puppet::Node::Environment.new("testing") env.stubs(:[]).with(setting).returns path env.stubs(:validate_dirs).returns %w{/one /two} env.send(setting).should == %w{/one /two} end end it "should prefix the value of the 'PUPPETLIB' environment variable to the module path if present" do Puppet::Util::Execution.withenv("PUPPETLIB" => %w{/l1 /l2}.join(File::PATH_SEPARATOR)) do env = Puppet::Node::Environment.new("testing") module_path = %w{/one /two}.join(File::PATH_SEPARATOR) env.expects(:validate_dirs).with(%w{/l1 /l2 /one /two}).returns %w{/l1 /l2 /one /two} env.expects(:[]).with(:modulepath).returns module_path env.modulepath.should == %w{/l1 /l2 /one /two} end end describe "when validating modulepath or manifestdir directories" do it "should not return non-directories" do env = Puppet::Node::Environment.new("testing") FileTest.expects(:directory?).with("/one").returns true FileTest.expects(:directory?).with("/two").returns false env.validate_dirs(%w{/one /two}).should == %w{/one} end it "should use the current working directory to fully-qualify unqualified paths" do FileTest.stubs(:directory?).returns true env = Puppet::Node::Environment.new("testing") two = File.join(Dir.getwd, "two") env.validate_dirs(%w{/one two}).should == ["/one", two] end end describe "when modeling a specific environment" do it "should have a method for returning the environment name" do Puppet::Node::Environment.new("testing").name.should == :testing end it "should provide an array-like accessor method for returning any environment-specific setting" do env = Puppet::Node::Environment.new("testing") env.should respond_to(:[]) end it "should ask the Puppet settings instance for the setting qualified with the environment name" do Puppet.settings.expects(:value).with("myvar", :testing).returns("myval") env = Puppet::Node::Environment.new("testing") env["myvar"].should == "myval" end it "should be able to return an individual module that exists in its module path" do env = Puppet::Node::Environment.new("testing") mod = mock 'module' Puppet::Module.expects(:new).with("one", env).returns mod mod.expects(:exist?).returns true env.module("one").should equal(mod) end it "should return nil if asked for a module that does not exist in its path" do env = Puppet::Node::Environment.new("testing") mod = mock 'module' Puppet::Module.expects(:new).with("one", env).returns mod mod.expects(:exist?).returns false env.module("one").should be_nil end it "should be able to return its modules" do Puppet::Node::Environment.new("testing").should respond_to(:modules) end describe ".modules" do it "should return a module named for every directory in each module path" do env = Puppet::Node::Environment.new("testing") env.expects(:modulepath).at_least_once.returns %w{/a /b} Dir.expects(:entries).with("/a").returns %w{foo bar} Dir.expects(:entries).with("/b").returns %w{bee baz} env.modules.collect{|mod| mod.name}.sort.should == %w{foo bar bee baz}.sort end it "should remove duplicates" do env = Puppet::Node::Environment.new("testing") env.expects(:modulepath).returns( %w{/a /b} ).at_least_once Dir.expects(:entries).with("/a").returns %w{foo} Dir.expects(:entries).with("/b").returns %w{foo} env.modules.collect{|mod| mod.name}.sort.should == %w{foo} end it "should ignore invalid modules" do env = Puppet::Node::Environment.new("testing") env.stubs(:modulepath).returns %w{/a} Dir.expects(:entries).with("/a").returns %w{foo bar} Puppet::Module.expects(:new).with { |name, env| name == "foo" }.returns mock("foomod", :name => "foo") Puppet::Module.expects(:new).with { |name, env| name == "bar" }.raises( Puppet::Module::InvalidName, "name is invalid" ) env.modules.collect{|mod| mod.name}.sort.should == %w{foo} end it "should create modules with the correct environment" do env = Puppet::Node::Environment.new("testing") env.expects(:modulepath).at_least_once.returns %w{/a} Dir.expects(:entries).with("/a").returns %w{foo} env.modules.each {|mod| mod.environment.should == env } end it "should cache the module list" do env = Puppet::Node::Environment.new("testing") env.expects(:modulepath).at_least_once.returns %w{/a} Dir.expects(:entries).once.with("/a").returns %w{foo} env.modules env.modules end end end describe Puppet::Node::Environment::Helper do before do @helper = Object.new @helper.extend(Puppet::Node::Environment::Helper) end it "should be able to set and retrieve the environment" do @helper.environment = :foo @helper.environment.name.should == :foo end it "should accept an environment directly" do env = Puppet::Node::Environment.new :foo @helper.environment = env @helper.environment.name.should == :foo end it "should accept an environment as a string" do env = Puppet::Node::Environment.new "foo" @helper.environment = env @helper.environment.name.should == :foo end end describe "when performing initial import" do before do @parser = stub 'parser', :file= => nil, :string => nil, :parse => nil Puppet::Parser::Parser.stubs(:new).returns @parser @env = Puppet::Node::Environment.new("env") end it "should create a new parser instance" do Puppet::Parser::Parser.expects(:new).returns @parser @env.instance_eval { perform_initial_import } end it "should set the parser's string to the 'code' setting and parse if code is available" do Puppet.settings[:code] = "my code" @parser.expects(:string=).with "my code" @parser.expects(:parse) @env.instance_eval { perform_initial_import } end it "should set the parser's file to the 'manifest' setting and parse if no code is available and the manifest is available" do File.stubs(:expand_path).with("/my/file").returns "/my/file" File.expects(:exist?).with("/my/file").returns true Puppet.settings[:manifest] = "/my/file" @parser.expects(:file=).with "/my/file" @parser.expects(:parse) @env.instance_eval { perform_initial_import } end it "should not attempt to load a manifest if none is present" do File.stubs(:expand_path).with("/my/file").returns "/my/file" File.expects(:exist?).with("/my/file").returns false Puppet.settings[:manifest] = "/my/file" @parser.expects(:file=).never @parser.expects(:parse).never @env.instance_eval { perform_initial_import } end it "should fail helpfully if there is an error importing" do File.stubs(:exist?).returns true @parser.expects(:parse).raises ArgumentError lambda { @env.instance_eval { perform_initial_import } }.should raise_error(Puppet::Error) end it "should not do anything if the ignore_import settings is set" do Puppet.settings[:ignoreimport] = true @parser.expects(:string=).never @parser.expects(:file=).never @parser.expects(:parse).never @env.instance_eval { perform_initial_import } end end end diff --git a/spec/unit/parser/ast/definition_spec.rb b/spec/unit/parser/ast/definition_spec.rb new file mode 100644 index 000000000..01ca068ad --- /dev/null +++ b/spec/unit/parser/ast/definition_spec.rb @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +describe Puppet::Parser::AST::Definition do + describe "when instantiated" do + it "should create a definition with the proper type, name, context, and module name" do + definition = Puppet::Parser::AST::Definition.new('foo', :line => 5) + instantiated_definitions = definition.instantiate('modname') + instantiated_definitions.length.should == 1 + instantiated_definitions[0].type.should == :definition + instantiated_definitions[0].name.should == 'foo' + instantiated_definitions[0].line.should == 5 + instantiated_definitions[0].module_name.should == 'modname' + end + end +end diff --git a/spec/unit/parser/ast/hostclass_spec.rb b/spec/unit/parser/ast/hostclass_spec.rb new file mode 100644 index 000000000..b22eba98b --- /dev/null +++ b/spec/unit/parser/ast/hostclass_spec.rb @@ -0,0 +1,73 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +describe Puppet::Parser::AST::Hostclass do + def ast + Puppet::Parser::AST + end + + def newarray(*elems) + ast::ASTArray.new({}).push(*elems) + end + + it "should make its name and context available through accessors" do + hostclass = ast::Hostclass.new('foo', :line => 5) + hostclass.name.should == 'foo' + hostclass.context.should == {:line => 5} + end + + it "should make its code available through an accessor" do + code = newarray + hostclass = ast::Hostclass.new('foo', :code => code) + hostclass.code.should be_equal(code) + end + + describe "when instantiated" do + it "should create a class with the proper type, code, name, context, and module name" do + code = newarray + hostclass = ast::Hostclass.new('foo', :code => code, :line => 5) + instantiated_class = hostclass.instantiate('modname')[0] + instantiated_class.type.should == :hostclass + instantiated_class.name.should == 'foo' + instantiated_class.code.should be_equal(code) + instantiated_class.line.should == 5 + instantiated_class.module_name.should == 'modname' + end + + it "should instantiate all nested classes, defines, and nodes with the same module name." do + nested_objects = newarray(ast::Hostclass.new('foo::child1'), + ast::Definition.new('foo::child2'), + ast::Definition.new('child3')) + hostclass = ast::Hostclass.new('foo', :code => nested_objects) + instantiated_classes = hostclass.instantiate('modname') + instantiated_classes.length.should == 4 + instantiated_classes[0].name.should == 'foo' + instantiated_classes[1].name.should == 'foo::child1' + instantiated_classes[2].name.should == 'foo::child2' + instantiated_classes[3].name.should == 'child3' + instantiated_classes.each { |cls| cls.module_name.should == 'modname' } + end + + it "should handle a nested class that contains its own nested classes." do + foo_bar_baz = ast::Hostclass.new('foo::bar::baz') + foo_bar = ast::Hostclass.new('foo::bar', :code => newarray(foo_bar_baz)) + foo = ast::Hostclass.new('foo', :code => newarray(foo_bar)) + instantiated_classes = foo.instantiate('') + instantiated_classes.length.should == 3 + instantiated_classes[0].name.should == 'foo' + instantiated_classes[1].name.should == 'foo::bar' + instantiated_classes[2].name.should == 'foo::bar::baz' + end + + it "should skip nested elements that are not classes, definitions, or nodes." do + func = ast::Function.new(:name => 'biz', :arguments => newarray(ast::Name.new(:value => 'baz'))) + foo = ast::Hostclass.new('foo', :code => newarray(func)) + instantiated_classes = foo.instantiate('') + instantiated_classes.length.should == 1 + instantiated_classes[0].should be_a(Puppet::Resource::Type) + instantiated_classes[0].name.should == 'foo' + end + end +end + diff --git a/spec/unit/parser/ast/node_spec.rb b/spec/unit/parser/ast/node_spec.rb new file mode 100644 index 000000000..409e877f9 --- /dev/null +++ b/spec/unit/parser/ast/node_spec.rb @@ -0,0 +1,30 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +describe Puppet::Parser::AST::Node do + describe "when instantiated" do + it "should make its names available through an accessor" do + node = Puppet::Parser::AST::Node.new(['foo', 'bar']) + node.names.should == ['foo', 'bar'] + end + + it "should create a node with the proper type, name, context, and module name" do + node = Puppet::Parser::AST::Node.new(['foo'], :line => 5) + instantiated_nodes = node.instantiate('modname') + instantiated_nodes.length.should == 1 + instantiated_nodes[0].type.should == :node + instantiated_nodes[0].name.should == 'foo' + instantiated_nodes[0].line.should == 5 + instantiated_nodes[0].module_name.should == 'modname' + end + + it "should handle multiple names" do + node = Puppet::Parser::AST::Node.new(['foo', 'bar']) + instantiated_nodes = node.instantiate('modname') + instantiated_nodes.length.should == 2 + instantiated_nodes[0].name.should == 'foo' + instantiated_nodes[1].name.should == 'bar' + end + end +end diff --git a/spec/unit/parser/ast/resource_spec.rb b/spec/unit/parser/ast/resource_spec.rb index 58ffae925..4e5549b96 100755 --- a/spec/unit/parser/ast/resource_spec.rb +++ b/spec/unit/parser/ast/resource_spec.rb @@ -1,120 +1,120 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../../spec_helper' describe Puppet::Parser::AST::Resource do ast = Puppet::Parser::AST before :each do @title = Puppet::Parser::AST::String.new(:value => "mytitle") @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("mynode")) @scope = Puppet::Parser::Scope.new(:compiler => @compiler) @scope.stubs(:resource).returns(stub_everything) @resource = ast::Resource.new(:title => @title, :type => "file", :parameters => ast::ASTArray.new(:children => []) ) @resource.stubs(:qualified_type).returns("Resource") end it "should evaluate all its parameters" do param = stub 'param' param.expects(:safeevaluate).with(@scope).returns Puppet::Parser::Resource::Param.new(:name => "myparam", :value => "myvalue", :source => stub("source")) @resource.stubs(:parameters).returns [param] @resource.evaluate(@scope) end it "should evaluate its title" do @resource.evaluate(@scope)[0].title.should == "mytitle" end it "should flatten the titles array" do titles = [] %w{one two}.each do |title| titles << Puppet::Parser::AST::String.new(:value => title) end array = Puppet::Parser::AST::ASTArray.new(:children => titles) @resource.title = array result = @resource.evaluate(@scope).collect { |r| r.title } result.should be_include("one") result.should be_include("two") end it "should create and return one resource objects per title" do titles = [] %w{one two}.each do |title| titles << Puppet::Parser::AST::String.new(:value => title) end array = Puppet::Parser::AST::ASTArray.new(:children => titles) @resource.title = array result = @resource.evaluate(@scope).collect { |r| r.title } result.should be_include("one") result.should be_include("two") end it "should handover resources to the compiler" do titles = [] %w{one two}.each do |title| titles << Puppet::Parser::AST::String.new(:value => title) end array = Puppet::Parser::AST::ASTArray.new(:children => titles) @resource.title = array result = @resource.evaluate(@scope) result.each do |res| @compiler.catalog.resource(res.ref).should be_instance_of(Puppet::Parser::Resource) end end it "should generate virtual resources if it is virtual" do @resource.virtual = true result = @resource.evaluate(@scope) result[0].should be_virtual end it "should generate virtual and exported resources if it is exported" do @resource.exported = true result = @resource.evaluate(@scope) result[0].should be_virtual result[0].should be_exported end # Related to #806, make sure resources always look up the full path to the resource. describe "when generating qualified resources" do before do @scope = Puppet::Parser::Scope.new :compiler => Puppet::Parser::Compiler.new(Puppet::Node.new("mynode")) @parser = Puppet::Parser::Parser.new(Puppet::Node::Environment.new) - @parser.newdefine "one" - @parser.newdefine "one::two" - @parser.newdefine "three" + ["one", "one::two", "three"].each do |name| + @parser.environment.known_resource_types.add(Puppet::Resource::Type.new(:definition, name, {})) + end @twoscope = @scope.newscope(:namespace => "one") @twoscope.resource = @scope.resource end def resource(type, params = nil) params ||= Puppet::Parser::AST::ASTArray.new(:children => []) Puppet::Parser::AST::Resource.new(:type => type, :title => Puppet::Parser::AST::String.new(:value => "myresource"), :parameters => params) end it "should be able to generate resources with fully qualified type information" do resource("two").evaluate(@twoscope)[0].type.should == "One::Two" end it "should be able to generate resources with unqualified type information" do resource("one").evaluate(@twoscope)[0].type.should == "One" end it "should correctly generate resources that can look up builtin types" do resource("file").evaluate(@twoscope)[0].type.should == "File" end it "should fail for resource types that do not exist" do lambda { resource("nosuchtype").evaluate(@twoscope) }.should raise_error(Puppet::ParseError) end end end diff --git a/spec/unit/parser/parser_spec.rb b/spec/unit/parser/parser_spec.rb index 0657ab37a..0a61e73de 100755 --- a/spec/unit/parser/parser_spec.rb +++ b/spec/unit/parser/parser_spec.rb @@ -1,412 +1,422 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../spec_helper' describe Puppet::Parser do ast = 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) 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") 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 describe "in ruby" do it "should use the ruby interpreter to load the file" do @parser.file = "/my/file.rb" @parser.expects(:require).with "/my/file.rb" @parser.parse_ruby_file end end end describe "when parsing append operator" do it "should not raise syntax errors" do lambda { @parser.parse("$var += something") }.should_not raise_error end it "shouldraise syntax error on incomplete syntax " do lambda { @parser.parse("$var += ") }.should raise_error end - it "should call ast::VarDef with append=true" do - ast::VarDef.expects(:new).with { |h| h[:append] == true } - @parser.parse("$var += 2") + 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 - ast::VarDef.expects(:new).with { |h| h[:append] == true } - @parser.parse("$var += ['test']") + vardef = @parser.parse("$var += ['test']").code[0] + vardef.should be_a(Puppet::Parser::AST::VarDef) + vardef.append.should == true end end describe "when parsing 'if'" do it "not, it should create the correct ast objects" do ast::Not.expects(:new).with { |h| h[:value].is_a?(ast::Boolean) } @parser.parse("if ! true { $var = 1 }") end it "boolean operation, it should create the correct ast objects" do ast::BooleanOperator.expects(:new).with { |h| h[:rval].is_a?(ast::Boolean) and h[:lval].is_a?(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 ast::ComparisonOperator.expects(:new).with { |h| h[:lval].is_a?(ast::Name) and h[:rval].is_a?(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' ast::ComparisonOperator.expects(:new).with { |h| h[:rval].is_a?(ast::Name) and h[:lval].is_a?(ast::Name) and h[:operator]==">" }.returns(aststub) ast::ComparisonOperator.expects(:new).with { |h| h[:rval].is_a?(ast::Name) and h[:lval].is_a?(ast::Name) and h[:operator]=="==" }.returns(aststub) 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 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 end it "should not raise syntax errors with multiple references" do lambda { @parser.parse('exec { test: param => File["a","b"] }') }.should_not raise_error end it "should create an ast::ResourceReference" do ast::Resource.stubs(:new) ast::ResourceReference.expects(:new).with { |arg| arg[:line]==1 and arg[:type]=="File" and arg[:title].is_a?(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 end it "should not raise syntax errors with multiple overrides" do lambda { @parser.parse('Resource["title1","title2"] { param => value }') }.should_not raise_error end it "should create an ast::ResourceOverride" do - ast::ResourceOverride.expects(:new).with { |arg| - arg[:line]==1 and arg[:object].is_a?(ast::ResourceReference) and arg[:parameters].is_a?(ast::ResourceParam) - } - @parser.parse('Resource["title1","title2"] { param => value }') + #ast::ResourceOverride.expects(:new).with { |arg| + # arg[:line]==1 and arg[:object].is_a?(ast::ResourceReference) and arg[:parameters].is_a?(ast::ResourceParam) + #} + ro = @parser.parse('Resource["title1","title2"] { param => value }').code[0] + ro.should be_a(ast::ResourceOverride) + ro.line.should == 1 + ro.object.should be_a(ast::ResourceReference) + ro.parameters[0].should be_a(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 end it "should not raise errors with empty else" do lambda { @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 end it "should create a nop node for empty branch" do ast::Nop.expects(:new) @parser.parse("if true { }") end it "should create a nop node for empty else branch" do 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 ast = @parser.parse(<<-PP) 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 end it "should not raise errors with rvalue function with no args" do lambda { @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 end it "should not raise errors with multiple arguments" do lambda { @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 end end describe "when parsing arrays with trailing comma" do it "should not raise errors with a trailing comma" do lambda { @parser.parse("$a = [1,2,]") }.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 = stub 'class', :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" } @parser.expects(:ast_context).returns :file => "/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(true).returns({}) @parser.ast(@class, :file => "/bar") end end - describe "when creating a node" do - before :each do - @lexer = stub 'lexer' - @lexer.stubs(:getcomment) - @parser.stubs(:lexer).returns(@lexer) - @node = stub_everything 'node' - @parser.stubs(:ast_context).returns({}) - @parser.stubs(:node).returns(nil) - - @nodename = stub 'nodename', :is_a? => false, :value => "foo" - @nodename.stubs(:is_a?).with(Puppet::Parser::AST::HostName).returns(true) - end - - it "should return an array of nodes" do - @parser.newnode(@nodename).should be_instance_of(Array) - 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 create new classes" do - @parser.parse("class foobar {}") - @krt.hostclass("foobar").should be_instance_of(Puppet::Resource::Type) + 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 {}") - @krt.hostclass("foobar").parent.should == "yayness" + @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 - @parser.parse("class foobar inherits yayness {}\nclass boo inherits bar {}") - @krt.hostclass("foobar").parent.should == "yayness" - @krt.hostclass("boo").parent.should == "bar" + 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 }") - @krt.hostclass("foobar").code.should_not be_nil + @parser.parse("class foobar { $var = val }").code[0].code.should_not be_nil end it "should define parameters when provided" do - @parser.parse("class foobar($biz,$baz) {}") - @krt.hostclass("foobar").arguments.should == {"biz" => nil, "baz" => nil} + 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 end it "should correctly mark exported resources as exported" do - @parser.parse("@@file { '/file': }") - @krt.hostclass("").code[0].exported.should be_true + @parser.parse("@@file { '/file': }").code[0][0].exported.should be_true end it "should correctly mark virtual resources as virtual" do - @parser.parse("@file { '/file': }") - @krt.hostclass("").code[0].virtual.should be_true + @parser.parse("@file { '/file': }").code[0][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 end diff --git a/spec/unit/parser/scope_spec.rb b/spec/unit/parser/scope_spec.rb index 9895f446b..2e390a53b 100755 --- a/spec/unit/parser/scope_spec.rb +++ b/spec/unit/parser/scope_spec.rb @@ -1,629 +1,628 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../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) - @topscope.source.module_name = "foo" + @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 = stub 'environment' compiler = stub 'compiler', :environment => env scope = Puppet::Parser::Scope.new :compiler => compiler scope.environment.should equal(env) 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 initializing" do it "should extend itself with its environment's Functions module as well as the default" do env = Puppet::Node::Environment.new("myenv") compiler = stub 'compiler', :environment => env mod = Module.new root_mod = Module.new Puppet::Parser::Functions.expects(:environment_module).with(Puppet::Node::Environment.root).returns root_mod Puppet::Parser::Functions.expects(:environment_module).with(env).returns mod Puppet::Parser::Scope.new(:compiler => compiler).singleton_class.ancestors.should be_include(mod) end it "should extend itself with the default Functions module if it has no environment" do mod = Module.new Puppet::Parser::Functions.expects(:environment_module).with(Puppet::Node::Environment.root).returns(mod) Puppet::Parser::Functions.expects(:environment_module).with(nil).returns mod Puppet::Parser::Scope.new.singleton_class.ancestors.should be_include(mod) end end describe "when looking up a variable" do it "should default to an empty string" do @scope.lookupvar("var").should == "" end it "should return an string when asked for a string" do @scope.lookupvar("var", true).should == "" end it "should return ':undefined' for unset variables when asked not to return a string" do @scope.lookupvar("var", false).should == :undefined end it "should be able to look up values" do @scope.setvar("var", "yep") @scope.lookupvar("var").should == "yep" end it "should be able to look up hashes" do @scope.setvar("var", {"a" => "b"}) @scope.lookupvar("var").should == {"a" => "b"} end it "should be able to look up variables in parent scopes" do @topscope.setvar("var", "parentval") @scope.lookupvar("var").should == "parentval" end it "should prefer its own values to parent values" do @topscope.setvar("var", "parentval") @scope.setvar("var", "childval") @scope.lookupvar("var").should == "childval" 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) Puppet::Parser::Resource.new("class", name, :scope => @scope, :source => mock('source')).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.setvar("othervar", "otherval") @scope.lookupvar("::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.setvar("var", "otherval") @scope.lookupvar("::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.setvar("var", "otherval") @scope.lookupvar("other::deep::klass::var").should == "otherval" end it "should return an empty string for qualified variables that cannot be found in other classes" do other_scope = create_class_scope("other::deep::klass") @scope.lookupvar("other::deep::klass::var").should == "" end it "should warn and return an empty string for qualified variables whose classes have not been evaluated" do klass = newclass("other::deep::klass") @scope.expects(:warning) @scope.lookupvar("other::deep::klass::var").should == "" end it "should warn and return an empty string for qualified variables whose classes do not exist" do @scope.expects(:warning) @scope.lookupvar("other::deep::klass::var").should == "" end it "should return ':undefined' when asked for a non-string qualified variable from a class that does not exist" do @scope.stubs(:warning) @scope.lookupvar("other::deep::klass::var", false).should == :undefined end it "should return ':undefined' when asked for a non-string qualified variable from a class that has not been evaluated" do @scope.stubs(:warning) klass = newclass("other::deep::klass") @scope.lookupvar("other::deep::klass::var", false).should == :undefined end end end describe "when setvar is called with append=true" do it "should raise error if the variable is already defined in this scope" do @scope.setvar("var","1", :append => false) lambda { @scope.setvar("var","1", :append => true) }.should raise_error(Puppet::ParseError) end it "should lookup current variable value" do @scope.expects(:lookupvar).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.lookupvar("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.lookupvar("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.lookupvar("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.lookupvar("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.lookupvar("1", false).should == :undefined end it "should not remove classic variables when unset_ephemeral_var is called" do @scope.setvar("myvar", :value1) @scope.setvar("1", :value2, :ephemeral => true) @scope.stubs(:parent).returns(nil) @scope.unset_ephemeral_var @scope.lookupvar("myvar", false).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.lookupvar("0", false).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.lookupvar("1", false).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.lookupvar("1", false).should == :undefined 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.lookupvar("1", false).should == :value2 end end end end describe "when interpolating string" do (0..9).each do |n| it "should allow $#{n} to match" do @scope.setvar(n.to_s, "value", :ephemeral => true) @scope.strinterp("$#{n}").should == "value" end end (0..9).each do |n| it "should not allow $#{n} to match if not ephemeral" do @scope.setvar(n.to_s, "value", :ephemeral => false) @scope.strinterp("$#{n}").should_not == "value" end end it "should not allow $10 to match" do @scope.setvar("10", "value", :ephemeral => true) @scope.strinterp('==$10==').should_not == "==value==" end it "should not allow ${10} to match" do @scope.setvar("10", "value", :ephemeral => true) @scope.strinterp('==${10}==').should == "==value==" end describe "with qualified variables" do before do @scopes = {} klass = @scope.known_resource_types.add(Puppet::Resource::Type.new(:hostclass, "")) Puppet::Parser::Resource.new("class", :main, :scope => @scope, :source => mock('source')).evaluate @scopes[""] = @scope.class_scope(klass) @scopes[""].setvar("test", "value") %w{one one::two one::two::three}.each do |name| klass = @scope.known_resource_types.add(Puppet::Resource::Type.new(:hostclass, name)) Puppet::Parser::Resource.new("class", name, :scope => @scope, :source => mock('source')).evaluate @scopes[name] = @scope.class_scope(klass) @scopes[name].setvar("test", "value-#{name.sub(/.+::/,'')}") end end { "===${one::two::three::test}===" => "===value-three===", "===$one::two::three::test===" => "===value-three===", "===${one::two::test}===" => "===value-two===", "===$one::two::test===" => "===value-two===", "===${one::test}===" => "===value-one===", "===$one::test===" => "===value-one===", "===${::test}===" => "===value===", "===$::test===" => "===value===" }.each do |input, output| it "should parse '#{input}' correctly" do @scope.strinterp(input).should == output end end end tests = { "===${test}===" => "===value===", "===${test} ${test} ${test}===" => "===value value value===", "===$test ${test} $test===" => "===value value value===", "===\\$test===" => "===$test===", '===\\$test string===' => "===$test string===", '===$test string===' => "===value string===", '===a testing $===' => "===a testing $===", '===a testing \$===' => "===a testing $===", "===an escaped \\\n carriage return===" => "===an escaped carriage return===", '\$' => "$", '\s' => "\s", '\t' => "\t", '\n' => "\n" } tests.each do |input, output| it "should parse '#{input}' correctly" do @scope.setvar("test", "value") @scope.strinterp(input).should == output end end # #523 %w{d f h l w z}.each do |l| it "should parse '#{l}' when escaped" do string = "\\#{l}" @scope.strinterp(string).should == string end end end def test_strinterp # Make and evaluate our classes so the qualified lookups work parser = mkparser klass = parser.newclass("") scope = mkscope(:parser => parser) Puppet::Parser::Resource.new(:type => "class", :title => :main, :scope => scope, :source => mock('source')).evaluate assert_nothing_raised { scope.setvar("test","value") } scopes = {"" => scope} %w{one one::two one::two::three}.each do |name| klass = parser.newclass(name) Puppet::Parser::Resource.new(:type => "class", :title => name, :scope => scope, :source => mock('source')).evaluate scopes[name] = scope.class_scope(klass) scopes[name].setvar("test", "value-#{name.sub(/.+::/,'')}") end assert_equal("value", scope.lookupvar("::test"), "did not look up qualified value correctly") tests.each do |input, output| assert_nothing_raised("Failed to scan #{input.inspect}") do assert_equal(output, scope.strinterp(input), 'did not parserret %s correctly' % input.inspect) end end logs = [] Puppet::Util::Log.close Puppet::Util::Log.newdestination(logs) # #523 %w{d f h l w z}.each do |l| string = "\\#{l}" assert_nothing_raised do assert_equal( string, scope.strinterp(string), 'did not parserret %s correctly' % string) end assert( logs.detect { |m| m.message =~ /Unrecognised escape/ }, "Did not get warning about escape sequence with #{string}") logs.clear end end 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.setvar("foo", "bar") @scope.unsetvar("foo") @scope.lookupvar("foo").should == "" end it "should be able to unset ephemeral variables" do @scope.setvar("0", "bar", :ephemeral => true) @scope.unsetvar("0") @scope.lookupvar("0").should == "" 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.lookupvar("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.setdefaults(: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.setdefaults(:mytype, param) lambda { @scope.setdefaults(: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.setdefaults(:mytype, param1) param2 = Puppet::Parser::Resource::Param.new(:name => :other, :value => "myvalue", :source => stub("source")) @scope.setdefaults(: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.setdefaults(:mytype, param1) child_scope = @scope.newscope param2 = Puppet::Parser::Resource::Param.new(:name => :other, :value => "myvalue", :source => stub("source")) child_scope.setdefaults(:mytype, param2) child_scope.lookupdefaults(:mytype).should == {:myparam => param1, :other => param2} end end end diff --git a/spec/unit/parser/type_loader_spec.rb b/spec/unit/parser/type_loader_spec.rb index b7e174753..b06251681 100644 --- a/spec/unit/parser/type_loader_spec.rb +++ b/spec/unit/parser/type_loader_spec.rb @@ -1,154 +1,146 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/parser/type_loader' require 'puppet_spec/files' describe Puppet::Parser::TypeLoader do include PuppetSpec::Files before do @loader = Puppet::Parser::TypeLoader.new(:myenv) end it "should support an environment" do loader = Puppet::Parser::TypeLoader.new(:myenv) loader.environment.name.should == :myenv end it "should include the Environment Helper" do @loader.class.ancestors.should be_include(Puppet::Node::Environment::Helper) end it "should delegate its known resource types to its environment" do @loader.known_resource_types.should be_instance_of(Puppet::Resource::TypeCollection) end describe "when loading names from namespaces" do it "should do nothing if the name to import is an empty string" do @loader.expects(:name2files).never - @loader.try_load_fqname("") { |filename, modname| raise :should_not_occur }.should be_nil + @loader.try_load_fqname(:hostclass, "") { |filename, modname| raise :should_not_occur }.should be_nil end it "should attempt to import each generated name" do - @loader.expects(:import).with("foo/bar",nil) - @loader.expects(:import).with("foo",nil) - @loader.try_load_fqname("foo::bar") { |f| false } - end - - it "should yield after each import" do - yielded = [] - @loader.expects(:import).with("foo/bar",nil) - @loader.expects(:import).with("foo",nil) - @loader.try_load_fqname("foo::bar") { |filename, modname| yielded << [filename, modname]; false } - yielded.should == [["foo/bar", nil], ["foo", nil]] + @loader.expects(:import).with("foo/bar",nil).returns([]) + @loader.expects(:import).with("foo",nil).returns([]) + @loader.try_load_fqname(:hostclass, "foo::bar") { |f| false } end it "should know when a given name has been loaded" do - @loader.expects(:import).with("file",nil) - @loader.try_load_fqname("file") { |f| true } + @loader.expects(:import).with("file",nil).returns([]) + @loader.try_load_fqname(:hostclass, "file") { |f| true } @loader.should be_loaded("file") end end describe "when importing" do before do Puppet::Parser::Files.stubs(:find_manifests).returns ["modname", %w{file}] - @loader.stubs(:parse_file) + @loader.stubs(:parse_file).returns(Puppet::Parser::AST::Hostclass.new('')) end it "should return immediately when imports are being ignored" do Puppet::Parser::Files.expects(:find_manifests).never Puppet[:ignoreimport] = true @loader.import("foo").should be_nil end it "should find all manifests matching the file or pattern" do Puppet::Parser::Files.expects(:find_manifests).with { |pat, opts| pat == "myfile" }.returns ["modname", %w{one}] @loader.import("myfile") end it "should use the directory of the current file if one is set" do Puppet::Parser::Files.expects(:find_manifests).with { |pat, opts| opts[:cwd] == "/current" }.returns ["modname", %w{one}] @loader.import("myfile", "/current/file") end it "should pass the environment when looking for files" do Puppet::Parser::Files.expects(:find_manifests).with { |pat, opts| opts[:environment] == @loader.environment }.returns ["modname", %w{one}] @loader.import("myfile") end it "should fail if no files are found" do Puppet::Parser::Files.expects(:find_manifests).returns [nil, []] lambda { @loader.import("myfile") }.should raise_error(Puppet::ImportError) end it "should parse each found file" do Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{/one}] - @loader.expects(:parse_file).with("/one") + @loader.expects(:parse_file).with("/one").returns(Puppet::Parser::AST::Hostclass.new('')) @loader.import("myfile") end it "should make each file qualified before attempting to parse it" do Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{one}] - @loader.expects(:parse_file).with("/current/one") + @loader.expects(:parse_file).with("/current/one").returns(Puppet::Parser::AST::Hostclass.new('')) @loader.import("myfile", "/current/file") end it "should know when a given file has been imported" do Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{/one}] @loader.import("myfile") @loader.should be_imported("/one") end it "should not attempt to import files that have already been imported" do Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{/one}] - @loader.expects(:parse_file).once + @loader.expects(:parse_file).once.returns(Puppet::Parser::AST::Hostclass.new('')) @loader.import("myfile") # This will fail if it tries to reimport the file. @loader.import("myfile") end end describe "when parsing a file" do before do @parser = Puppet::Parser::Parser.new(@loader.environment) - @parser.stubs(:parse) + @parser.stubs(:parse).returns(Puppet::Parser::AST::Hostclass.new('')) @parser.stubs(:file=) Puppet::Parser::Parser.stubs(:new).with(@loader.environment).returns @parser end it "should create a new parser instance for each file using the current environment" do Puppet::Parser::Parser.expects(:new).with(@loader.environment).returns @parser @loader.parse_file("/my/file") end it "should assign the parser its file and parse" do @parser.expects(:file=).with("/my/file") - @parser.expects(:parse) + @parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new('')) @loader.parse_file("/my/file") end end it "should be able to add classes to the current resource type collection" do file = tmpfile("simple_file") File.open(file, "w") { |f| f.puts "class foo {}" } @loader.import(file) @loader.known_resource_types.hostclass("foo").should be_instance_of(Puppet::Resource::Type) end describe "when deciding where to look for files" do { 'foo' => ['foo'], 'foo::bar' => ['foo/bar', 'foo'], 'foo::bar::baz' => ['foo/bar/baz', 'foo/bar', 'foo'] }.each do |fqname, expected_paths| it "should look for #{fqname.inspect} in #{expected_paths.inspect}" do @loader.instance_eval { name2files(fqname) }.should == expected_paths end end end end diff --git a/spec/unit/resource/type_collection_spec.rb b/spec/unit/resource/type_collection_spec.rb index fc53e35b1..b8da3cf58 100644 --- a/spec/unit/resource/type_collection_spec.rb +++ b/spec/unit/resource/type_collection_spec.rb @@ -1,447 +1,447 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/resource/type_collection' require 'puppet/resource/type' describe Puppet::Resource::TypeCollection do before do @instance = Puppet::Resource::Type.new(:hostclass, "foo") @code = Puppet::Resource::TypeCollection.new("env") end it "should require an environment at initialization" do env = Puppet::Node::Environment.new("testing") Puppet::Resource::TypeCollection.new(env).environment.should equal(env) end it "should convert the environment into an environment instance if a string is provided" do env = Puppet::Node::Environment.new("testing") Puppet::Resource::TypeCollection.new("testing").environment.should equal(env) end it "should create a 'loader' at initialization" do Puppet::Resource::TypeCollection.new("testing").loader.should be_instance_of(Puppet::Parser::TypeLoader) end it "should be able to add a resource type" do Puppet::Resource::TypeCollection.new("env").should respond_to(:add) end it "should consider '<<' to be an alias to 'add' but should return self" do loader = Puppet::Resource::TypeCollection.new("env") loader.expects(:add).with "foo" loader.expects(:add).with "bar" loader << "foo" << "bar" end it "should set itself as the code collection for added resource types" do loader = Puppet::Resource::TypeCollection.new("env") node = Puppet::Resource::Type.new(:node, "foo") @code.add(node) @code.node("foo").should equal(node) node.resource_type_collection.should equal(@code) end it "should store node resource types as nodes" do node = Puppet::Resource::Type.new(:node, "foo") @code.add(node) @code.node("foo").should equal(node) end it "should store hostclasses as hostclasses" do klass = Puppet::Resource::Type.new(:hostclass, "foo") @code.add(klass) @code.hostclass("foo").should equal(klass) end it "should store definitions as definitions" do define = Puppet::Resource::Type.new(:definition, "foo") @code.add(define) @code.definition("foo").should equal(define) end it "should merge new classes with existing classes of the same name" do loader = Puppet::Resource::TypeCollection.new("env") first = Puppet::Resource::Type.new(:hostclass, "foo") second = Puppet::Resource::Type.new(:hostclass, "foo") loader.add first first.expects(:merge).with(second) loader.add(second) end it "should remove all nodes, classes, and definitions when cleared" do loader = Puppet::Resource::TypeCollection.new("env") loader.add Puppet::Resource::Type.new(:hostclass, "class") loader.add Puppet::Resource::Type.new(:definition, "define") loader.add Puppet::Resource::Type.new(:node, "node") loader.clear loader.hostclass("class").should be_nil loader.definition("define").should be_nil loader.node("node").should be_nil end describe "when resolving namespaces" do [ ['', '::foo', ['foo']], ['a', '::foo', ['foo']], ['a::b', '::foo', ['foo']], [['a::b'], '::foo', ['foo']], [['a::b', 'c'], '::foo', ['foo']], [['A::B', 'C'], '::Foo', ['foo']], ['', '', ['']], ['a', '', ['']], ['a::b', '', ['']], [['a::b'], '', ['']], [['a::b', 'c'], '', ['']], [['A::B', 'C'], '', ['']], ['', 'foo', ['foo']], ['a', 'foo', ['a::foo', 'foo']], ['a::b', 'foo', ['a::b::foo', 'a::foo', 'foo']], ['A::B', 'Foo', ['a::b::foo', 'a::foo', 'foo']], [['a::b'], 'foo', ['a::b::foo', 'a::foo', 'foo']], [['a', 'b'], 'foo', ['a::foo', 'foo', 'b::foo']], [['a::b', 'c::d'], 'foo', ['a::b::foo', 'a::foo', 'foo', 'c::d::foo', 'c::foo']], [['a::b', 'a::c'], 'foo', ['a::b::foo', 'a::foo', 'foo', 'a::c::foo']], ].each do |namespaces, name, expected_result| it "should resolve #{name.inspect} in namespaces #{namespaces.inspect} correctly" do @code.instance_eval { resolve_namespaces(namespaces, name) }.should == expected_result end end end describe "when looking up names" do before do @type = Puppet::Resource::Type.new(:hostclass, "ns::klass") end it "should support looking up with multiple namespaces" do @code.add @type @code.find_hostclass(%w{boo baz ns}, "klass").should equal(@type) end it "should not attempt to import anything when the type is already defined" do @code.add @type @code.loader.expects(:import).never @code.find_hostclass(%w{ns}, "klass").should equal(@type) end describe "that need to be loaded" do it "should use the loader to load the files" do - @code.loader.expects(:try_load_fqname).with("ns::klass") - @code.loader.expects(:try_load_fqname).with("klass") + @code.loader.expects(:try_load_fqname).with(:hostclass, "ns::klass") + @code.loader.expects(:try_load_fqname).with(:hostclass, "klass") @code.find_hostclass(["ns"], "klass") end it "should downcase the name and downcase and array-fy the namespaces before passing to the loader" do - @code.loader.expects(:try_load_fqname).with("ns::klass") - @code.loader.expects(:try_load_fqname).with("klass") + @code.loader.expects(:try_load_fqname).with(:hostclass, "ns::klass") + @code.loader.expects(:try_load_fqname).with(:hostclass, "klass") @code.find_hostclass("Ns", "Klass") end - it "should attempt to find the type when the loader yields" do - @code.loader.expects(:try_load_fqname).yields - @code.expects(:hostclass).with("ns::klass").times(2).returns(false).then.returns(true) - @code.find_hostclass("ns", "klass") + it "should use the class returned by the loader" do + @code.loader.expects(:try_load_fqname).returns(:klass) + @code.expects(:hostclass).with("ns::klass").returns(false) + @code.find_hostclass("ns", "klass").should == :klass end it "should return nil if the name isn't found" do @code.stubs(:try_load_fqname).returns(nil) @code.find_hostclass("Ns", "Klass").should be_nil end it "already-loaded names at broader scopes should not shadow autoloaded names" do @code.add Puppet::Resource::Type.new(:hostclass, "bar") - @code.loader.expects(:try_load_fqname).with("foo::bar") - @code.find_hostclass("foo", "bar") + @code.loader.expects(:try_load_fqname).with(:hostclass, "foo::bar").returns(:foobar) + @code.find_hostclass("foo", "bar").should == :foobar end end end %w{hostclass node definition}.each do |data| before do @instance = Puppet::Resource::Type.new(data, "foo") end it "should have a method for adding a #{data}" do Puppet::Resource::TypeCollection.new("env").should respond_to("add_#{data}") end it "should use the name of the instance to add it" do loader = Puppet::Resource::TypeCollection.new("env") loader.send("add_#{data}", @instance) loader.send(data, @instance.name).should equal(@instance) end unless data == "hostclass" it "should fail to add a #{data} when one already exists" do loader = Puppet::Resource::TypeCollection.new("env") loader.add @instance lambda { loader.add(@instance) }.should raise_error(Puppet::ParseError) end end it "should return the added #{data}" do loader = Puppet::Resource::TypeCollection.new("env") loader.add(@instance).should equal(@instance) end it "should be able to retrieve #{data} by name" do loader = Puppet::Resource::TypeCollection.new("env") instance = Puppet::Resource::Type.new(data, "bar") loader.add instance loader.send(data, "bar").should equal(instance) end it "should retrieve #{data} insensitive to case" do loader = Puppet::Resource::TypeCollection.new("env") instance = Puppet::Resource::Type.new(data, "Bar") loader.add instance loader.send(data, "bAr").should equal(instance) end it "should return nil when asked for a #{data} that has not been added" do Puppet::Resource::TypeCollection.new("env").send(data, "foo").should be_nil end it "should be able to retrieve all #{data}s" do plurals = { "hostclass" => "hostclasses", "node" => "nodes", "definition" => "definitions" } loader = Puppet::Resource::TypeCollection.new("env") instance = Puppet::Resource::Type.new(data, "foo") loader.add instance loader.send(plurals[data]).should == { "foo" => instance } end end describe "when finding a qualified instance" do it "should return any found instance if the instance name is fully qualified" do loader = Puppet::Resource::TypeCollection.new("env") instance = Puppet::Resource::Type.new(:hostclass, "foo::bar") loader.add instance loader.find_hostclass("namespace", "::foo::bar").should equal(instance) end it "should return nil if the instance name is fully qualified and no such instance exists" do loader = Puppet::Resource::TypeCollection.new("env") loader.find_hostclass("namespace", "::foo::bar").should be_nil end it "should be able to find classes in the base namespace" do loader = Puppet::Resource::TypeCollection.new("env") instance = Puppet::Resource::Type.new(:hostclass, "foo") loader.add instance loader.find_hostclass("", "foo").should equal(instance) end it "should return the partially qualified object if it exists in a provided namespace" do loader = Puppet::Resource::TypeCollection.new("env") instance = Puppet::Resource::Type.new(:hostclass, "foo::bar::baz") loader.add instance loader.find_hostclass("foo", "bar::baz").should equal(instance) end it "should be able to find partially qualified objects in any of the provided namespaces" do loader = Puppet::Resource::TypeCollection.new("env") instance = Puppet::Resource::Type.new(:hostclass, "foo::bar::baz") loader.add instance loader.find_hostclass(["nons", "foo", "otherns"], "bar::baz").should equal(instance) end it "should return the unqualified object if it exists in a provided namespace" do loader = Puppet::Resource::TypeCollection.new("env") instance = Puppet::Resource::Type.new(:hostclass, "foo::bar") loader.add instance loader.find_hostclass("foo", "bar").should equal(instance) end it "should return the unqualified object if it exists in the parent namespace" do loader = Puppet::Resource::TypeCollection.new("env") instance = Puppet::Resource::Type.new(:hostclass, "foo::bar") loader.add instance loader.find_hostclass("foo::bar::baz", "bar").should equal(instance) end it "should should return the partially qualified object if it exists in the parent namespace" do loader = Puppet::Resource::TypeCollection.new("env") instance = Puppet::Resource::Type.new(:hostclass, "foo::bar::baz") loader.add instance loader.find_hostclass("foo::bar", "bar::baz").should equal(instance) end it "should return the qualified object if it exists in the root namespace" do loader = Puppet::Resource::TypeCollection.new("env") instance = Puppet::Resource::Type.new(:hostclass, "foo::bar::baz") loader.add instance loader.find_hostclass("foo::bar", "foo::bar::baz").should equal(instance) end it "should return nil if the object cannot be found" do loader = Puppet::Resource::TypeCollection.new("env") instance = Puppet::Resource::Type.new(:hostclass, "foo::bar::baz") loader.add instance loader.find_hostclass("foo::bar", "eh").should be_nil end describe "when topscope has a class that has the same name as a local class" do before do @loader = Puppet::Resource::TypeCollection.new("env") [ "foo::bar", "bar" ].each do |name| @loader.add Puppet::Resource::Type.new(:hostclass, name) end end it "should favor the local class, if the name is unqualified" do @loader.find_hostclass("foo", "bar").name.should == 'foo::bar' end it "should only look in the topclass, if the name is qualified" do @loader.find_hostclass("foo", "::bar").name.should == 'bar' end end it "should not look in the local scope for classes when the name is qualified" do @loader = Puppet::Resource::TypeCollection.new("env") @loader.add Puppet::Resource::Type.new(:hostclass, "foo::bar") @loader.find_hostclass("foo", "::bar").should == nil end end it "should be able to find nodes" do node = Puppet::Resource::Type.new(:node, "bar") loader = Puppet::Resource::TypeCollection.new("env") loader.add(node) loader.find_node(stub("ignored"), "bar").should == node end it "should use the 'find_or_load' method to find hostclasses" do loader = Puppet::Resource::TypeCollection.new("env") loader.expects(:find_or_load).with("foo", "bar", :hostclass) loader.find_hostclass("foo", "bar") end it "should use the 'find_or_load' method to find definitions" do loader = Puppet::Resource::TypeCollection.new("env") loader.expects(:find_or_load).with("foo", "bar", :definition) loader.find_definition("foo", "bar") end it "should indicate whether any nodes are defined" do loader = Puppet::Resource::TypeCollection.new("env") loader.add_node(Puppet::Resource::Type.new(:node, "foo")) loader.should be_nodes end it "should indicate whether no nodes are defined" do Puppet::Resource::TypeCollection.new("env").should_not be_nodes end describe "when finding nodes" do before :each do @loader = Puppet::Resource::TypeCollection.new("env") end it "should return any node whose name exactly matches the provided node name" do node = Puppet::Resource::Type.new(:node, "foo") @loader << node @loader.node("foo").should equal(node) end it "should return the first regex node whose regex matches the provided node name" do node1 = Puppet::Resource::Type.new(:node, /\w/) node2 = Puppet::Resource::Type.new(:node, /\d/) @loader << node1 << node2 @loader.node("foo10").should equal(node1) end it "should preferentially return a node whose name is string-equal over returning a node whose regex matches a provided name" do node1 = Puppet::Resource::Type.new(:node, /\w/) node2 = Puppet::Resource::Type.new(:node, "foo") @loader << node1 << node2 @loader.node("foo").should equal(node2) end end describe "when managing files" do before do @loader = Puppet::Resource::TypeCollection.new("env") Puppet::Util::LoadedFile.stubs(:new).returns stub("watched_file") end it "should have a method for specifying a file should be watched" do @loader.should respond_to(:watch_file) end it "should have a method for determining if a file is being watched" do @loader.watch_file("/foo/bar") @loader.should be_watching_file("/foo/bar") end it "should use LoadedFile to watch files" do Puppet::Util::LoadedFile.expects(:new).with("/foo/bar").returns stub("watched_file") @loader.watch_file("/foo/bar") end it "should be considered stale if any files have changed" do file1 = stub 'file1', :changed? => false file2 = stub 'file2', :changed? => true Puppet::Util::LoadedFile.expects(:new).times(2).returns(file1).then.returns(file2) @loader.watch_file("/foo/bar") @loader.watch_file("/other/bar") @loader.should be_stale end it "should not be considered stable if no files have changed" do file1 = stub 'file1', :changed? => false file2 = stub 'file2', :changed? => false Puppet::Util::LoadedFile.expects(:new).times(2).returns(file1).then.returns(file2) @loader.watch_file("/foo/bar") @loader.watch_file("/other/bar") @loader.should_not be_stale end end describe "when determining the configuration version" do before do @code = Puppet::Resource::TypeCollection.new("env") end it "should default to the current time" do time = Time.now Time.stubs(:now).returns time @code.version.should == time.to_i end it "should use the output of the environment's config_version setting if one is provided" do @code.environment.stubs(:[]).with(:config_version).returns("/my/foo") Puppet::Util.expects(:execute).with(["/my/foo"]).returns "output\n" @code.version.should == "output" end it "should raise a puppet parser error if executing config_version fails" do @code.environment.stubs(:[]).with(:config_version).returns("test") Puppet::Util.expects(:execute).raises(Puppet::ExecutionFailure.new("msg")) lambda { @code.version }.should raise_error(Puppet::ParseError) end end end diff --git a/spec/unit/resource/type_spec.rb b/spec/unit/resource/type_spec.rb index ac9d3811b..29c13c53f 100755 --- a/spec/unit/resource/type_spec.rb +++ b/spec/unit/resource/type_spec.rb @@ -1,722 +1,722 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/resource/type' describe Puppet::Resource::Type do it "should have a 'name' attribute" do Puppet::Resource::Type.new(:hostclass, "foo").name.should == "foo" end [:code, :doc, :line, :file, :resource_type_collection, :ruby_code].each do |attr| it "should have a '#{attr}' attribute" do type = Puppet::Resource::Type.new(:hostclass, "foo") type.send(attr.to_s + "=", "yay") type.send(attr).should == "yay" end end [:hostclass, :node, :definition].each do |type| it "should know when it is a #{type}" do Puppet::Resource::Type.new(type, "foo").send("#{type}?").should be_true end end it "should indirect 'resource_type'" do Puppet::Resource::Type.indirection.name.should == :resource_type end it "should default to 'parser' for its terminus class" do Puppet::Resource::Type.indirection.terminus_class.should == :parser end describe "when converting to json" do before do @type = Puppet::Resource::Type.new(:hostclass, "foo") end def from_json(json) Puppet::Resource::Type.from_pson(json) end def double_convert Puppet::Resource::Type.from_pson(PSON.parse(@type.to_pson)) end it "should include the name and type" do double_convert.name.should == @type.name double_convert.type.should == @type.type end it "should include any arguments" do @type.set_arguments("one" => nil, "two" => "foo") double_convert.arguments.should == {"one" => nil, "two" => "foo"} end it "should include any extra attributes" do @type.file = "/my/file" @type.line = 50 double_convert.file.should == "/my/file" double_convert.line.should == 50 end end describe "when a node" do it "should allow a regex as its name" do lambda { Puppet::Resource::Type.new(:node, /foo/) }.should_not raise_error end it "should allow a AST::HostName instance as its name" do regex = Puppet::Parser::AST::Regex.new(:value => /foo/) name = Puppet::Parser::AST::HostName.new(:value => regex) lambda { Puppet::Resource::Type.new(:node, name) }.should_not raise_error end it "should match against the regexp in the AST::HostName when a HostName instance is provided" do regex = Puppet::Parser::AST::Regex.new(:value => /\w/) name = Puppet::Parser::AST::HostName.new(:value => regex) node = Puppet::Resource::Type.new(:node, name) node.match("foo").should be_true end it "should return the value of the hostname if provided a string-form AST::HostName instance as the name" do name = Puppet::Parser::AST::HostName.new(:value => "foo") node = Puppet::Resource::Type.new(:node, name) node.name.should == "foo" end describe "and the name is a regex" do it "should have a method that indicates that this is the case" do Puppet::Resource::Type.new(:node, /w/).should be_name_is_regex end it "should set its namespace to ''" do Puppet::Resource::Type.new(:node, /w/).namespace.should == "" end it "should return the regex converted to a string when asked for its name" do Puppet::Resource::Type.new(:node, /ww/).name.should == "ww" end it "should downcase the regex when returning the name as a string" do Puppet::Resource::Type.new(:node, /W/).name.should == "w" end it "should remove non-alpha characters when returning the name as a string" do Puppet::Resource::Type.new(:node, /w*w/).name.should_not include("*") end it "should remove leading dots when returning the name as a string" do Puppet::Resource::Type.new(:node, /.ww/).name.should_not =~ /^\./ end it "should have a method for matching its regex name against a provided name" do Puppet::Resource::Type.new(:node, /.ww/).should respond_to(:match) end it "should return true when its regex matches the provided name" do Puppet::Resource::Type.new(:node, /\w/).match("foo").should be_true end it "should return false when its regex does not match the provided name" do (!!Puppet::Resource::Type.new(:node, /\d/).match("foo")).should be_false end it "should return true when its name, as a string, is matched against an equal string" do Puppet::Resource::Type.new(:node, "foo").match("foo").should be_true end it "should return false when its name is matched against an unequal string" do Puppet::Resource::Type.new(:node, "foo").match("bar").should be_false end it "should match names insensitive to case" do Puppet::Resource::Type.new(:node, "fOo").match("foO").should be_true end end it "should return the name converted to a string when the name is not a regex" do pending "Need to define LoadedCode behaviour first" name = Puppet::Parser::AST::HostName.new(:value => "foo") Puppet::Resource::Type.new(:node, name).name.should == "foo" end it "should return the name converted to a string when the name is a regex" do pending "Need to define LoadedCode behaviour first" name = Puppet::Parser::AST::HostName.new(:value => /regex/) Puppet::Resource::Type.new(:node, name).name.should == /regex/.to_s end it "should mark any created scopes as a node scope" do pending "Need to define LoadedCode behaviour first" name = Puppet::Parser::AST::HostName.new(:value => /regex/) Puppet::Resource::Type.new(:node, name).name.should == /regex/.to_s end end describe "when initializing" do it "should require a resource super type" do Puppet::Resource::Type.new(:hostclass, "foo").type.should == :hostclass end it "should fail if provided an invalid resource super type" do lambda { Puppet::Resource::Type.new(:nope, "foo") }.should raise_error(ArgumentError) end it "should set its name to the downcased, stringified provided name" do Puppet::Resource::Type.new(:hostclass, "Foo::Bar".intern).name.should == "foo::bar" end it "should set its namespace to the downcased, stringified qualified name for classes" do Puppet::Resource::Type.new(:hostclass, "Foo::Bar::Baz".intern).namespace.should == "foo::bar::baz" end [:definition, :node].each do |type| it "should set its namespace to the downcased, stringified qualified portion of the name for #{type}s" do Puppet::Resource::Type.new(type, "Foo::Bar::Baz".intern).namespace.should == "foo::bar" end end %w{code line file doc}.each do |arg| it "should set #{arg} if provided" do type = Puppet::Resource::Type.new(:hostclass, "foo", arg.to_sym => "something") type.send(arg).should == "something" end end it "should set any provided arguments with the keys as symbols" do type = Puppet::Resource::Type.new(:hostclass, "foo", :arguments => {:foo => "bar", :baz => "biz"}) type.should be_valid_parameter("foo") type.should be_valid_parameter("baz") end it "should set any provided arguments with they keys as strings" do type = Puppet::Resource::Type.new(:hostclass, "foo", :arguments => {"foo" => "bar", "baz" => "biz"}) type.should be_valid_parameter(:foo) type.should be_valid_parameter(:baz) end it "should function if provided no arguments" do type = Puppet::Resource::Type.new(:hostclass, "foo") type.should_not be_valid_parameter(:foo) end end describe "when testing the validity of an attribute" do it "should return true if the parameter was typed at initialization" do Puppet::Resource::Type.new(:hostclass, "foo", :arguments => {"foo" => "bar"}).should be_valid_parameter("foo") end it "should return true if it is a metaparam" do Puppet::Resource::Type.new(:hostclass, "foo").should be_valid_parameter("require") end it "should return true if the parameter is named 'name'" do Puppet::Resource::Type.new(:hostclass, "foo").should be_valid_parameter("name") end it "should return false if it is not a metaparam and was not provided at initialization" do Puppet::Resource::Type.new(:hostclass, "foo").should_not be_valid_parameter("yayness") end end describe "when creating a subscope" do before do @scope = stub 'scope', :newscope => nil @resource = stub 'resource' @type = Puppet::Resource::Type.new(:hostclass, "foo") end it "should return a new scope created with the provided scope as the parent" do @scope.expects(:newscope).returns "foo" @type.subscope(@scope, @resource).should == "foo" end it "should set the source as itself" do @scope.expects(:newscope).with { |args| args[:source] == @type } @type.subscope(@scope, @resource) end it "should set the scope's namespace to its namespace" do @type.expects(:namespace).returns "yayness" @scope.expects(:newscope).with { |args| args[:namespace] == "yayness" } @type.subscope(@scope, @resource) end it "should set the scope's resource to the provided resource" do @scope.expects(:newscope).with { |args| args[:resource] == @resource } @type.subscope(@scope, @resource) end end describe "when setting its parameters in the scope" do before do @scope = Puppet::Parser::Scope.new(:compiler => stub("compiler", :environment => Puppet::Node::Environment.new), :source => stub("source")) @resource = Puppet::Parser::Resource.new(:foo, "bar", :scope => @scope) @type = Puppet::Resource::Type.new(:hostclass, "foo") end it "should set each of the resource's parameters as variables in the scope" do @type.set_arguments :foo => nil, :boo => nil @resource[:foo] = "bar" @resource[:boo] = "baz" @type.set_resource_parameters(@resource, @scope) @scope.lookupvar("foo").should == "bar" @scope.lookupvar("boo").should == "baz" end it "should set the variables as strings" do @type.set_arguments :foo => nil @resource[:foo] = "bar" @type.set_resource_parameters(@resource, @scope) @scope.lookupvar("foo").should == "bar" end it "should fail if any of the resource's parameters are not valid attributes" do @type.set_arguments :foo => nil @resource[:boo] = "baz" lambda { @type.set_resource_parameters(@resource, @scope) }.should raise_error(Puppet::ParseError) end it "should evaluate and set its default values as variables for parameters not provided by the resource" do @type.set_arguments :foo => stub("value", :safeevaluate => "something") @type.set_resource_parameters(@resource, @scope) @scope.lookupvar("foo").should == "something" end it "should set all default values as parameters in the resource" do @type.set_arguments :foo => stub("value", :safeevaluate => "something") @type.set_resource_parameters(@resource, @scope) @resource[:foo].should == "something" end it "should fail if the resource does not provide a value for a required argument" do @type.set_arguments :foo => nil @resource.expects(:to_hash).returns({}) lambda { @type.set_resource_parameters(@resource, @scope) }.should raise_error(Puppet::ParseError) end it "should set the resource's title as a variable if not otherwise provided" do @type.set_resource_parameters(@resource, @scope) @scope.lookupvar("title").should == "bar" end it "should set the resource's name as a variable if not otherwise provided" do @type.set_resource_parameters(@resource, @scope) @scope.lookupvar("name").should == "bar" end it "should set its module name in the scope if available" do - @type.module_name = "mymod" + @type.instance_eval { @module_name = "mymod" } @type.set_resource_parameters(@resource, @scope) @scope.lookupvar("module_name").should == "mymod" end it "should set its caller module name in the scope if available" do @scope.expects(:parent_module_name).returns "mycaller" @type.set_resource_parameters(@resource, @scope) @scope.lookupvar("caller_module_name").should == "mycaller" end end describe "when describing and managing parent classes" do before do @code = Puppet::Resource::TypeCollection.new("env") @parent = Puppet::Resource::Type.new(:hostclass, "bar") @code.add @parent @child = Puppet::Resource::Type.new(:hostclass, "foo", :parent => "bar") @code.add @child @env = stub "environment", :known_resource_types => @code @scope = stub "scope", :environment => @env, :namespaces => [""] end it "should be able to define a parent" do Puppet::Resource::Type.new(:hostclass, "foo", :parent => "bar") end it "should use the code collection to find the parent resource type" do @child.parent_type(@scope).should equal(@parent) end it "should be able to find parent nodes" do parent = Puppet::Resource::Type.new(:node, "bar") @code.add parent child = Puppet::Resource::Type.new(:node, "foo", :parent => "bar") @code.add child child.parent_type(@scope).should equal(parent) end it "should cache a reference to the parent type" do @code.stubs(:hostclass).with("foo::bar").returns nil @code.expects(:hostclass).with("bar").once.returns @parent @child.parent_type(@scope) @child.parent_type end it "should correctly state when it is another type's child" do @child.parent_type(@scope) @child.should be_child_of(@parent) end it "should be considered the child of a parent's parent" do @grandchild = Puppet::Resource::Type.new(:hostclass, "baz", :parent => "foo") @code.add @grandchild @child.parent_type(@scope) @grandchild.parent_type(@scope) @grandchild.should be_child_of(@parent) end it "should correctly state when it is not another type's child" do @notchild = Puppet::Resource::Type.new(:hostclass, "baz") @code.add @notchild @notchild.should_not be_child_of(@parent) end end describe "when evaluating its code" do before do @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("mynode")) @scope = Puppet::Parser::Scope.new :compiler => @compiler @resource = Puppet::Parser::Resource.new(:foo, "yay", :scope => @scope) # This is so the internal resource lookup works, yo. @compiler.catalog.add_resource @resource @known_resource_types = stub 'known_resource_types' @resource.stubs(:known_resource_types).returns @known_resource_types @type = Puppet::Resource::Type.new(:hostclass, "foo") end it "should set all of its parameters in a subscope" do subscope = stub 'subscope', :compiler => @compiler @type.expects(:subscope).with(@scope, @resource).returns subscope @type.expects(:set_resource_parameters).with(@resource, subscope) @type.evaluate_code(@resource) end it "should not create a subscope for the :main class" do @resource.stubs(:title).returns(:main) @type.expects(:subscope).never @type.expects(:set_resource_parameters).with(@resource, @scope) @type.evaluate_code(@resource) end it "should store the class scope" do @type.evaluate_code(@resource) @scope.class_scope(@type).should be_instance_of(@scope.class) end it "should still create a scope but not store it if the type is a definition" do @type = Puppet::Resource::Type.new(:definition, "foo") @type.evaluate_code(@resource) @scope.class_scope(@type).should be_nil end it "should evaluate the AST code if any is provided" do code = stub 'code' @type.stubs(:code).returns code @type.stubs(:subscope).returns stub_everything("subscope", :compiler => @compiler) code.expects(:safeevaluate).with @type.subscope @type.evaluate_code(@resource) end describe "and ruby code is provided" do it "should create a DSL Resource API and evaluate it" do @type.stubs(:ruby_code).returns(proc { "foo" }) @api = stub 'api' Puppet::DSL::ResourceAPI.expects(:new).with { |res, scope, code| code == @type.ruby_code }.returns @api @api.expects(:evaluate) @type.evaluate_code(@resource) end end it "should noop if there is no code" do @type.expects(:code).returns nil @type.evaluate_code(@resource) end describe "and it has a parent class" do before do @parent_type = Puppet::Resource::Type.new(:hostclass, "parent") @type.parent = "parent" @parent_resource = Puppet::Parser::Resource.new(:class, "parent", :scope => @scope) @compiler.add_resource @scope, @parent_resource @type.resource_type_collection = @scope.known_resource_types @type.resource_type_collection.add @parent_type end it "should evaluate the parent's resource" do @type.parent_type(@scope) @type.evaluate_code(@resource) @scope.class_scope(@parent_type).should_not be_nil end it "should not evaluate the parent's resource if it has already been evaluated" do @parent_resource.evaluate @type.parent_type(@scope) @parent_resource.expects(:evaluate).never @type.evaluate_code(@resource) end it "should use the parent's scope as its base scope" do @type.parent_type(@scope) @type.evaluate_code(@resource) @scope.class_scope(@type).parent.object_id.should == @scope.class_scope(@parent_type).object_id end end describe "and it has a parent node" do before do @type = Puppet::Resource::Type.new(:node, "foo") @parent_type = Puppet::Resource::Type.new(:node, "parent") @type.parent = "parent" @parent_resource = Puppet::Parser::Resource.new(:node, "parent", :scope => @scope) @compiler.add_resource @scope, @parent_resource @type.resource_type_collection = @scope.known_resource_types @type.resource_type_collection.add(@parent_type) end it "should evaluate the parent's resource" do @type.parent_type(@scope) @type.evaluate_code(@resource) @scope.class_scope(@parent_type).should_not be_nil end it "should not evaluate the parent's resource if it has already been evaluated" do @parent_resource.evaluate @type.parent_type(@scope) @parent_resource.expects(:evaluate).never @type.evaluate_code(@resource) end it "should use the parent's scope as its base scope" do @type.parent_type(@scope) @type.evaluate_code(@resource) @scope.class_scope(@type).parent.object_id.should == @scope.class_scope(@parent_type).object_id end end end describe "when creating a resource" do before do @node = Puppet::Node.new("foo", :environment => 'env') @compiler = Puppet::Parser::Compiler.new(@node) @scope = Puppet::Parser::Scope.new(:compiler => @compiler) @top = Puppet::Resource::Type.new :hostclass, "top" @middle = Puppet::Resource::Type.new :hostclass, "middle", :parent => "top" @code = Puppet::Resource::TypeCollection.new("env") @code.add @top @code.add @middle @node.environment.stubs(:known_resource_types).returns(@code) end it "should create a resource instance" do @top.mk_plain_resource(@scope).should be_instance_of(Puppet::Parser::Resource) end it "should set its resource type to 'class' when it is a hostclass" do Puppet::Resource::Type.new(:hostclass, "top").mk_plain_resource(@scope).type.should == "Class" end it "should set its resource type to 'node' when it is a node" do Puppet::Resource::Type.new(:node, "top").mk_plain_resource(@scope).type.should == "Node" end it "should fail when it is a definition" do lambda { Puppet::Resource::Type.new(:definition, "top").mk_plain_resource(@scope) }.should raise_error(ArgumentError) end it "should add the created resource to the scope's catalog" do @top.mk_plain_resource(@scope) @compiler.catalog.resource(:class, "top").should be_instance_of(Puppet::Parser::Resource) end it "should evaluate the parent class if one exists" do @middle.mk_plain_resource(@scope) @compiler.catalog.resource(:class, "top").should be_instance_of(Puppet::Parser::Resource) end it "should fail to evaluate if a parent class is defined but cannot be found" do othertop = Puppet::Resource::Type.new :hostclass, "something", :parent => "yay" @code.add othertop lambda { othertop.mk_plain_resource(@scope) }.should raise_error(Puppet::ParseError) end it "should not create a new resource if one already exists" do @compiler.catalog.expects(:resource).with(:class, "top").returns("something") @compiler.catalog.expects(:add_resource).never @top.mk_plain_resource(@scope) end it "should return the existing resource when not creating a new one" do @compiler.catalog.expects(:resource).with(:class, "top").returns("something") @compiler.catalog.expects(:add_resource).never @top.mk_plain_resource(@scope).should == "something" end it "should not create a new parent resource if one already exists and it has a parent class" do @top.mk_plain_resource(@scope) top_resource = @compiler.catalog.resource(:class, "top") @middle.mk_plain_resource(@scope) @compiler.catalog.resource(:class, "top").should equal(top_resource) end # #795 - tag before evaluation. it "should tag the catalog with the resource tags when it is evaluated" do @middle.mk_plain_resource(@scope) @compiler.catalog.should be_tagged("middle") end it "should tag the catalog with the parent class tags when it is evaluated" do @middle.mk_plain_resource(@scope) @compiler.catalog.should be_tagged("top") end end describe "when merging code from another instance" do def code(str) Puppet::Parser::AST::Leaf.new :value => str end it "should fail unless it is a class" do lambda { Puppet::Resource::Type.new(:node, "bar").merge("foo") }.should raise_error(Puppet::Error) end it "should fail unless the source instance is a class" do dest = Puppet::Resource::Type.new(:hostclass, "bar") source = Puppet::Resource::Type.new(:node, "foo") lambda { dest.merge(source) }.should raise_error(Puppet::Error) end it "should fail if both classes have different parent classes" do code = Puppet::Resource::TypeCollection.new("env") {"a" => "b", "c" => "d"}.each do |parent, child| code.add Puppet::Resource::Type.new(:hostclass, parent) code.add Puppet::Resource::Type.new(:hostclass, child, :parent => parent) end lambda { code.hostclass("b").merge(code.hostclass("d")) }.should raise_error(Puppet::Error) end it "should fail if it's named 'main' and 'freeze_main' is enabled" do Puppet.settings[:freeze_main] = true code = Puppet::Resource::TypeCollection.new("env") code.add Puppet::Resource::Type.new(:hostclass, "") other = Puppet::Resource::Type.new(:hostclass, "") lambda { code.hostclass("").merge(other) }.should raise_error(Puppet::Error) end it "should copy the other class's parent if it has not parent" do dest = Puppet::Resource::Type.new(:hostclass, "bar") parent = Puppet::Resource::Type.new(:hostclass, "parent") source = Puppet::Resource::Type.new(:hostclass, "foo", :parent => "parent") dest.merge(source) dest.parent.should == "parent" end it "should copy the other class's documentation as its docs if it has no docs" do dest = Puppet::Resource::Type.new(:hostclass, "bar") source = Puppet::Resource::Type.new(:hostclass, "foo", :doc => "yayness") dest.merge(source) dest.doc.should == "yayness" end it "should append the other class's docs to its docs if it has any" do dest = Puppet::Resource::Type.new(:hostclass, "bar", :doc => "fooness") source = Puppet::Resource::Type.new(:hostclass, "foo", :doc => "yayness") dest.merge(source) dest.doc.should == "foonessyayness" end it "should turn its code into an ASTArray if necessary" do dest = Puppet::Resource::Type.new(:hostclass, "bar", :code => code("foo")) source = Puppet::Resource::Type.new(:hostclass, "foo", :code => code("bar")) dest.merge(source) dest.code.should be_instance_of(Puppet::Parser::AST::ASTArray) end it "should set the other class's code as its code if it has none" do dest = Puppet::Resource::Type.new(:hostclass, "bar") source = Puppet::Resource::Type.new(:hostclass, "foo", :code => code("bar")) dest.merge(source) dest.code.value.should == "bar" end it "should append the other class's code to its code if it has any" do dcode = Puppet::Parser::AST::ASTArray.new :children => [code("dest")] dest = Puppet::Resource::Type.new(:hostclass, "bar", :code => dcode) scode = Puppet::Parser::AST::ASTArray.new :children => [code("source")] source = Puppet::Resource::Type.new(:hostclass, "foo", :code => scode) dest.merge(source) dest.code.children.collect { |l| l.value }.should == %w{dest source} end end end diff --git a/spec/unit/util/rdoc/parser_spec.rb b/spec/unit/util/rdoc/parser_spec.rb index 79195e657..5dc083cab 100755 --- a/spec/unit/util/rdoc/parser_spec.rb +++ b/spec/unit/util/rdoc/parser_spec.rb @@ -1,540 +1,549 @@ #!/usr/bin/env ruby Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } require 'puppet/resource/type_collection' require 'puppet/util/rdoc/parser' require 'puppet/util/rdoc/code_objects' require 'rdoc/options' require 'rdoc/rdoc' describe RDoc::Parser do before :each do File.stubs(:stat).with("init.pp") @top_level = stub_everything 'toplevel', :file_relative_name => "init.pp" @parser = RDoc::Parser.new(@top_level, "module/manifests/init.pp", nil, Options.instance, RDoc::Stats.new) end describe "when scanning files" do + before do + @environment = Puppet::Node::Environment.new("foo") + end + it "should parse puppet files with the puppet parser" do @parser.stubs(:scan_top_level) parser = stub 'parser' - Puppet::Parser::Parser.expects(:new).returns(parser) - parser.expects(:parse) + Puppet::Parser::Parser.stubs(:new).returns(parser) + parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new('')) parser.expects(:file=).with("module/manifests/init.pp") + parser.expects(:environment).returns(@environment) @parser.scan end it "should scan the ast for Puppet files" do parser = stub_everything 'parser' Puppet::Parser::Parser.stubs(:new).returns(parser) + parser.expects(:environment).returns(@environment) + parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new('')) @parser.expects(:scan_top_level) @parser.scan end it "should return a PuppetTopLevel to RDoc" do parser = stub_everything 'parser' Puppet::Parser::Parser.stubs(:new).returns(parser) + parser.expects(:environment).returns(@environment) + parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new('')) @parser.expects(:scan_top_level) @parser.scan.should be_a(RDoc::PuppetTopLevel) end end describe "when scanning top level entities" do before :each do - @resource_type_collection = stub_everything 'resource_type_collection' - @parser.ast = @resource_type_collection + @resource_type_collection = resource_type_collection = stub_everything('resource_type_collection') + @parser.instance_eval { @known_resource_types = resource_type_collection } @parser.stubs(:split_module).returns("module") @topcontainer = stub_everything 'topcontainer' @container = stub_everything 'container' @module = stub_everything 'module' @container.stubs(:add_module).returns(@module) @parser.stubs(:get_class_or_module).returns([@container, "module"]) end it "should read any present README as module documentation" do FileTest.stubs(:readable?).returns(true) File.stubs(:open).returns("readme") @parser.stubs(:parse_elements) @module.expects(:comment=).with("readme") @parser.scan_top_level(@topcontainer) end it "should tell the container its module name" do @parser.stubs(:parse_elements) @topcontainer.expects(:module_name=).with("module") @parser.scan_top_level(@topcontainer) end it "should not document our toplevel if it isn't a valid module" do @parser.stubs(:split_module).returns(nil) @topcontainer.expects(:document_self=).with(false) @parser.expects(:parse_elements).never @parser.scan_top_level(@topcontainer) end it "should set the module as global if we parse the global manifests (ie __site__ module)" do @parser.stubs(:split_module).returns(RDoc::Parser::SITE) @parser.stubs(:parse_elements) @topcontainer.expects(:global=).with(true) @parser.scan_top_level(@topcontainer) end it "should attach this module container to the toplevel container" do @parser.stubs(:parse_elements) @container.expects(:add_module).with(RDoc::PuppetModule, "module").returns(@module) @parser.scan_top_level(@topcontainer) end it "should defer ast parsing to parse_elements for this module" do @parser.expects(:parse_elements).with(@module) @parser.scan_top_level(@topcontainer) end it "should defer plugins parsing to parse_plugins for this module" do @parser.input_file_name = "module/lib/puppet/parser/function.rb" @parser.expects(:parse_plugins).with(@module) @parser.scan_top_level(@topcontainer) end end describe "when finding modules from filepath" do before :each do Puppet::Module.stubs(:modulepath).returns("/path/to/modules") end it "should return the module name for modulized puppet manifests" do File.stubs(:expand_path).returns("/path/to/module/manifests/init.pp") File.stubs(:identical?).with("/path/to", "/path/to/modules").returns(true) @parser.split_module("/path/to/modules/mymodule/manifests/init.pp").should == "module" end it "should return for manifests not under module path" do File.stubs(:expand_path).returns("/path/to/manifests/init.pp") File.stubs(:identical?).returns(false) @parser.split_module("/path/to/manifests/init.pp").should == RDoc::Parser::SITE end end describe "when parsing AST elements" do before :each do @klass = stub_everything 'klass', :file => "module/manifests/init.pp", :name => "myclass", :type => :hostclass @definition = stub_everything 'definition', :file => "module/manifests/init.pp", :type => :definition, :name => "mydef" @node = stub_everything 'node', :file => "module/manifests/init.pp", :type => :node, :name => "mynode" - @resource_type_collection = Puppet::Resource::TypeCollection.new("env") - @parser.ast = @resource_type_collection + @resource_type_collection = resource_type_collection = Puppet::Resource::TypeCollection.new("env") + @parser.instance_eval { @known_resource_types = resource_type_collection } @container = stub_everything 'container' end it "should document classes in the parsed file" do @resource_type_collection.add_hostclass(@klass) @parser.expects(:document_class).with("myclass", @klass, @container) @parser.parse_elements(@container) end it "should not document class parsed in an other file" do @klass.stubs(:file).returns("/not/same/path/file.pp") @resource_type_collection.add_hostclass(@klass) @parser.expects(:document_class).with("myclass", @klass, @container).never @parser.parse_elements(@container) end it "should document vardefs for the main class" do @klass.stubs(:name).returns :main @resource_type_collection.add_hostclass(@klass) code = stub 'code', :is_a? => false @klass.stubs(:name).returns("") @klass.stubs(:code).returns(code) @parser.expects(:scan_for_vardef).with(@container, code) @parser.parse_elements(@container) end it "should document definitions in the parsed file" do @resource_type_collection.add_definition(@definition) @parser.expects(:document_define).with("mydef", @definition, @container) @parser.parse_elements(@container) end it "should not document definitions parsed in an other file" do @definition.stubs(:file).returns("/not/same/path/file.pp") @resource_type_collection.add_definition(@definition) @parser.expects(:document_define).with("mydef", @definition, @container).never @parser.parse_elements(@container) end it "should document nodes in the parsed file" do @resource_type_collection.add_node(@node) @parser.expects(:document_node).with("mynode", @node, @container) @parser.parse_elements(@container) end it "should not document node parsed in an other file" do @node.stubs(:file).returns("/not/same/path/file.pp") @resource_type_collection.add_node(@node) @parser.expects(:document_node).with("mynode", @node, @container).never @parser.parse_elements(@container) end end describe "when documenting definition" do before(:each) do @define = stub_everything 'define', :arguments => [], :doc => "mydoc", :file => "file", :line => 42 @class = stub_everything 'class' @parser.stubs(:get_class_or_module).returns([@class, "mydef"]) end it "should register a RDoc method to the current container" do @class.expects(:add_method).with { |m| m.name == "mydef"} @parser.document_define("mydef", @define, @class) end it "should attach the documentation to this method" do @class.expects(:add_method).with { |m| m.comment = "mydoc" } @parser.document_define("mydef", @define, @class) end it "should produce a better error message on unhandled exception" do @class.expects(:add_method).raises(ArgumentError) lambda { @parser.document_define("mydef", @define, @class) }.should raise_error(Puppet::ParseError, /in file at line 42/) end it "should convert all definition parameter to string" do arg = stub 'arg' val = stub 'val' @define.stubs(:arguments).returns({arg => val}) arg.expects(:to_s).returns("arg") val.expects(:to_s).returns("val") @parser.document_define("mydef", @define, @class) end end describe "when documenting nodes" do before :each do @code = stub_everything 'code' @node = stub_everything 'node', :doc => "mydoc", :parent => "parent", :code => @code, :file => "file", :line => 42 @rdoc_node = stub_everything 'rdocnode' @class = stub_everything 'class' @class.stubs(:add_node).returns(@rdoc_node) end it "should add a node to the current container" do @class.expects(:add_node).with("mynode", "parent").returns(@rdoc_node) @parser.document_node("mynode", @node, @class) end it "should associate the node documentation to the rdoc node" do @rdoc_node.expects(:comment=).with("mydoc") @parser.document_node("mynode", @node, @class) end it "should scan for include and require" do @parser.expects(:scan_for_include_or_require).with(@rdoc_node, @code) @parser.document_node("mynode", @node, @class) end it "should scan for variable definition" do @parser.expects(:scan_for_vardef).with(@rdoc_node, @code) @parser.document_node("mynode", @node, @class) end it "should scan for resources if needed" do Puppet.settings.stubs(:[]).with(:document_all).returns(true) @parser.expects(:scan_for_resource).with(@rdoc_node, @code) @parser.document_node("mynode", @node, @class) end it "should produce a better error message on unhandled exception" do @class.stubs(:add_node).raises(ArgumentError) lambda { @parser.document_node("mynode", @node, @class) }.should raise_error(Puppet::ParseError, /in file at line 42/) end end describe "when documenting classes" do before :each do @code = stub_everything 'code' @class = stub_everything 'class', :doc => "mydoc", :parent => "parent", :code => @code, :file => "file", :line => 42 @rdoc_class = stub_everything 'rdoc-class' @module = stub_everything 'class' @module.stubs(:add_class).returns(@rdoc_class) @parser.stubs(:get_class_or_module).returns([@module, "myclass"]) end it "should add a class to the current container" do @module.expects(:add_class).with(RDoc::PuppetClass, "myclass", "parent").returns(@rdoc_class) @parser.document_class("mynode", @class, @module) end it "should set the superclass" do @rdoc_class.expects(:superclass=).with("parent") @parser.document_class("mynode", @class, @module) end it "should associate the node documentation to the rdoc class" do @rdoc_class.expects(:comment=).with("mydoc") @parser.document_class("mynode", @class, @module) end it "should scan for include and require" do @parser.expects(:scan_for_include_or_require).with(@rdoc_class, @code) @parser.document_class("mynode", @class, @module) end it "should scan for resources if needed" do Puppet.settings.stubs(:[]).with(:document_all).returns(true) @parser.expects(:scan_for_resource).with(@rdoc_class, @code) @parser.document_class("mynode", @class, @module) end it "should produce a better error message on unhandled exception" do @module.stubs(:add_class).raises(ArgumentError) lambda { @parser.document_class("mynode", @class, @module) }.should raise_error(Puppet::ParseError, /in file at line 42/) end end describe "when scanning for includes and requires" do def create_stmt(name) stmt_value = stub "#{name}_value", :value => "myclass" stmt = stub_everything 'stmt', :name => name, :arguments => [stmt_value], :doc => "mydoc" stmt.stubs(:is_a?).with(Puppet::Parser::AST::ASTArray).returns(false) stmt.stubs(:is_a?).with(Puppet::Parser::AST::Function).returns(true) stmt end before(:each) do @class = stub_everything 'class' @code = stub_everything 'code' @code.stubs(:is_a?).with(Puppet::Parser::AST::ASTArray).returns(true) end it "should also scan mono-instruction code" do @class.expects(:add_include).with { |i| i.is_a?(RDoc::Include) and i.name == "myclass" and i.comment == "mydoc" } @parser.scan_for_include_or_require(@class,create_stmt("include")) end it "should register recursively includes to the current container" do @code.stubs(:children).returns([ create_stmt("include") ]) @class.expects(:add_include).with { |i| i.is_a?(RDoc::Include) and i.name == "myclass" and i.comment == "mydoc" } @parser.scan_for_include_or_require(@class, [@code]) end it "should register requires to the current container" do @code.stubs(:children).returns([ create_stmt("require") ]) @class.expects(:add_require).with { |i| i.is_a?(RDoc::Include) and i.name == "myclass" and i.comment == "mydoc" } @parser.scan_for_include_or_require(@class, [@code]) end end describe "when scanning for realized virtual resources" do def create_stmt stmt_value = stub "resource_ref", :to_s => "File[\"/tmp/a\"]" stmt = stub_everything 'stmt', :name => "realize", :arguments => [stmt_value], :doc => "mydoc" stmt.stubs(:is_a?).with(Puppet::Parser::AST::ASTArray).returns(false) stmt.stubs(:is_a?).with(Puppet::Parser::AST::Function).returns(true) stmt end before(:each) do @class = stub_everything 'class' @code = stub_everything 'code' @code.stubs(:is_a?).with(Puppet::Parser::AST::ASTArray).returns(true) end it "should also scan mono-instruction code" do @class.expects(:add_realize).with { |i| i.is_a?(RDoc::Include) and i.name == "File[\"/tmp/a\"]" and i.comment == "mydoc" } @parser.scan_for_realize(@class,create_stmt) end it "should register recursively includes to the current container" do @code.stubs(:children).returns([ create_stmt ]) @class.expects(:add_realize).with { |i| i.is_a?(RDoc::Include) and i.name == "File[\"/tmp/a\"]" and i.comment == "mydoc" } @parser.scan_for_realize(@class, [@code]) end end describe "when scanning for variable definition" do before :each do @class = stub_everything 'class' @stmt = stub_everything 'stmt', :name => "myvar", :value => "myvalue", :doc => "mydoc" @stmt.stubs(:is_a?).with(Puppet::Parser::AST::ASTArray).returns(false) @stmt.stubs(:is_a?).with(Puppet::Parser::AST::VarDef).returns(true) @code = stub_everything 'code' @code.stubs(:is_a?).with(Puppet::Parser::AST::ASTArray).returns(true) end it "should recursively register variables to the current container" do @code.stubs(:children).returns([ @stmt ]) @class.expects(:add_constant).with { |i| i.is_a?(RDoc::Constant) and i.name == "myvar" and i.comment == "mydoc" } @parser.scan_for_vardef(@class, [ @code ]) end it "should also scan mono-instruction code" do @class.expects(:add_constant).with { |i| i.is_a?(RDoc::Constant) and i.name == "myvar" and i.comment == "mydoc" } @parser.scan_for_vardef(@class, @stmt) end end describe "when scanning for resources" do before :each do @class = stub_everything 'class' param = stub 'params', :children => [] @stmt = stub_everything 'stmt', :type => "File", :title => "myfile", :doc => "mydoc", :params => param @stmt.stubs(:is_a?).with(Puppet::Parser::AST::ASTArray).returns(false) @stmt.stubs(:is_a?).with(Puppet::Parser::AST::Resource).returns(true) @code = stub_everything 'code' @code.stubs(:is_a?).with(Puppet::Parser::AST::ASTArray).returns(true) end it "should register a PuppetResource to the current container" do @code.stubs(:children).returns([ @stmt ]) @class.expects(:add_resource).with { |i| i.is_a?(RDoc::PuppetResource) and i.title == "myfile" and i.comment == "mydoc" } @parser.scan_for_resource(@class, [ @code ]) end it "should also scan mono-instruction code" do @class.expects(:add_resource).with { |i| i.is_a?(RDoc::PuppetResource) and i.title == "myfile" and i.comment == "mydoc" } @parser.scan_for_resource(@class, @stmt) end end describe "when parsing plugins" do before :each do @container = stub 'container' end it "should delegate parsing custom facts to parse_facts" do @parser = RDoc::Parser.new(@top_level, "module/manifests/lib/puppet/facter/test.rb", nil, Options.instance, RDoc::Stats.new) @parser.expects(:parse_fact).with(@container) @parser.parse_plugins(@container) end it "should delegate parsing plugins to parse_plugins" do @parser = RDoc::Parser.new(@top_level, "module/manifests/lib/puppet/functions/test.rb", nil, Options.instance, RDoc::Stats.new) @parser.expects(:parse_puppet_plugin).with(@container) @parser.parse_plugins(@container) end end describe "when parsing plugins" do before :each do @container = stub_everything 'container' end it "should add custom functions to the container" do File.stubs(:open).yields("# documentation module Puppet::Parser::Functions newfunction(:myfunc, :type => :rvalue) do |args| File.dirname(args[0]) end end".split("\n")) @container.expects(:add_plugin).with do |plugin| plugin.comment == "documentation\n" #and plugin.name == "myfunc" end @parser.parse_puppet_plugin(@container) end it "should add custom types to the container" do File.stubs(:open).yields("# documentation Puppet::Type.newtype(:mytype) do end".split("\n")) @container.expects(:add_plugin).with do |plugin| plugin.comment == "documentation\n" #and plugin.name == "mytype" end @parser.parse_puppet_plugin(@container) end end describe "when parsing facts" do before :each do @container = stub_everything 'container' File.stubs(:open).yields(["# documentation", "Facter.add('myfact') do", "confine :kernel => :linux", "end"]) end it "should add facts to the container" do @container.expects(:add_fact).with do |fact| fact.comment == "documentation\n" and fact.name == "myfact" end @parser.parse_fact(@container) end it "should add confine to the parsed facts" do ourfact = nil @container.expects(:add_fact).with do |fact| ourfact = fact true end @parser.parse_fact(@container) ourfact.confine.should == { :type => "kernel", :value => ":linux" } end end end diff --git a/test/language/functions.rb b/test/language/functions.rb index 1d4ed8241..081063e2b 100755 --- a/test/language/functions.rb +++ b/test/language/functions.rb @@ -1,543 +1,543 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../lib/puppettest' require 'puppet' require 'puppet/parser/parser' require 'puppet/network/client' 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.setvar("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.lookupvar("output"), "Undefined template variables do not raise exceptions") # Now, fill in the last variable and make sure the whole thing # evaluates correctly. scope.setvar("two", "Two") scope.unsetvar("output") assert_nothing_raised do ast.evaluate(scope) end assert_equal( "template One\ntemplate Two\n", scope.lookupvar("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.setvar("yay", "this is yay") assert_nothing_raised do ast.evaluate(scope) end assert_equal( "template this is yay\n", scope.lookupvar("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.setvar("deprecated", "deprecated value") assert_nothing_raised do ast.evaluate(scope) end assert_equal( "template deprecated value\n", scope.lookupvar("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.setvar("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.setvar("yayness", string) assert_equal(string, scope.lookupvar("yayness", false)) assert_nothing_raised("An empty string was not a valid variable value") do ast.evaluate(scope) end assert_equal( "template #{value}\n", scope.lookupvar("output"), "#{string.inspect} did not get evaluated correctly") 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::ParseError, "did not throw error on missing class") do scope.function_include("nosuchclass") end - parser.newclass("myclass") + 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 index 5a433c724..330dacb13 100755 --- a/test/language/parser.rb +++ b/test/language/parser.rb @@ -1,746 +1,737 @@ #!/usr/bin/env ruby require 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 Puppet[:parseonly] = true #@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, "Did not fail while parsing #{file}") { - parser.file = file - ast = parser.parse + 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}") 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 importer = tempfile 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.hostclass("").code.each do |obj| + 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.parse %{define mydef($schedule) {}} + parser.known_resource_types.import_ast(parser.parse(%{define mydef($schedule) {}}), '') } assert_nothing_raised { - parser.parse %{define adef($schedule = false) {}} - parser.parse %{define mydef($schedule = daily) {}} + 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).hostclass("").code[0] + 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).hostclass("").code[0] + 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.parse %{class myclass { class other {} }} + 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.parse "class base {} + 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.parse "class container::one inherits container::deep::sub {}" + 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.parse "include container::deep::sub" + 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 - assert_nothing_raised do - out = parser.parse "" - - assert_instance_of(Puppet::Resource::TypeCollection, out) - assert_nil(parser.hostclass(""), "Got a 'main' class when we had no code") - end - - # Now try something a touch more complicated parser.initvars assert_nothing_raised do - out = parser.parse "Exec { path => '/usr/bin:/usr/sbin' }" - assert_instance_of(Puppet::Resource::TypeCollection, out) - assert_equal("", parser.hostclass("").name) - assert_equal("", parser.hostclass("").namespace) + 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 - ret = parser.parse("#{at}file { '/tmp/testing': owner => root }") + 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] + resdef = ret.hostclass("").code[0][0] assert_instance_of(AST::Resource, resdef) assert_equal("/tmp/testing", resdef.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 - ret = parser.parse("#{at}file { ['/tmp/1', '/tmp/2']: owner => root }") + 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.each do |res| + 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.cache_class = catalog_cache_class Puppet::Node::Facts.cache_class = facts_cache_class Puppet::Node.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.hostclass("").code[0] + 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.cache_class = catalog_cache_class Puppet::Node::Facts.cache_class = facts_cache_class Puppet::Node.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).hostclass("").code[0] + 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).hostclass("").code[0] + 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).hostclass("").code[0] + 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") { - parser.parse %{define one::two { }} + types.import_ast(parser.parse(%{define one::two { }}), '') } assert(parser.definition("one::two"), "Could not find one::two with no namespace") - - # Now try using the definition - assert_nothing_raised("Could not parse fully-qualified definition usage") { - parser.parse %{one::two { yayness: }} - } 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 two = tempfile base = tempfile 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.hostclass("").code + 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 - result = parser.parse(str) + 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 - result = parser.newclass "Yayness" + 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 - result = parser.newdefine "FunTest" + 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 index cb5558aec..d9c122a92 100755 --- a/test/language/scope.rb +++ b/test/language/scope.rb @@ -1,277 +1,277 @@ #!/usr/bin/env ruby require 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.setvar("first", "topval") scopes.each do |name, scope| assert_equal("topval", scope.lookupvar("first", false), "Could not find var in #{name}") end # Now set a var in the midscope and make sure the mid and bottom can see it but not the top midscope.setvar("second", "midval") assert_equal(:undefined, scopes[:top].lookupvar("second", false), "Found child var in top scope") [:mid, :bot].each do |name| assert_equal("midval", scopes[name].lookupvar("second", false), "Could not find var in #{name}") end # And set something in the bottom, and make sure we only find it there. botscope.setvar("third", "botval") [:top, :mid].each do |name| assert_equal(:undefined, scopes[name].lookupvar("third", false), "Found child var in top scope") end assert_equal("botval", scopes[:bot].lookupvar("third", false), "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.setvar("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.setvar("test","value") } assert_raise(Puppet::ParseError) { top.setvar("test","other") } assert_nothing_raised { sub.setvar("test","later") } assert_raise(Puppet::ParseError) { top.setvar("test","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.newclass("") + 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.newdefine "one", :arguments => [%w{arg}], + 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.cache_class = catalog_cache_class Puppet::Node::Facts.cache_class = facts_cache_class Puppet::Node.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.setvar("testing", :undef) assert_equal( :undef, scope.lookupvar("testing", false), "undef was not returned as :undef when not string") assert_equal( "", scope.lookupvar("testing", true), "undef was not returned as '' when string") end end diff --git a/test/rails/railsparameter.rb b/test/rails/railsparameter.rb index 9f6fc1c1e..77ce33912 100755 --- a/test/rails/railsparameter.rb +++ b/test/rails/railsparameter.rb @@ -1,80 +1,80 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../lib/puppettest' require 'puppet' require 'puppet/rails' require 'puppettest' require 'puppettest/railstesting' # Don't do any tests w/out this class if defined? ::ActiveRecord::Base class TestRailsParameter < Test::Unit::TestCase include PuppetTest::RailsTesting def params {"myname" => "myval", "multiple" => %w{one two three}} end # Create a resource param from a rails parameter def test_to_resourceparam railsinit # Now create a source parser = mkparser - source = parser.newclass "myclass" + source = parser.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "myclass") host = Puppet::Rails::Host.new(:name => "myhost") host.save resource = host.resources.create( :title => "/tmp/to_resource", :restype => "file", :exported => true) # Use array and non-array values, to make sure we get things back in # the same form. params.each do |name, value| param = Puppet::Rails::ParamName.find_or_create_by_name(name) if value.is_a? Array values = value else values = [value] end valueobjects = values.collect do |v| resource.param_values.create( :value => v, :param_name => param) end assert(param, "Did not create rails parameter") # The id doesn't get assigned until we save end resource.save # And try to convert our parameter params.each do |name, value| param = Puppet::Rails::ParamName.find_by_name(name) pp = nil assert_nothing_raised do pp = param.to_resourceparam(resource, source) end assert_instance_of(Puppet::Parser::Resource::Param, pp) assert_equal(name.to_sym, pp.name, "parameter name was not equal") assert_equal(value, pp.value, "value was not equal for #{value.inspect}") end end end else $stderr.puts "Install Rails for Rails and Caching tests" end