From 7c0a3a1233fe41a0a8510e4cd5055a0a4b799ff8 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 2 Jun 2017 12:26:23 +0200 Subject: [PATCH 1/2] Fix `rubocop` in `brew audit`. --- Library/Homebrew/cmd/style.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/style.rb b/Library/Homebrew/cmd/style.rb index e469c47bbb..7da71749cd 100644 --- a/Library/Homebrew/cmd/style.rb +++ b/Library/Homebrew/cmd/style.rb @@ -120,7 +120,7 @@ module Homebrew # exitstatus can also be nil if RuboCop process crashes, e.g. due to # native extension problems. # JSON needs to be at least 2 characters. - if !status.success? || json.to_s.length < 2 + if !(0..1).cover?(status.exitstatus) || json.to_s.length < 2 raise "Error running `rubocop --format json #{args.join " "}`" end RubocopResults.new(JSON.parse(json)) From 3064b5b3c301897f8229ccc4f3b5922bcae64ddf Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 2 Jun 2017 19:15:40 +0200 Subject: [PATCH 2/2] Add test for `brew style`. --- Library/Homebrew/test/cmd/style_spec.rb | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Library/Homebrew/test/cmd/style_spec.rb diff --git a/Library/Homebrew/test/cmd/style_spec.rb b/Library/Homebrew/test/cmd/style_spec.rb new file mode 100644 index 0000000000..3c4c3f8099 --- /dev/null +++ b/Library/Homebrew/test/cmd/style_spec.rb @@ -0,0 +1,34 @@ +require "cmd/style" + +describe "brew style" do + around(:each) do |example| + begin + FileUtils.ln_s HOMEBREW_LIBRARY_PATH, HOMEBREW_LIBRARY/"Homebrew" + FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop.yml", HOMEBREW_LIBRARY/".rubocop.yml" + + example.run + ensure + FileUtils.rm_f HOMEBREW_LIBRARY/"Homebrew" + FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop.yml" + end + end + + describe "Homebrew::check_style_json" do + let(:dir) { mktmpdir } + + it "returns RubocopResults when RuboCop reports offenses" do + formula = dir/"my-formula.rb" + + formula.write <<-'EOS'.undent + class MyFormula < Formula + + end + EOS + + rubocop_result = Homebrew.check_style_json([formula]) + + expect(rubocop_result.file_offenses(formula.realpath.to_s).map(&:message)) + .to include("Extra empty line detected at class body beginning.") + end + end +end