From af5cd1a1da0e1b87696ae72b8a5f1c174e83e94e Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 14 Aug 2017 15:41:03 +0530 Subject: [PATCH] add tests for man+'man[1-8]' --- Library/Homebrew/rubocops/lines_cop.rb | 12 +++++----- .../Homebrew/test/rubocops/lines_cop_spec.rb | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb index 6a6f348211..cf1ac68c30 100644 --- a/Library/Homebrew/rubocops/lines_cop.rb +++ b/Library/Homebrew/rubocops/lines_cop.rb @@ -93,12 +93,12 @@ module RuboCop problem "Use build instead of ARGV to check options" end end - # - # find_instance_method_call(body_node, :man, :+) do |m| - # next unless match = regex_match_group(parameters(m).first, %r{man[1-8]}) - # problem "\"#{m.source}\" should be \"#{match[1]}\"" - # end - # + + find_instance_method_call(body_node, :man, :+) do |m| + next unless match = regex_match_group(parameters(m).first, %r{man[1-8]}) + problem "\"#{m.source}\" should be \"#{match[0]}\"" + end + # # Avoid hard-coding compilers # find_every_method_call_by_name(body_node, :system).each do |m| # param = parameters(m).first diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index b5ff3d1f49..c0cd754b3c 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -835,6 +835,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with man+ " do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def test + man1.install man+"man8" => "faad.1" + end + end + EOS + + expected_offenses = [{ message: "\"man+\"man8\"\" should be \"man8\"", + severity: :convention, + line: 5, + column: 22, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end end def expect_offense(expected, actual) expect(actual.message).to eq(expected[:message])