summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@puppetlabs.com>2011-02-12 11:52:21 -0800
committerDaniel Pittman <daniel@rimspace.net>2011-02-12 11:52:21 -0800
commit16e79f075622aa155a112d5a271c386f4ebc0241 (patch)
tree436218854ccc50181dd7cf985d1ca261c3950b8e
parent781601f8e7a9c6aecc5c9de66b1597b1879450d2 (diff)
parentb5b5923bf41196f5e72a69bfa627120c75732fe5 (diff)
downloadpuppet-16e79f075622aa155a112d5a271c386f4ebc0241.tar.gz
puppet-16e79f075622aa155a112d5a271c386f4ebc0241.tar.xz
puppet-16e79f075622aa155a112d5a271c386f4ebc0241.zip
Merge branch 'bug/2.6.next/5720-puppetdoc-fails-on-parameterized-class' into 2.6.next
-rw-r--r--lib/puppet/parser/ast/leaf.rb2
-rw-r--r--lib/puppet/parser/lexer.rb5
-rw-r--r--lib/puppet/parser/parser_support.rb6
-rw-r--r--lib/puppet/util/rdoc/parser.rb8
-rwxr-xr-xspec/unit/parser/lexer_spec.rb16
-rwxr-xr-xspec/unit/parser/parser_spec.rb29
-rwxr-xr-xspec/unit/util/rdoc/parser_spec.rb18
7 files changed, 72 insertions, 12 deletions
diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb
index fcdd219d7..77617e992 100644
--- a/lib/puppet/parser/ast/leaf.rb
+++ b/lib/puppet/parser/ast/leaf.rb
@@ -67,7 +67,7 @@ class Puppet::Parser::AST
end
def to_s
- "concat(#{@value.join(',')})"
+ "#{@value.map { |s| s.to_s.gsub(/^"(.*)"$/, '\1') }.join}"
end
end
diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb
index 31d39ae2f..9a25263f6 100644
--- a/lib/puppet/parser/lexer.rb
+++ b/lib/puppet/parser/lexer.rb
@@ -476,9 +476,12 @@ class Puppet::Parser::Lexer
@expected.pop
end
- if final_token.name == :LBRACE
+ if final_token.name == :LBRACE or final_token.name == :LPAREN
commentpush
end
+ if final_token.name == :RPAREN
+ commentpop
+ end
yield [final_token.name, token_value]
diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb
index 7bbebb124..7a0aa2601 100644
--- a/lib/puppet/parser/parser_support.rb
+++ b/lib/puppet/parser/parser_support.rb
@@ -135,19 +135,19 @@ class Puppet::Parser::Parser
# 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))
+ known_resource_types.add Puppet::Resource::Type.new(:hostclass, name, ast_context(true, options[:line]).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))
+ known_resource_types.add Puppet::Resource::Type.new(:definition, name, ast_context(true, options[:line]).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)
+ context = ast_context(true, options[:line])
names.collect do |name|
known_resource_types.add(Puppet::Resource::Type.new(:node, name, context.merge(options)))
end
diff --git a/lib/puppet/util/rdoc/parser.rb b/lib/puppet/util/rdoc/parser.rb
index f9becede1..ea7439ad7 100644
--- a/lib/puppet/util/rdoc/parser.rb
+++ b/lib/puppet/util/rdoc/parser.rb
@@ -41,8 +41,10 @@ class Parser
@parser.file = @input_file_name
@ast = @parser.parse
end
- scan_top_level(@top_level)
+ else
+ @ast = env.known_resource_types
end
+ scan_top_level(@top_level)
@top_level
end
@@ -157,8 +159,8 @@ class Parser
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))
+ Puppet.debug "found #{stmt.name}: #{included}"
+ container.send("add_#{stmt.name}",Include.new(included.to_s, stmt.doc))
end
end
end
diff --git a/spec/unit/parser/lexer_spec.rb b/spec/unit/parser/lexer_spec.rb
index 860326973..4ef242cf5 100755
--- a/spec/unit/parser/lexer_spec.rb
+++ b/spec/unit/parser/lexer_spec.rb
@@ -529,6 +529,22 @@ describe Puppet::Parser::Lexer, "when lexing comments" do
@lexer.fullscan
end
+ it "should add a new comment stack level on LPAREN" do
+ @lexer.string = "("
+
+ @lexer.expects(:commentpush)
+
+ @lexer.fullscan
+ end
+
+ it "should pop the current comment on RPAREN" do
+ @lexer.string = ")"
+
+ @lexer.expects(:commentpop)
+
+ @lexer.fullscan
+ end
+
it "should return the current comments on getcomment" do
@lexer.string = "# comment"
@lexer.fullscan
diff --git a/spec/unit/parser/parser_spec.rb b/spec/unit/parser/parser_spec.rb
index 07e2d220b..2f5d4b8ea 100755
--- a/spec/unit/parser/parser_spec.rb
+++ b/spec/unit/parser/parser_spec.rb
@@ -276,7 +276,7 @@ describe Puppet::Parser do
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{ |a| a[0] == true }.returns({})
+ @parser.expects(:ast_context).with{ |docs, line| docs == true }.returns({})
@parser.ast(@class, :file => "/bar")
end
@@ -304,6 +304,33 @@ describe Puppet::Parser do
it "should return an array of nodes" do
@parser.newnode(@nodename).should be_instance_of(Array)
end
+
+ it "should initialize the ast context with the correct line number" do
+ @parser.expects(:ast_context).with { |a,b| b == 123 }.returns({})
+ @parser.newnode(@nodename, { :line => 123 })
+ end
+ end
+
+ %w{class define}.each do |entity|
+ describe "when creating a #{entity}" do
+ before :each do
+ @parser.stubs(:ast_context).returns({})
+
+ @name = stub "#{entity}name", :is_a? => false, :value => "foo"
+ end
+
+ it "should create and add the correct resource type" do
+ instance = stub 'instance'
+ Puppet::Resource::Type.expects(:new).returns(instance)
+ @parser.known_resource_types.expects(:add).with(instance)
+ @parser.send("new#{entity}", @name)
+ end
+
+ it "should initialize the ast context with the correct line number" do
+ @parser.expects(:ast_context).with { |a,b| b == 123 }.returns({})
+ @parser.send("new#{entity}", @name, { :line => 123 })
+ end
+ end
end
describe "when retrieving a specific node" do
diff --git a/spec/unit/util/rdoc/parser_spec.rb b/spec/unit/util/rdoc/parser_spec.rb
index 28c33c295..b4453ae86 100755
--- a/spec/unit/util/rdoc/parser_spec.rb
+++ b/spec/unit/util/rdoc/parser_spec.rb
@@ -43,6 +43,18 @@ describe RDoc::Parser do
@parser.scan.should be_a(RDoc::PuppetTopLevel)
end
+
+ it "should scan the top level even if the file has already parsed" do
+ known_type = stub 'known_types'
+ env = stub 'env'
+ Puppet::Node::Environment.stubs(:new).returns(env)
+ env.stubs(:known_resource_types).returns(known_type)
+ known_type.expects(:watching_file?).with("module/manifests/init.pp").returns(true)
+
+ @parser.expects(:scan_top_level)
+
+ @parser.scan
+ end
end
describe "when scanning top level entities" do
@@ -339,7 +351,7 @@ describe RDoc::Parser do
describe "when scanning for includes and requires" do
def create_stmt(name)
- stmt_value = stub "#{name}_value", :value => "myclass"
+ stmt_value = stub "#{name}_value", :to_s => "myclass"
Puppet::Parser::AST::Function.new(
:name => name,
@@ -357,13 +369,13 @@ describe RDoc::Parser do
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"))
+ @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" }
+ @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