From 4db84c81e50dbf43c46a2e601421b4b5a0db96b1 Mon Sep 17 00:00:00 2001 From: Eugene Piven Date: Fri, 23 Feb 2018 13:56:55 +0300 Subject: [PATCH] Fix return type matching for Puppet functions --- .../yard/handlers/puppet/function_handler.rb | 2 +- .../handlers/puppet/function_handler_spec.rb | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/puppet-strings/yard/handlers/puppet/function_handler.rb b/lib/puppet-strings/yard/handlers/puppet/function_handler.rb index 579fcd4..7efc161 100644 --- a/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +++ b/lib/puppet-strings/yard/handlers/puppet/function_handler.rb @@ -37,7 +37,7 @@ class PuppetStrings::Yard::Handlers::Puppet::FunctionHandler < PuppetStrings::Ya def add_return_tag(object, type=nil) tag = object.tag(:return) if tag - if (type && tag.types) && (type != tag.types) + if (type && tag.types.first) && (type != tag.types.first) log.warn "Documented return type does not match return type in function definition near #{statement.file}:#{statement.line}." end diff --git a/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb b/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb index 54bd6b2..0651e39 100644 --- a/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +++ b/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb @@ -20,7 +20,7 @@ describe PuppetStrings::Yard::Handlers::Puppet::FunctionHandler, if: TEST_PUPPET let(:source) { 'function foo{' } it 'should log an error' do - expect{ subject }.to output(/\[error\]: Failed to parse \(stdin\): Syntax error at end of file/).to_stdout_from_any_process + expect{ subject }.to output(/\[error\]: Failed to parse \(stdin\): Syntax error at end of/).to_stdout_from_any_process expect(subject.empty?).to eq(true) end end @@ -216,6 +216,21 @@ SOURCE end end + describe 'parsing a function with a non-conflicting return tag and type in function definition', if: TEST_FUNCTION_RETURN_TYPE do + let(:source) { <<-SOURCE +# A simple foo function +# @return [String] Hi there +function foo() >> String { + notice 'hi there' +} +SOURCE + } + + it 'should not output a warning if return types match' do + expect{ subject }.not_to output(/Documented return type does not match return type in function definition/).to_stdout_from_any_process + end + end + describe 'parsing a function with a conflicting return tag and type in function definition', if: TEST_FUNCTION_RETURN_TYPE do let(:source) { <<-SOURCE # A simple foo function.