diff options
| author | Max Martin <max@puppetlabs.com> | 2011-03-08 13:32:25 -0800 |
|---|---|---|
| committer | Max Martin <max@puppetlabs.com> | 2011-03-08 13:32:25 -0800 |
| commit | 9d551be70ab2a5d64a75a5c497534b0413cd3d81 (patch) | |
| tree | 062d88419140fd3d848d68946c76cd3e75baeec5 | |
| parent | c3ec3d100fb27211bf86c12bdc759d1fa1afce25 (diff) | |
| parent | 2a915725adf0ccefcc28653cbba2219925194594 (diff) | |
Merge branch 'ticket/next/4798-rdoc-fixes' into next
* ticket/next/4798-rdoc-fixes:
(#4798) Make rdoc work if moduledir & manifestdir overlap
maint: Fix rdoc when documenting manifest files
maint: Move puppetdoc settings to defaults so we can use them in tests
| -rw-r--r-- | lib/puppet/application/doc.rb | 8 | ||||
| -rw-r--r-- | lib/puppet/defaults.rb | 4 | ||||
| -rw-r--r-- | lib/puppet/util/rdoc.rb | 14 | ||||
| -rw-r--r-- | lib/puppet/util/rdoc/parser.rb | 4 | ||||
| -rw-r--r-- | spec/fixtures/unit/util/rdoc/basic.pp | 16 | ||||
| -rw-r--r-- | spec/integration/application/doc_spec.rb | 1 | ||||
| -rwxr-xr-x | spec/unit/util/rdoc_spec.rb | 70 |
7 files changed, 44 insertions, 73 deletions
diff --git a/lib/puppet/application/doc.rb b/lib/puppet/application/doc.rb index 3bfe41653..74811919e 100644 --- a/lib/puppet/application/doc.rb +++ b/lib/puppet/application/doc.rb @@ -1,7 +1,6 @@ require 'puppet/application' class Puppet::Application::Doc < Puppet::Application - should_not_parse_config run_mode :master @@ -140,7 +139,7 @@ COPYRIGHT Copyright (c) 2005-2007 Puppet Labs, LLC Licensed under the GNU Public License - HELP +HELP end def handle_unknown( opt, arg ) @@ -163,11 +162,6 @@ License files += command_line.args Puppet.info "scanning: #{files.inspect}" - Puppet.settings.setdefaults( - "puppetdoc", - - "document_all" => [false, "Document all resources"] - ) Puppet.settings[:document_all] = options[:all] || false begin require 'puppet/util/rdoc' diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index 576acfeb6..f308d4476 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -822,4 +822,8 @@ module Puppet directories." ] ) + setdefaults( + :puppetdoc, + :document_all => [false, "Document all resources"] + ) end diff --git a/lib/puppet/util/rdoc.rb b/lib/puppet/util/rdoc.rb index bdac579d6..c00bc6f85 100644 --- a/lib/puppet/util/rdoc.rb +++ b/lib/puppet/util/rdoc.rb @@ -31,6 +31,7 @@ module Puppet::Util::RDoc options << "--force-update" if Options::OptionList.options.any? { |o| o[0] == "--force-update" } options += [ "--charset", charset] if charset options += files + #TODO dedup file paths (not strict duplication sense, parents, children, etc # launch the documentation process r.document(options) @@ -53,17 +54,10 @@ module Puppet::Util::RDoc # of a manifest def output(file, ast) astobj = [] - ast.nodes.each do |name, k| - astobj << k if k.file == file + ast.instantiate('').each do |resource_type| + astobj << resource_type if resource_type.file == file end - ast.hostclasses.each do |name,k| - astobj << k if k.file == file - end - - ast.definitions.each do |name, k| - astobj << k if k.file == file - end astobj.sort! {|a,b| a.line <=> b.line }.each do |k| output_astnode_doc(k) end @@ -89,4 +83,4 @@ module Puppet::Util::RDoc end end -end
\ No newline at end of file +end diff --git a/lib/puppet/util/rdoc/parser.rb b/lib/puppet/util/rdoc/parser.rb index 2b89baace..0f746e2ea 100644 --- a/lib/puppet/util/rdoc/parser.rb +++ b/lib/puppet/util/rdoc/parser.rb @@ -34,17 +34,18 @@ class Parser # main entry point def scan environment = Puppet::Node::Environment.new + @known_resource_types = environment.known_resource_types unless environment.known_resource_types.watching_file?(@input_file_name) Puppet.info "rdoc: scanning #{@input_file_name}" if @input_file_name =~ /\.pp$/ @parser = Puppet::Parser::Parser.new(environment) @parser.file = @input_file_name - @known_resource_types = environment.known_resource_types @parser.parse.instantiate('').each do |type| @known_resource_types.add type end end end + scan_top_level(@top_level) @top_level end @@ -342,6 +343,7 @@ class Parser # that contains the documentation def parse_elements(container) Puppet.debug "rdoc: scanning manifest" + @known_resource_types.hostclasses.values.sort { |a,b| a.name <=> b.name }.each do |klass| name = klass.name if klass.file == @input_file_name diff --git a/spec/fixtures/unit/util/rdoc/basic.pp b/spec/fixtures/unit/util/rdoc/basic.pp new file mode 100644 index 000000000..5616503c1 --- /dev/null +++ b/spec/fixtures/unit/util/rdoc/basic.pp @@ -0,0 +1,16 @@ +# im a class +class foo { + file { '/tmp/foo' : + ensure => present, + } +} + +# im a node +node gar { +} + +# im a define +define baz { } + +# im a resource +host { 'cow' : } diff --git a/spec/integration/application/doc_spec.rb b/spec/integration/application/doc_spec.rb index d94b3043b..f0b9d7db0 100644 --- a/spec/integration/application/doc_spec.rb +++ b/spec/integration/application/doc_spec.rb @@ -7,7 +7,6 @@ describe Puppet::Application::Doc do include PuppetSpec::Files it "should not generate an error when module dir overlaps parent of site.pp (#4798)" do - pending "need to fix as part of fixing Brice's rdoc patch" begin # Note: the directory structure below is more complex than it # needs to be, but it's representative of the directory structure diff --git a/spec/unit/util/rdoc_spec.rb b/spec/unit/util/rdoc_spec.rb index 41d4b9cd0..93c4f9bfa 100755 --- a/spec/unit/util/rdoc_spec.rb +++ b/spec/unit/util/rdoc_spec.rb @@ -123,63 +123,25 @@ describe Puppet::Util::RDoc do end describe "when outputing documentation" do - before :each do - @node = stub 'node', :file => "file", :line => 1, :doc => "" - @class = stub 'class', :file => "file", :line => 4, :doc => "" - @definition = stub 'definition', :file => "file", :line => 3, :doc => "" - @ast = stub 'ast', :nodes => { :node => @node }, :hostclasses => { :class => @class }, :definitions => { :definition => @definition } - end - - it "should output doc for ast nodes" do - @node.expects(:doc) - - Puppet::Util::RDoc.output("file", @ast) - end - - it "should output doc for ast classes" do - @class.expects(:doc) - - Puppet::Util::RDoc.output("file", @ast) - end - - it "should output doc for ast definitions" do - @definition.expects(:doc) - - Puppet::Util::RDoc.output("file", @ast) - end - - it "should output doc in order of increasing line number" do - byline = sequence('byline') - @node.expects(:doc).in_sequence(byline) - @definition.expects(:doc).in_sequence(byline) - @class.expects(:doc).in_sequence(byline) - - Puppet::Util::RDoc.output("file", @ast) - end - - it "should not output documentation of ast object of another node" do - klass = stub 'otherclass', :file => "otherfile", :line => 12, :doc => "" - @ast.stubs(:hostclasses).returns({ :otherclass => klass }) - - klass.expects(:doc).never - - Puppet::Util::RDoc.output("file", @ast) + it "should output doc for ast classes, nodes and definitions in order of increasing line number" do + byline = sequence('documentation outputs in line order') + Puppet::Util::RDoc.expects(:puts).with("im a class\n").in_sequence(byline) + Puppet::Util::RDoc.expects(:puts).with("im a node\n").in_sequence(byline) + Puppet::Util::RDoc.expects(:puts).with("im a define\n").in_sequence(byline) + # any other output must fail + Puppet::Util::RDoc.manifestdoc([my_fixture('basic.pp')]) end it "should output resource documentation if needed" do - Puppet.settings.stubs(:[]).with(:document_all).returns(true) - [@node,@definition].each do |o| - o.stubs(:code).returns([]) - end - - resource = stub_everything 'resource', :line => 1 - resource.stubs(:is_a?).with(Puppet::Parser::AST::ASTArray).returns(false) - resource.stubs(:is_a?).with(Puppet::Parser::AST::Resource).returns(true) - @class.stubs(:code).returns([resource]) - - resource.expects(:doc) - - Puppet::Util::RDoc.output("file", @ast) + pending "#6634 being fixed" + Puppet.settings[:document_all] = true + byline = sequence('documentation outputs in line order') + Puppet::Util::RDoc.expects(:puts).with("im a class\n").in_sequence(byline) + Puppet::Util::RDoc.expects(:puts).with("im a node\n").in_sequence(byline) + Puppet::Util::RDoc.expects(:puts).with("im a define\n").in_sequence(byline) + Puppet::Util::RDoc.expects(:puts).with("im a resource\n").in_sequence(byline) + # any other output must fail + Puppet::Util::RDoc.manifestdoc([my_fixture('basic.pp')]) end end end |
