Merge pull request #159 from pegasd/fix_return_type_matching
Fix return type matching for Puppet functions
This commit is contained in:
commit
0b1a095df6
|
@ -37,7 +37,7 @@ class PuppetStrings::Yard::Handlers::Puppet::FunctionHandler < PuppetStrings::Ya
|
||||||
def add_return_tag(object, type=nil)
|
def add_return_tag(object, type=nil)
|
||||||
tag = object.tag(:return)
|
tag = object.tag(:return)
|
||||||
if tag
|
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}."
|
log.warn "Documented return type does not match return type in function definition near #{statement.file}:#{statement.line}."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ describe PuppetStrings::Yard::Handlers::Puppet::FunctionHandler, if: TEST_PUPPET
|
||||||
let(:source) { 'function foo{' }
|
let(:source) { 'function foo{' }
|
||||||
|
|
||||||
it 'should log an error' do
|
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)
|
expect(subject.empty?).to eq(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -216,6 +216,21 @@ SOURCE
|
||||||
end
|
end
|
||||||
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
|
describe 'parsing a function with a conflicting return tag and type in function definition', if: TEST_FUNCTION_RETURN_TYPE do
|
||||||
let(:source) { <<-SOURCE
|
let(:source) { <<-SOURCE
|
||||||
# A simple foo function.
|
# A simple foo function.
|
||||||
|
|
Loading…
Reference in New Issue