From bd8d1590167d9f7ca2bd0faa68ccbd6e8ab13780 Mon Sep 17 00:00:00 2001 From: Ian Kronquist Date: Fri, 14 Aug 2015 16:11:27 -0700 Subject: [PATCH 1/2] (PDOC-21) Fix duplicate warnings for hostclasses Host classes inherit behavior from defined types. I didn't realize this when I was first implementing this functionality. --- .../strings/yard/templates/default/hostclass/setup.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/setup.rb b/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/setup.rb index b88dbff..b8bda9e 100644 --- a/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/setup.rb +++ b/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/setup.rb @@ -3,13 +3,6 @@ include T('default/definedtype') def init super sections.push :subclasses - - @template_helper = TemplateHelper.new - @template_helper.check_parameters_match_docs object - params = object.parameters.map { |param| param.first } - param_tags = object.tags.find_all{ |tag| tag.tag_name == "param"} - param_details = @template_helper.extract_param_details(params, param_tags) unless params.nil? - @template_helper.check_types_match_docs object, param_details end def subclasses From f5c4c4c861f04bfe5994a926df79444fc6f085e7 Mon Sep 17 00:00:00 2001 From: Ian Kronquist Date: Mon, 17 Aug 2015 14:05:32 -0700 Subject: [PATCH 2/2] (PDOC-21) Test for duplicate hostclass warnings * Add testing file based off shaigy's tests. * Refactor using_module into a helper class. * Expect that the warnings printed to stdout are *exactly* what I want to see and nothing else. --- spec/lib/strings_spec/module_helper.rb | 20 ++++++++ spec/unit/puppet/face_spec.rb | 48 ++++++------------- .../yard/examples/test/manifests/init.pp | 7 +++ .../strings/yard/host_class_handler_spec.rb | 27 +++++++++++ 4 files changed, 69 insertions(+), 33 deletions(-) create mode 100644 spec/lib/strings_spec/module_helper.rb create mode 100644 spec/unit/puppet_x/puppetlabs/strings/yard/examples/test/manifests/init.pp diff --git a/spec/lib/strings_spec/module_helper.rb b/spec/lib/strings_spec/module_helper.rb new file mode 100644 index 0000000..77bc860 --- /dev/null +++ b/spec/lib/strings_spec/module_helper.rb @@ -0,0 +1,20 @@ +class PuppetModuleHelper +# Helper methods to handle file operations around generating and loading HTML + def self.using_module(path, modulename, &block) + Dir.mktmpdir do |tmp| + module_location = File.join(path, "examples", modulename) + FileUtils.cp_r(module_location, tmp) + old_dir = Dir.pwd + begin + Dir.chdir(tmp) + yield(tmp) + ensure + Dir.chdir(old_dir) + end + end + end + + def self.read_html(dir, modulename, file) + File.read(File.join(dir, modulename, 'doc', file)) + end +end diff --git a/spec/unit/puppet/face_spec.rb b/spec/unit/puppet/face_spec.rb index 015c051..f08e013 100644 --- a/spec/unit/puppet/face_spec.rb +++ b/spec/unit/puppet/face_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'lib/strings_spec/module_helper' require 'puppet/face/strings' require 'tmpdir' require 'stringio' @@ -51,61 +52,61 @@ describe Puppet::Face do it "should properly generate HTML for manifest comments" do - using_module('test') do |tmp| + PuppetModuleHelper.using_module(File.dirname(__FILE__), 'test') do |tmp| Dir.chdir('test') Puppet::Face[:strings, :current].yardoc - expect(read_html(tmp, 'test', 'test.html')).to include("Class: test") + expect(PuppetModuleHelper.read_html(tmp, 'test', 'test.html')).to include("Class: test") end end it "should properly generate HTML for 3x function comments" do - using_module('test') do |tmp| + PuppetModuleHelper.using_module(File.dirname(__FILE__), 'test') do |tmp| Dir.chdir('test') Puppet::Face[:strings, :current].yardoc - expect(read_html(tmp, 'test', 'Puppet3xFunctions.html')).to include("This is the function documentation for `function3x`") + expect(PuppetModuleHelper.read_html(tmp, 'test', 'Puppet3xFunctions.html')).to include("This is the function documentation for `function3x`") end end it "should properly generate HTML for 4x function comments" do - using_module('test') do |tmp| + PuppetModuleHelper.using_module(File.dirname(__FILE__), 'test') do |tmp| Dir.chdir('test') Puppet::Face[:strings, :current].yardoc - expect(read_html(tmp, 'test', 'Puppet4xFunctions.html')).to include("This is a function which is used to test puppet strings") + expect(PuppetModuleHelper.read_html(tmp, 'test', 'Puppet4xFunctions.html')).to include("This is a function which is used to test puppet strings") end end it "should create correct files for nested classes" do - using_module('test') do |tmp| + PuppetModuleHelper.using_module(File.dirname(__FILE__), 'test') do |tmp| Dir.chdir('test') Puppet::Face[:strings, :current].yardoc - expect(read_html(tmp, + expect(PuppetModuleHelper.read_html(tmp, 'test', 'outer.html')).to include("Puppet Class: outer") - expect(read_html(tmp, 'test', + expect(PuppetModuleHelper.read_html(tmp, 'test', 'outer/middle.html')).to include("Puppet Class: middle") - expect(read_html(tmp, 'test', + expect(PuppetModuleHelper.read_html(tmp, 'test', 'outer/middle/inner.html')).to include("Puppet Class: inner") end end it "should create proper namespace for nested classes" do - using_module('test') do |tmp| + PuppetModuleHelper.using_module(File.dirname(__FILE__), 'test') do |tmp| Dir.chdir('test') Puppet::Face[:strings, :current].yardoc - expect(read_html(tmp, + expect(PuppetModuleHelper.read_html(tmp, 'test', 'outer.html')).to include("Hostclass: outer") - expect(read_html(tmp, 'test', + expect(PuppetModuleHelper.read_html(tmp, 'test', 'outer/middle.html')).to include("Hostclass: outer::middle") - expect(read_html(tmp, 'test', + expect(PuppetModuleHelper.read_html(tmp, 'test', 'outer/middle/inner.html')).to include("Hostclass: outer::middle::inner") end end @@ -127,24 +128,5 @@ describe Puppet::Face do expect{Puppet::Face[:strings, :current].server}.to raise_error(RuntimeError, "This face requires Ruby 1.9 or greater.") end end - - # Helper methods to handle file operations around generating and loading HTML - def using_module(modulename, &block) - Dir.mktmpdir do |tmp| - module_location = File.join(File.dirname(__FILE__), "examples", modulename) - FileUtils.cp_r(module_location, tmp) - old_dir = Dir.pwd - begin - Dir.chdir(tmp) - yield(tmp) - ensure - Dir.chdir(old_dir) - end - end - end - - def read_html(dir, modulename, file) - File.read(File.join(dir, modulename, 'doc', file)) - end end diff --git a/spec/unit/puppet_x/puppetlabs/strings/yard/examples/test/manifests/init.pp b/spec/unit/puppet_x/puppetlabs/strings/yard/examples/test/manifests/init.pp new file mode 100644 index 0000000..7d1a8ee --- /dev/null +++ b/spec/unit/puppet_x/puppetlabs/strings/yard/examples/test/manifests/init.pp @@ -0,0 +1,7 @@ +# @param [Float] ident identification +class foo( String $ident = "Bob" , Integer $age = 10, ) +{ + notify {'$ident':} + notify {'$age':} +} + diff --git a/spec/unit/puppet_x/puppetlabs/strings/yard/host_class_handler_spec.rb b/spec/unit/puppet_x/puppetlabs/strings/yard/host_class_handler_spec.rb index 6759d22..4939b6e 100644 --- a/spec/unit/puppet_x/puppetlabs/strings/yard/host_class_handler_spec.rb +++ b/spec/unit/puppet_x/puppetlabs/strings/yard/host_class_handler_spec.rb @@ -1,4 +1,6 @@ require 'spec_helper' +require 'lib/strings_spec/module_helper' +require 'puppet/face/strings' require 'puppet_x/puppetlabs/strings/yard/handlers/host_class_handler' require 'strings_spec/parsing' @@ -59,4 +61,29 @@ describe PuppetX::PuppetLabs::Strings::YARD::Handlers::HostClassHandler do expect(namespace).to_not be_nil end + it "should not issue just one warning if the parameter types don't match." do + YARD::Registry.clear + # FIXME The type information here will change with the next version of + # puppet. `expected` is the output expected from the stable branch. The + # output from the master branch will use this instead: + # "...specifies the types [String] in file..." + expected = <<-output +[warn]: @param tag types do not match the code. The ident parameter is declared as types [\"Float\"] in the docstring, but the code specifies the types [Puppet::Pops::Types::PStringType] in file manifests/init.pp near line 2 +Files: 1 +Modules: 0 ( 0 undocumented) +Classes: 0 ( 0 undocumented) +Constants: 0 ( 0 undocumented) +Methods: 0 ( 0 undocumented) +Puppet Classes: 1 ( 0 undocumented) +Puppet Types: 0 ( 0 undocumented) + 100.00% documented + output + + expect { + PuppetModuleHelper.using_module(File.dirname(__FILE__),'test') do |tmp| + Dir.chdir('test') + Puppet::Face[:strings, :current].yardoc + end + }.to output(expected).to_stdout_from_any_process + end end