(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.
This commit is contained in:
Ian Kronquist 2015-08-17 14:05:32 -07:00
parent bd8d159016
commit f5c4c4c861
4 changed files with 69 additions and 33 deletions

View File

@ -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

View File

@ -1,4 +1,5 @@
require 'spec_helper' require 'spec_helper'
require 'lib/strings_spec/module_helper'
require 'puppet/face/strings' require 'puppet/face/strings'
require 'tmpdir' require 'tmpdir'
require 'stringio' require 'stringio'
@ -51,61 +52,61 @@ describe Puppet::Face do
it "should properly generate HTML for manifest comments" 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') Dir.chdir('test')
Puppet::Face[:strings, :current].yardoc 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
end end
it "should properly generate HTML for 3x function comments" do 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') Dir.chdir('test')
Puppet::Face[:strings, :current].yardoc 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
end end
it "should properly generate HTML for 4x function comments" do 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') Dir.chdir('test')
Puppet::Face[:strings, :current].yardoc 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
end end
it "should create correct files for nested classes" do 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') Dir.chdir('test')
Puppet::Face[:strings, :current].yardoc Puppet::Face[:strings, :current].yardoc
expect(read_html(tmp, expect(PuppetModuleHelper.read_html(tmp,
'test', 'outer.html')).to include("Puppet Class: outer") '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") '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") 'outer/middle/inner.html')).to include("Puppet Class: inner")
end end
end end
it "should create proper namespace for nested classes" do 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') Dir.chdir('test')
Puppet::Face[:strings, :current].yardoc Puppet::Face[:strings, :current].yardoc
expect(read_html(tmp, expect(PuppetModuleHelper.read_html(tmp,
'test', 'outer.html')).to include("Hostclass: outer") '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") '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") 'outer/middle/inner.html')).to include("Hostclass: outer::middle::inner")
end end
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.") expect{Puppet::Face[:strings, :current].server}.to raise_error(RuntimeError, "This face requires Ruby 1.9 or greater.")
end end
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 end

View File

@ -0,0 +1,7 @@
# @param [Float] ident identification
class foo( String $ident = "Bob" , Integer $age = 10, )
{
notify {'$ident':}
notify {'$age':}
}

View File

@ -1,4 +1,6 @@
require 'spec_helper' require 'spec_helper'
require 'lib/strings_spec/module_helper'
require 'puppet/face/strings'
require 'puppet_x/puppetlabs/strings/yard/handlers/host_class_handler' require 'puppet_x/puppetlabs/strings/yard/handlers/host_class_handler'
require 'strings_spec/parsing' require 'strings_spec/parsing'
@ -59,4 +61,29 @@ describe PuppetX::PuppetLabs::Strings::YARD::Handlers::HostClassHandler do
expect(namespace).to_not be_nil expect(namespace).to_not be_nil
end 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 end