From 3edae73cd90cc9e6233718bfb48c5cc075aa0f36 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Wed, 2 Aug 2017 23:49:51 +0530 Subject: audit: Add tests for audit rules ported from line_problems method to rubocops --- Library/Homebrew/test/dev-cmd/audit_spec.rb | 22 ---- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 151 +++++++++++++++++++++++ 2 files changed, 151 insertions(+), 22 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/dev-cmd/audit_spec.rb b/Library/Homebrew/test/dev-cmd/audit_spec.rb index f2d8a8e7c..037865fdf 100644 --- a/Library/Homebrew/test/dev-cmd/audit_spec.rb +++ b/Library/Homebrew/test/dev-cmd/audit_spec.rb @@ -263,28 +263,6 @@ describe FormulaAuditor do expect(fa.problems.shift) .to eq('Use pkgshare instead of (share/"foolibc++")') end - - specify "no space in class inheritance" do - fa = formula_auditor "foo", <<-EOS.undent - class Foo do |s|\" is preferred over \"|longvar|\".", + severity: :convention, + line: 4, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + end +end -- cgit v1.2.3 From d9c81901c3a7f6ed112a99e9067d78fb9a2c3293 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Sat, 5 Aug 2017 14:58:09 +0530 Subject: audit: Add tests for rubocop methods in line_cop.rb --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 269 +++++++++++++++++++++++ 1 file changed, 269 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 122f8a364..293a415a5 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -200,5 +200,274 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with invalid rebuild" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + bottle do + rebuild 0 + sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra + end + end + EOS + + expected_offenses = [{ message: "'rebuild 0' should be removed", + severity: :convention, + line: 5, + column: 4, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with OS.linux? check" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + bottle do + if OS.linux? + nil + end + sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra + end + end + EOS + + expected_offenses = [{ message: "Don't use OS.linux?; Homebrew/core only supports macOS", + severity: :convention, + line: 5, + column: 7, + source: source }] + + inspect_source(cop, source, "/homebrew-core/") + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with fails_with :llvm" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + bottle do + sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra + end + fails_with :llvm do + build 2335 + cause "foo" + end + end + EOS + + expected_offenses = [{ message: "'fails_with :llvm' is now a no-op so should be removed", + severity: :convention, + line: 7, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with def test" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + + def test + assert_equals "1", "1" + end + end + EOS + + expected_offenses = [{ message: "Use new-style test definitions (test do)", + severity: :convention, + line: 5, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with def options" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + + def options + [["--bar", "desc"]] + end + end + EOS + + expected_offenses = [{ message: "Use new-style option definitions", + severity: :convention, + line: 5, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with deprecated skip_clean call" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + skip_clean :all + end + EOS + + expected_offenses = [{ message: "`skip_clean :all` is deprecated; brew no longer strips symbols\n" \ + "\tPass explicit paths to prevent Homebrew from removing empty folders.", + severity: :convention, + line: 4, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with build.universal?" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + if build.universal? + "foo" + end + end + EOS + + expected_offenses = [{ message: "macOS has been 64-bit only so build.universal? is deprecated.", + severity: :convention, + line: 4, + column: 5, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with ENV.universal_binary" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + if build? + ENV.universal_binary + end + end + EOS + + expected_offenses = [{ message: "macOS has been 64-bit only since 10.6 so ENV.universal_binary is deprecated.", + severity: :convention, + line: 5, + column: 5, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with ENV.universal_binary" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + if build? + ENV.x11 + end + end + EOS + + expected_offenses = [{ message: 'Use "depends_on :x11" instead of "ENV.x11"', + severity: :convention, + line: 5, + column: 5, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with ruby-macho alternatives" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + system "install_name_tool", "-id" + end + EOS + + expected_offenses = [{ message: 'Use ruby-macho instead of calling "install_name_tool"', + severity: :convention, + line: 4, + column: 10, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with npm install without language::Node args" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + system "npm", "install" + end + EOS + + expected_offenses = [{ message: "Use Language::Node for npm install args", + severity: :convention, + line: 4, + column: 17, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end end end -- cgit v1.2.3 From 686fc514cfd7ddd18484c37b177dc2b8298d129b Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Sat, 12 Aug 2017 23:28:08 +0530 Subject: Add tests for assert match and depends_on instance audit rules --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 68 ++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 293a415a5..aca9a7209 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -50,6 +50,12 @@ describe RuboCop::Cop::FormulaAudit::Lines do end end end + def expect_offense(expected, actual) + expect(actual.message).to eq(expected[:message]) + expect(actual.severity).to eq(expected[:severity]) + expect(actual.line).to eq(expected[:line]) + expect(actual.column).to eq(expected[:column]) + end end describe RuboCop::Cop::FormulaAudit::ClassInheritance do @@ -77,6 +83,12 @@ describe RuboCop::Cop::FormulaAudit::ClassInheritance do end end end + def expect_offense(expected, actual) + expect(actual.message).to eq(expected[:message]) + expect(actual.severity).to eq(expected[:severity]) + expect(actual.line).to eq(expected[:line]) + expect(actual.column).to eq(expected[:column]) + end end describe RuboCop::Cop::FormulaAudit::Comments do @@ -149,6 +161,12 @@ describe RuboCop::Cop::FormulaAudit::Comments do end end end + def expect_offense(expected, actual) + expect(actual.message).to eq(expected[:message]) + expect(actual.severity).to eq(expected[:severity]) + expect(actual.line).to eq(expected[:line]) + expect(actual.column).to eq(expected[:column]) + end end describe RuboCop::Cop::FormulaAudit::Miscellaneous do @@ -469,5 +487,55 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with assert include" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + assert File.read("inbox").include?("Sample message 1") + end + EOS + + expected_offenses = [{ message: "Use `assert_match` instead of `assert ...include?`", + severity: :convention, + line: 4, + column: 9, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "depends_on with an instance as an argument" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + depends_on FOO::BAR.new + end + EOS + + expected_offenses = [{ message: "`depends_on` can take requirement classes instead of instances", + severity: :convention, + line: 4, + column: 13, + 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]) + expect(actual.severity).to eq(expected[:severity]) + expect(actual.line).to eq(expected[:line]) + expect(actual.column).to eq(expected[:column]) end end -- cgit v1.2.3 From 77105b809a83583e3da5726105dc9cd913112913 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Sun, 13 Aug 2017 14:50:29 +0530 Subject: Add tests for macOS check --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index aca9a7209..69caee80c 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -527,6 +527,27 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do inspect_source(cop, source) + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + it "with old style OS check" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + depends_on :foo if MacOS.snow_leopard? + end + EOS + + expected_offenses = [{ message: "\"MacOS.snow_leopard?\" is deprecated, use a comparison to MacOS.version instead", + severity: :convention, + line: 4, + column: 21, + source: source }] + + inspect_source(cop, source) + expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end -- cgit v1.2.3 From a73c29fef21ccb7f45243500f04f1ed9965fdf38 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 14 Aug 2017 00:02:44 +0530 Subject: add tests for non glob dirs audit --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 69caee80c..203f8a7d9 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -552,6 +552,29 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with non glob DIR" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + rm_rf Dir["src/{llvm,test,librustdoc,etc/snapshot.pyc}"] + rm_rf Dir["src/snapshot.pyc"] + end + EOS + + expected_offenses = [{ message: "Dir([\"src/snapshot.pyc\"]) is unnecessary; just use \"src/snapshot.pyc\"", + severity: :convention, + line: 5, + column: 13, + 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]) -- cgit v1.2.3 From 7dfe09ccae5b1a8309326e5a5cb3172fbcd795d3 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 14 Aug 2017 01:09:06 +0530 Subject: Add tests for fileUtils call in system --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 203f8a7d9..1af5d2e72 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -571,6 +571,27 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do inspect_source(cop, source) + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + it "with system call to fileUtils Method" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + system "mkdir", "foo" + end + EOS + + expected_offenses = [{ message: "Use the `mkdir` Ruby method instead of `system \"mkdir\", \"foo\"`", + severity: :convention, + line: 4, + column: 10, + source: source }] + + inspect_source(cop, source) + expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end -- cgit v1.2.3 From 6dad9d8b44e22f2729a2db95a1c2d14b3e84d477 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 14 Aug 2017 01:25:44 +0530 Subject: Add test for top level method def --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 1af5d2e72..00543f545 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -592,6 +592,29 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do inspect_source(cop, source) + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + it "with a top-level function def " do + source = <<-EOS.undent + def test + nil + end + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + end + EOS + + expected_offenses = [{ message: "Define method test in the class body, not at the top-level", + severity: :convention, + line: 1, + column: 0, + source: source }] + + inspect_source(cop, source) + expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end -- cgit v1.2.3 From f968776e8460d7b6a0a3199d9c92c945cda0738d Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 14 Aug 2017 01:52:48 +0530 Subject: Add tests for unless build.without? --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 00543f545..352dc8219 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -619,6 +619,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with unless build.without?" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def post_install + return unless build.without? "bar" + end + end + EOS + + expected_offenses = [{ message: 'Use if build.with? "bar" instead of unless build.without? "bar"', + severity: :convention, + line: 5, + column: 18, + 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]) -- cgit v1.2.3 From ec2b0df10e62152529386cf2a696f9aaece405ea Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 14 Aug 2017 01:55:47 +0530 Subject: Add tests for unless build.with? --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 352dc8219..dda1b96e6 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -643,6 +643,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with unless build.with?" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def post_install + return unless build.with? "bar" + end + end + EOS + + expected_offenses = [{ message: 'Use if build.without? "bar" instead of unless build.with? "bar"', + severity: :convention, + line: 5, + column: 18, + 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]) -- cgit v1.2.3 From e14fedd1b35480ea3707689db044140d18662b9c Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 14 Aug 2017 02:14:20 +0530 Subject: Add test for negated build.with? --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index dda1b96e6..8e3f42adf 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -667,6 +667,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with negated build.with?" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def post_install + return if !build.with? "bar" + end + end + EOS + + expected_offenses = [{ message: "Don't negate 'build.with?': use 'build.without?'", + severity: :convention, + line: 5, + column: 14, + 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]) -- cgit v1.2.3 From 3efba57cd936f1e53b72a9e66561d594fcf37d65 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 14 Aug 2017 02:18:46 +0530 Subject: Add negated? method to formula cop and add tests for negated build.without? --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 8e3f42adf..e00834963 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -691,6 +691,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with negated build.with?" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def post_install + return if !build.without? "bar" + end + end + EOS + + expected_offenses = [{ message: "Don't negate 'build.without?': use 'build.with?'", + severity: :convention, + line: 5, + column: 14, + 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]) -- cgit v1.2.3 From 02a1406a2e4c2d0506861248eb767d99f5ce4515 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 14 Aug 2017 02:32:29 +0530 Subject: add test for build.without --without-foo --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index e00834963..0c225a5b6 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -715,6 +715,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with negated build.with?" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def post_install + return if build.without? "--without-bar" + end + end + EOS + + expected_offenses = [{ message: "Don't duplicate 'without': Use `build.without? \"bar\"` to check for \"--without-bar\"", + severity: :convention, + line: 5, + column: 30, + 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]) -- cgit v1.2.3 From 5a7cbb762f1a9e715ae03e82eb6cb8ef4ac4a0bb Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 14 Aug 2017 02:43:54 +0530 Subject: add test for build.with? "--with-foo" --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 26 +++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 0c225a5b6..273014cf1 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -716,7 +716,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with negated build.with?" do + it "with duplicated build.without?" do source = <<-EOS.undent class Foo < Formula desc "foo" @@ -739,6 +739,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with duplicated build.with?" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def post_install + return if build.with? "--with-bar" + end + end + EOS + + expected_offenses = [{ message: "Don't duplicate 'with': Use `build.with? \"bar\"` to check for \"--with-bar\"", + severity: :convention, + line: 5, + column: 27, + 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]) -- cgit v1.2.3 From 3ff8be1216388817dda2b4bb95aeaa5c3d3d5a6b Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 14 Aug 2017 02:47:29 +0530 Subject: add test for build.include? --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 273014cf1..36c6272b3 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -763,6 +763,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with build.include?" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def post_install + return if build.include? "without-bar" + end + end + EOS + + expected_offenses = [{ message: "Use build.without? \"bar\" instead of build.include? 'without-bar'", + severity: :convention, + line: 5, + column: 30, + 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]) -- cgit v1.2.3 From dc4d10ff6a59ce0da1bfc7bc06dd819c442813ab Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 14 Aug 2017 02:49:52 +0530 Subject: add test for build.include? having dashed args --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 36c6272b3..288ca8f8f 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -787,6 +787,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with build.include? with dashed args" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def post_install + return if build.include? "--bar" + end + end + EOS + + expected_offenses = [{ message: "Reference 'bar' without dashes", + severity: :convention, + line: 5, + column: 30, + 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]) -- cgit v1.2.3 From 76f4eccdceb5b3fb4e88b56e077234a6a3e56b08 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 14 Aug 2017 15:22:44 +0530 Subject: add test for using ARGV to check options --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 288ca8f8f..b5ff3d1f4 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -811,6 +811,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with using ARGV to check options" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def test + verbose = ARGV.verbose? + end + end + EOS + + expected_offenses = [{ message: "Use build instead of ARGV to check options", + severity: :convention, + line: 5, + column: 14, + 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]) -- cgit v1.2.3 From af5cd1a1da0e1b87696ae72b8a5f1c174e83e94e Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 14 Aug 2017 15:41:03 +0530 Subject: add tests for man+'man[1-8]' --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index b5ff3d1f4..c0cd754b3 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]) -- cgit v1.2.3 From 77468fdae36ee58580a643d8bc0fdd9f8b6e61c3 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 14 Aug 2017 19:58:39 +0530 Subject: add tests for hard coded compilers in system calls --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 48 ++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index c0cd754b3..7e901f0e2 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -859,6 +859,54 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with hardcoded compiler 1 " do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def test + system "/usr/bin/gcc", "foo" + end + end + EOS + + expected_offenses = [{ message: "Use \"\#{ENV.cc}\" instead of hard-coding \"gcc\"", + severity: :convention, + line: 5, + column: 12, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with hardcoded compiler 2 " do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def test + system "/usr/bin/g++", "-o", "foo", "foo.cc" + end + end + EOS + + expected_offenses = [{ message: "Use \"\#{ENV.cxx}\" instead of hard-coding \"g++\"", + severity: :convention, + line: 5, + column: 12, + 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]) -- cgit v1.2.3 From 65ae6bacd8c92d718b259f7efd50fc3fe9f0838b Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 14 Aug 2017 20:10:45 +0530 Subject: add tests for hardcoded compilers in ENV --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 56 ++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 4 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 7e901f0e2..afe65e9ac 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -817,7 +817,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - def test + def install verbose = ARGV.verbose? end end @@ -841,7 +841,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - def test + def install man1.install man+"man8" => "faad.1" end end @@ -865,7 +865,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - def test + def install system "/usr/bin/gcc", "foo" end end @@ -889,7 +889,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - def test + def install system "/usr/bin/g++", "-o", "foo", "foo.cc" end end @@ -907,6 +907,54 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with hardcoded compiler 3 " do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def install + ENV["COMPILER_PATH"] = "/usr/bin/llvm-g++" + end + end + EOS + + expected_offenses = [{ message: "Use \"\#{ENV.cxx}\" instead of hard-coding \"llvm-g++\"", + severity: :convention, + line: 5, + column: 28, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with hardcoded compiler 4 " do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def install + ENV["COMPILER_PATH"] = "/usr/bin/gcc" + end + end + EOS + + expected_offenses = [{ message: "Use \"\#{ENV.cc}\" instead of hard-coding \"gcc\"", + severity: :convention, + line: 5, + column: 28, + 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]) -- cgit v1.2.3 From 9c9c280c8aeb97a6ec8956242727208d80247826 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 14 Aug 2017 21:34:01 +0530 Subject: add tests for formula path string 1 --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index afe65e9ac..63ae88dd9 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -955,6 +955,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with formula path shortcut long form" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def install + mv "\#{share}/man", share + end + end + EOS + + expected_offenses = [{ message: "\"\#\{share}/man\" should be \"\#{man}\"", + severity: :convention, + line: 5, + column: 17, + 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]) -- cgit v1.2.3 From 063cbe7acdb0af0a4cd9bd35f29f89bc0d638d4a Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 14 Aug 2017 22:44:28 +0530 Subject: add tests for formula path shortucut 3 --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 72 ++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 63ae88dd9..1d25c4721 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -979,6 +979,78 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with formula path shortcut long form 1" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def install + mv "\#{prefix}/libexec", share + end + end + EOS + + expected_offenses = [{ message: "\"\#\{prefix}/libexec\" should be \"\#{libexec}\"", + severity: :convention, + line: 5, + column: 18, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with formula path shortcut long form 2" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def install + system "./configure", "--INFODIR=\#{prefix}/share/info" + end + end + EOS + + expected_offenses = [{ message: "\"\#\{prefix}/share/info\" should be \"\#{info}\"", + severity: :convention, + line: 5, + column: 47, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + it "with formula path shortcut long form 3" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def install + system "./configure", "--MANDIR=\#{prefix}/share/man/man8" + end + end + EOS + + expected_offenses = [{ message: "\"\#\{prefix}/share/man/man8\" should be \"\#{man8}\"", + severity: :convention, + line: 5, + column: 46, + 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]) -- cgit v1.2.3 From 64a929184a45f530a49af7b047d5b6605b50b1f8 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 14 Aug 2017 23:05:00 +0530 Subject: add tests for vendored deps --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 1d25c4721..f3626cdce 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -1051,6 +1051,28 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end + it "with dependecies which have to vendored" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + depends_on "lpeg" => :lua51 + end + EOS + + expected_offenses = [{ message: "lua modules should be vendored rather than use deprecated depends_on \"lpeg\" => :lua51`", + severity: :convention, + line: 4, + column: 24, + 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]) -- cgit v1.2.3 From d2a7314f538f919e9b09e4b27c1f86b7d3d2eda2 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 14 Aug 2017 23:32:06 +0530 Subject: add test for env mod through system call --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index f3626cdce..be2b63c47 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -1073,6 +1073,28 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end + it "with setting env manually" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + system "export", "var=value" + end + EOS + + expected_offenses = [{ message: "Use ENV instead of invoking 'export' to modify the environment", + severity: :convention, + line: 4, + column: 10, + 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]) -- cgit v1.2.3 From cfc423e1839442f605072db14aac42f6f5fa6174 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Tue, 15 Aug 2017 00:05:50 +0530 Subject: add tests for dependencies --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index be2b63c47..1273ef9c9 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -1095,6 +1095,28 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end + it "with dependencies with invalid options" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + depends_on "foo" => "with-bar" + end + EOS + + expected_offenses = [{ message: "Dependency foo should not use option with-bar", + severity: :convention, + line: 4, + column: 13, + 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]) -- cgit v1.2.3 From 5744cd9066bbdfc4db5332a202ddb962d5359ee5 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Tue, 15 Aug 2017 00:29:58 +0530 Subject: add test for inspecting version --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 1273ef9c9..f24a6b09d 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -1117,6 +1117,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end + it "with inspecting version" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + if version == "HEAD" + foo() + end + end + EOS + + expected_offenses = [{ message: "Use 'build.head?' instead of inspecting 'version'", + severity: :convention, + line: 4, + column: 5, + 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]) -- cgit v1.2.3 From 3fc6cc1a3a4b8f1b7ca42dc0a7dd7cf8fad91b18 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Tue, 15 Aug 2017 00:32:34 +0530 Subject: add test for ENV.fortran --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index f24a6b09d..1b23cca83 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -1141,6 +1141,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end + it "with ENV.fortran" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + test do + ENV.fortran + end + end + EOS + + expected_offenses = [{ message: "Use `depends_on :fortran` instead of `ENV.fortran`", + severity: :convention, + line: 5, + column: 4, + 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]) -- cgit v1.2.3 From 2f94d5f499bca6bbab238bb6536f05195b358159 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Tue, 15 Aug 2017 00:36:37 +0530 Subject: add test for ARGV.include? --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 1b23cca83..44f22df62 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -1165,6 +1165,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end + it "with ARGV.include? (--HEAD)" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + test do + head = ARGV.include? "--HEAD" + end + end + EOS + + expected_offenses = [{ message: "Use \"if build.head?\" instead", + severity: :convention, + line: 5, + column: 26, + 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]) -- cgit v1.2.3 From efabd4b5c2beadecf3282dbe730b1b6f779571e0 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Tue, 15 Aug 2017 00:42:56 +0530 Subject: Add tests for MACOS version consts usage --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 44f22df62..b069148f9 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -1189,6 +1189,30 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end + it "with MACOS_VERSION const" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + test do + version = MACOS_VERSION + end + end + EOS + + expected_offenses = [{ message: "Use MacOS.version instead of MACOS_VERSION", + severity: :convention, + line: 5, + column: 14, + 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]) -- cgit v1.2.3 From afdd0e2437426ec85ff86e5b7562d3a6a69ba3e5 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Tue, 15 Aug 2017 16:09:32 +0530 Subject: add tests for condition dependencies --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 66 ++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index b069148f9..6f1f8a48c 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -1213,6 +1213,72 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end + it "with if conditional dep" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + depends_on "foo" if build.with? "with-foo" + end + EOS + + expected_offenses = [{ message: 'Replace depends_on "foo" if build.with? "with-foo" with depends_on "foo" => :optional', + severity: :convention, + line: 4, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with unless conditional dep and symbol" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + depends_on :foo unless build.without? "foo" + end + EOS + + expected_offenses = [{ message: 'Replace depends_on :foo unless build.without? "foo" with depends_on :foo => :recommended', + severity: :convention, + line: 4, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with unless conditional dep with build.include?" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + depends_on :foo unless build.include? "without-foo" + end + EOS + + expected_offenses = [{ message: 'Replace depends_on :foo unless build.include? "without-foo" with depends_on :foo => :recommended', + severity: :convention, + line: 4, + column: 2, + 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]) -- cgit v1.2.3 From ee35d6586791be65b9cfbb976394c9191625aaee Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Sat, 21 Oct 2017 12:50:49 +0530 Subject: lines_cop: Refactor to multiple cops and fix style violations --- Library/Homebrew/test/rubocops/lines_cop_spec.rb | 1044 +++++++++++----------- 1 file changed, 526 insertions(+), 518 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index df4085721..9705e8278 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -7,7 +7,7 @@ describe RuboCop::Cop::FormulaAudit::Lines do subject(:cop) { described_class.new } context "When auditing lines" do - it "with correctable deprecated dependencies" do + it "correctable deprecated dependencies usage" do formulae = [{ "dependency" => :automake, "correct" => "automake", @@ -36,11 +36,11 @@ describe RuboCop::Cop::FormulaAudit::Lines do else offense = ":#{formula["dependency"]} is deprecated" end - expected_offenses = [{ message: offense, - severity: :convention, - line: 3, - column: 2, - source: source }] + expected_offenses = [{ message: offense, + severity: :convention, + line: 3, + column: 2, + source: source }] inspect_source(source) @@ -56,7 +56,7 @@ describe RuboCop::Cop::FormulaAudit::ClassInheritance do subject(:cop) { described_class.new } context "When auditing lines" do - it "with no space in class inheritance" do + it "inconsistent space in class inheritance" do source = <<-EOS.undent class Foo do |s|\" is preferred over \"|longvar|\".", - severity: :convention, - line: 4, - column: 2, - source: source }] + expected_offenses = [{ message: 'Use `assert_predicate , :exist?` instead of `assert File.exist? "default.ini"`', + severity: :convention, + line: 4, + column: 9, + source: source }] - inspect_source(source) + inspect_source(source) - expected_offenses.zip(cop.offenses).each do |expected, actual| - expect_offense(expected, actual) - end + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) end + end - it "with invalid rebuild" do - source = <<-EOS.undent + it "assert ...exist? with a negation" do + source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - bottle do - rebuild 0 - sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra - end + assert !File.exist?("default.ini") end - EOS + EOS - expected_offenses = [{ message: "'rebuild 0' should be removed", - severity: :convention, - line: 5, - column: 4, - source: source }] + expected_offenses = [{ message: 'Use `refute_predicate , :exist?` instead of `assert !File.exist?("default.ini")`', + severity: :convention, + line: 4, + column: 9, + source: source }] - inspect_source(source) + inspect_source(source) - expected_offenses.zip(cop.offenses).each do |expected, actual| - expect_offense(expected, actual) - end + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) end + end - it "with OS.linux? check" do - source = <<-EOS.undent + it "assert ...executable? without a negation" do + source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - bottle do - if OS.linux? - nil - end - sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra - end + assert File.executable? f end - EOS + EOS - expected_offenses = [{ message: "Don't use OS.linux?; Homebrew/core only supports macOS", - severity: :convention, - line: 5, - column: 7, - source: source }] + expected_offenses = [{ message: "Use `assert_predicate , :executable?` instead of `assert File.executable? f`", + severity: :convention, + line: 4, + column: 9, + source: source }] - inspect_source(source, "/homebrew-core/") + inspect_source(source) - expected_offenses.zip(cop.offenses).each do |expected, actual| - expect_offense(expected, actual) - end + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) end + end +end - it "with fails_with :llvm" do - source = <<-EOS.undent +describe RuboCop::Cop::FormulaAudit::OptionDeclarations do + subject(:cop) { described_class.new } + + it "unless build.without? conditional" do + source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - bottle do - sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra - end - fails_with :llvm do - build 2335 - cause "foo" + def post_install + return unless build.without? "bar" end end - EOS + EOS - expected_offenses = [{ message: "'fails_with :llvm' is now a no-op so should be removed", - severity: :convention, - line: 7, - column: 2, - source: source }] + expected_offenses = [{ message: 'Use if build.with? "bar" instead of unless build.without? "bar"', + severity: :convention, + line: 5, + column: 18, + source: source }] - inspect_source(source) + inspect_source(source) - expected_offenses.zip(cop.offenses).each do |expected, actual| - expect_offense(expected, actual) - end + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) end + end - it "with def test" do - source = <<-EOS.undent + it "unless build.with? conditional" do + source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - - def test - assert_equals "1", "1" + def post_install + return unless build.with? "bar" end end - EOS + EOS - expected_offenses = [{ message: "Use new-style test definitions (test do)", - severity: :convention, - line: 5, - column: 2, - source: source }] + expected_offenses = [{ message: 'Use if build.without? "bar" instead of unless build.with? "bar"', + severity: :convention, + line: 5, + column: 18, + source: source }] - inspect_source(source) + inspect_source(source) - expected_offenses.zip(cop.offenses).each do |expected, actual| - expect_offense(expected, actual) - end + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) end + end - it "with def options" do - source = <<-EOS.undent + it "negated build.with? conditional" do + source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - - def options - [["--bar", "desc"]] + def post_install + return if !build.with? "bar" end end - EOS + EOS - expected_offenses = [{ message: "Use new-style option definitions", - severity: :convention, - line: 5, - column: 2, - source: source }] + expected_offenses = [{ message: "Don't negate 'build.with?': use 'build.without?'", + severity: :convention, + line: 5, + column: 14, + source: source }] - inspect_source(source) + inspect_source(source) - expected_offenses.zip(cop.offenses).each do |expected, actual| - expect_offense(expected, actual) - end + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) end + end - it "with deprecated skip_clean call" do - source = <<-EOS.undent + it "negated build.without? conditional" do + source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - skip_clean :all + def post_install + return if !build.without? "bar" + end end - EOS + EOS - expected_offenses = [{ message: <<-EOS.undent.chomp, - `skip_clean :all` is deprecated; brew no longer strips symbols - Pass explicit paths to prevent Homebrew from removing empty folders. - EOS - severity: :convention, - line: 4, - column: 2, - source: source }] + expected_offenses = [{ message: "Don't negate 'build.without?': use 'build.with?'", + severity: :convention, + line: 5, + column: 14, + source: source }] - inspect_source(source) + inspect_source(source) - expected_offenses.zip(cop.offenses).each do |expected, actual| - expect_offense(expected, actual) - end + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) end + end - it "with build.universal?" do - source = <<-EOS.undent + it "unnecessary build.without? conditional" do + source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - if build.universal? - "foo" + def post_install + return if build.without? "--without-bar" end end - EOS + EOS - expected_offenses = [{ message: "macOS has been 64-bit only since 10.6 so build.universal? is deprecated.", - severity: :convention, - line: 4, - column: 5, - source: source }] + expected_offenses = [{ message: "Don't duplicate 'without': Use `build.without? \"bar\"` to check for \"--without-bar\"", + severity: :convention, + line: 5, + column: 30, + source: source }] - inspect_source(source) + inspect_source(source) - expected_offenses.zip(cop.offenses).each do |expected, actual| - expect_offense(expected, actual) - end + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) end + end - it "with build.universal? exempted formula" do - source = <<-EOS.undent - class Wine < Formula + it "unnecessary build.with? conditional" do + source = <<-EOS.undent + class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - if build.universal? - "foo" + def post_install + return if build.with? "--with-bar" end end - EOS + EOS - inspect_source(source, "/homebrew-core/Formula/wine.rb") - expect(cop.offenses).to eq([]) + expected_offenses = [{ message: "Don't duplicate 'with': Use `build.with? \"bar\"` to check for \"--with-bar\"", + severity: :convention, + line: 5, + column: 27, + source: source }] + + inspect_source(source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) end + end - it "with ENV.universal_binary" do - source = <<-EOS.undent + it "build.include? conditional" do + source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - if build? - ENV.universal_binary + def post_install + return if build.include? "without-bar" end end - EOS + EOS - expected_offenses = [{ message: "macOS has been 64-bit only since 10.6 so ENV.universal_binary is deprecated.", - severity: :convention, - line: 5, - column: 5, - source: source }] + expected_offenses = [{ message: "Use build.without? \"bar\" instead of build.include? 'without-bar'", + severity: :convention, + line: 5, + column: 30, + source: source }] - inspect_source(source) + inspect_source(source) - expected_offenses.zip(cop.offenses).each do |expected, actual| - expect_offense(expected, actual) - end + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) end + end - it "with ENV.universal_binary 2" do - source = <<-EOS.undent + it "build.include? with dashed args conditional" do + source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - if build? - ENV.x11 + def post_install + return if build.include? "--bar" end end - EOS + EOS - expected_offenses = [{ message: 'Use "depends_on :x11" instead of "ENV.x11"', - severity: :convention, - line: 5, - column: 5, - source: source }] + expected_offenses = [{ message: "Reference 'bar' without dashes", + severity: :convention, + line: 5, + column: 30, + source: source }] - inspect_source(source) + inspect_source(source) - expected_offenses.zip(cop.offenses).each do |expected, actual| - expect_offense(expected, actual) - end + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) end + end - it "with ruby-macho alternatives" do - source = <<-EOS.undent + it "def options usage" do + source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - system "install_name_tool", "-id" + + def options + [["--bar", "desc"]] + end end - EOS + EOS - expected_offenses = [{ message: 'Use ruby-macho instead of calling "install_name_tool"', - severity: :convention, - line: 4, - column: 10, - source: source }] + expected_offenses = [{ message: "Use new-style option definitions", + severity: :convention, + line: 5, + column: 2, + source: source }] - inspect_source(source) + inspect_source(source) - expected_offenses.zip(cop.offenses).each do |expected, actual| - expect_offense(expected, actual) - end + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) end + end +end - it "with ruby-macho alternatives audit exempted formula" do - source = <<-EOS.undent - class Cctools < Formula - desc "foo" - url 'http://example.com/foo-1.0.tgz' - system "install_name_tool", "-id" - end - EOS - - inspect_source(source, "/homebrew-core/Formula/cctools.rb") - expect(cop.offenses).to eq([]) - end +describe RuboCop::Cop::FormulaAudit::Miscellaneous do + subject(:cop) { described_class.new } - it "with npm install without language::Node args" do + context "When auditing formula" do + it "FileUtils usage" do source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - system "npm", "install" + FileUtils.mv "hello" end EOS - expected_offenses = [{ message: "Use Language::Node for npm install args", - severity: :convention, - line: 4, - column: 2, - source: source }] + expected_offenses = [{ message: "Don't need 'FileUtils.' before mv", + severity: :convention, + line: 4, + column: 2, + source: source }] inspect_source(source) @@ -500,33 +490,22 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with npm install without language::Node args in kibana" do - source = <<-EOS.undent - class KibanaAT44 < Formula - desc "foo" - url 'http://example.com/foo-1.0.tgz' - system "npm", "install" - end - EOS - - inspect_source(source, "/homebrew-core/Formula/kibana@4.4.rb") - expect(cop.offenses).to eq([]) - end - - it "with assert include" do + it "long inreplace block vars" do source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - assert File.read("inbox").include?("Sample message 1") + inreplace "foo" do |longvar| + somerandomCall(longvar) + end end EOS - expected_offenses = [{ message: "Use `assert_match` instead of `assert ...include?`", - severity: :convention, - line: 4, - column: 9, - source: source }] + expected_offenses = [{ message: "\"inreplace do |s|\" is preferred over \"|longvar|\".", + severity: :convention, + line: 4, + column: 2, + source: source }] inspect_source(source) @@ -535,20 +514,23 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "assert ...exist? without a negation" do + it "invalid rebuild statement" do source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - assert File.exist? "default.ini" + bottle do + rebuild 0 + sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra + end end EOS - expected_offenses = [{ message: 'Use `assert_predicate , :exist?` instead of `assert File.exist? "default.ini"`', - severity: :convention, - line: 4, - column: 9, - source: source }] + expected_offenses = [{ message: "'rebuild 0' should be removed", + severity: :convention, + line: 5, + column: 4, + source: source }] inspect_source(source) @@ -557,42 +539,53 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "assert ...exist? with a negation" do + it "OS.linux? check" do source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - assert !File.exist?("default.ini") + bottle do + if OS.linux? + nil + end + sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra + end end EOS - expected_offenses = [{ message: 'Use `refute_predicate , :exist?` instead of `assert !File.exist?("default.ini")`', - severity: :convention, - line: 4, - column: 9, - source: source }] + expected_offenses = [{ message: "Don't use OS.linux?; Homebrew/core only supports macOS", + severity: :convention, + line: 5, + column: 7, + source: source }] - inspect_source(source) + inspect_source(source, "/homebrew-core/") expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end end - it "assert ...executable? without a negation" do + it "fails_with :llvm block" do source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - assert File.executable? f + bottle do + sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra + end + fails_with :llvm do + build 2335 + cause "foo" + end end EOS - expected_offenses = [{ message: "Use `assert_predicate , :executable?` instead of `assert File.executable? f`", - severity: :convention, - line: 4, - column: 9, - source: source }] + expected_offenses = [{ message: "'fails_with :llvm' is now a no-op so should be removed", + severity: :convention, + line: 7, + column: 2, + source: source }] inspect_source(source) @@ -601,20 +594,23 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "depends_on with an instance as an argument" do + it "def test deprecated usage" do source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - depends_on FOO::BAR.new + + def test + assert_equals "1", "1" + end end EOS - expected_offenses = [{ message: "`depends_on` can take requirement classes instead of instances", - severity: :convention, - line: 4, - column: 13, - source: source }] + expected_offenses = [{ message: "Use new-style test definitions (test do)", + severity: :convention, + line: 5, + column: 2, + source: source }] inspect_source(source) @@ -623,20 +619,23 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with old style OS check" do + it "deprecated skip_clean call" do source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - depends_on :foo if MacOS.snow_leopard? + skip_clean :all end EOS - expected_offenses = [{ message: "\"MacOS.snow_leopard?\" is deprecated, use a comparison to MacOS.version instead", - severity: :convention, - line: 4, - column: 21, - source: source }] + expected_offenses = [{ message: <<-EOS.undent.chomp, + `skip_clean :all` is deprecated; brew no longer strips symbols + Pass explicit paths to prevent Homebrew from removing empty folders. + EOS + severity: :convention, + line: 4, + column: 2, + source: source }] inspect_source(source) @@ -645,21 +644,22 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with non glob DIR" do + it "build.universal? deprecated usage" do source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - rm_rf Dir["src/{llvm,test,librustdoc,etc/snapshot.pyc}"] - rm_rf Dir["src/snapshot.pyc"] + if build.universal? + "foo" + end end EOS - expected_offenses = [{ message: "Dir([\"src/snapshot.pyc\"]) is unnecessary; just use \"src/snapshot.pyc\"", - severity: :convention, - line: 5, - column: 13, - source: source }] + expected_offenses = [{ message: "macOS has been 64-bit only since 10.6 so build.universal? is deprecated.", + severity: :convention, + line: 4, + column: 5, + source: source }] inspect_source(source) @@ -668,44 +668,37 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with system call to fileUtils Method" do + it "build.universal? deprecation exempted formula" do source = <<-EOS.undent - class Foo < Formula + class Wine < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - system "mkdir", "foo" + if build.universal? + "foo" + end end EOS - expected_offenses = [{ message: "Use the `mkdir` Ruby method instead of `system \"mkdir\", \"foo\"`", - severity: :convention, - line: 4, - column: 10, - source: source }] - - inspect_source(source) - - expected_offenses.zip(cop.offenses).each do |expected, actual| - expect_offense(expected, actual) - end + inspect_source(source, "/homebrew-core/Formula/wine.rb") + expect(cop.offenses).to eq([]) end - it "with a top-level function def " do + it "deprecated ENV.universal_binary usage" do source = <<-EOS.undent - def test - nil - end class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' + if build? + ENV.universal_binary + end end EOS - expected_offenses = [{ message: "Define method test in the class body, not at the top-level", - severity: :convention, - line: 1, - column: 0, - source: source }] + expected_offenses = [{ message: "macOS has been 64-bit only since 10.6 so ENV.universal_binary is deprecated.", + severity: :convention, + line: 5, + column: 5, + source: source }] inspect_source(source) @@ -714,22 +707,22 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with unless build.without?" do + it "deprecated ENV.x11 usage" do source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - def post_install - return unless build.without? "bar" + if build? + ENV.x11 end end EOS - expected_offenses = [{ message: 'Use if build.with? "bar" instead of unless build.without? "bar"', - severity: :convention, - line: 5, - column: 18, - source: source }] + expected_offenses = [{ message: 'Use "depends_on :x11" instead of "ENV.x11"', + severity: :convention, + line: 5, + column: 5, + source: source }] inspect_source(source) @@ -738,22 +731,20 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with unless build.with?" do + it "ruby-macho alternative to install_name_tool usage" do source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - def post_install - return unless build.with? "bar" - end + system "install_name_tool", "-id" end EOS - expected_offenses = [{ message: 'Use if build.without? "bar" instead of unless build.with? "bar"', - severity: :convention, - line: 5, - column: 18, - source: source }] + expected_offenses = [{ message: 'Use ruby-macho instead of calling "install_name_tool"', + severity: :convention, + line: 4, + column: 10, + source: source }] inspect_source(source) @@ -762,22 +753,33 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with negated build.with?" do + it "ruby-macho alternatives audit exempted formula" do + source = <<-EOS.undent + class Cctools < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + system "install_name_tool", "-id" + end + EOS + + inspect_source(source, "/homebrew-core/Formula/cctools.rb") + expect(cop.offenses).to eq([]) + end + + it "npm install without language::Node args" do source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - def post_install - return if !build.with? "bar" - end + system "npm", "install" end EOS - expected_offenses = [{ message: "Don't negate 'build.with?': use 'build.without?'", - severity: :convention, - line: 5, - column: 14, - source: source }] + expected_offenses = [{ message: "Use Language::Node for npm install args", + severity: :convention, + line: 4, + column: 2, + source: source }] inspect_source(source) @@ -786,22 +788,33 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with negated build.with?" do + it "npm install without language::Node args in kibana(exempted formula)" do + source = <<-EOS.undent + class KibanaAT44 < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + system "npm", "install" + end + EOS + + inspect_source(source, "/homebrew-core/Formula/kibana@4.4.rb") + expect(cop.offenses).to eq([]) + end + + it "depends_on with an instance as argument" do source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - def post_install - return if !build.without? "bar" - end + depends_on FOO::BAR.new end EOS - expected_offenses = [{ message: "Don't negate 'build.without?': use 'build.with?'", - severity: :convention, - line: 5, - column: 14, - source: source }] + expected_offenses = [{ message: "`depends_on` can take requirement classes instead of instances", + severity: :convention, + line: 4, + column: 13, + source: source }] inspect_source(source) @@ -810,22 +823,20 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with duplicated build.without?" do + it "old style OS check" do source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - def post_install - return if build.without? "--without-bar" - end + depends_on :foo if MacOS.snow_leopard? end EOS - expected_offenses = [{ message: "Don't duplicate 'without': Use `build.without? \"bar\"` to check for \"--without-bar\"", - severity: :convention, - line: 5, - column: 30, - source: source }] + expected_offenses = [{ message: "\"MacOS.snow_leopard?\" is deprecated, use a comparison to MacOS.version instead", + severity: :convention, + line: 4, + column: 21, + source: source }] inspect_source(source) @@ -834,22 +845,21 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with duplicated build.with?" do + it "non glob DIR usage" do source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - def post_install - return if build.with? "--with-bar" - end + rm_rf Dir["src/{llvm,test,librustdoc,etc/snapshot.pyc}"] + rm_rf Dir["src/snapshot.pyc"] end EOS - expected_offenses = [{ message: "Don't duplicate 'with': Use `build.with? \"bar\"` to check for \"--with-bar\"", - severity: :convention, - line: 5, - column: 27, - source: source }] + expected_offenses = [{ message: 'Dir(["src/snapshot.pyc"]) is unnecessary; just use "src/snapshot.pyc"', + severity: :convention, + line: 5, + column: 13, + source: source }] inspect_source(source) @@ -858,22 +868,20 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with build.include?" do + it "system call to fileUtils Method" do source = <<-EOS.undent class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - def post_install - return if build.include? "without-bar" - end + system "mkdir", "foo" end EOS - expected_offenses = [{ message: "Use build.without? \"bar\" instead of build.include? 'without-bar'", - severity: :convention, - line: 5, - column: 30, - source: source }] + expected_offenses = [{ message: 'Use the `mkdir` Ruby method instead of `system "mkdir", "foo"`', + severity: :convention, + line: 4, + column: 10, + source: source }] inspect_source(source) @@ -882,22 +890,22 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with build.include? with dashed args" do + it "top-level function def outside class body" do source = <<-EOS.undent + def test + nil + end class Foo < Formula desc "foo" url 'http://example.com/foo-1.0.tgz' - def post_install - return if build.include? "--bar" - end end EOS - expected_offenses = [{ message: "Reference 'bar' without dashes", - severity: :convention, - line: 5, - column: 30, - source: source }] + expected_offenses = [{ message: "Define method test in the class body, not at the top-level", + severity: :convention, + line: 1, + column: 0, + source: source }] inspect_source(source) @@ -906,7 +914,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with using ARGV to check options" do + it "Using ARGV to check options" do source = <<-EOS.undent class Foo < Formula desc "foo" @@ -917,11 +925,11 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - expected_offenses = [{ message: "Use build instead of ARGV to check options", - severity: :convention, - line: 5, - column: 14, - source: source }] + expected_offenses = [{ message: "Use build instead of ARGV to check options", + severity: :convention, + line: 5, + column: 14, + source: source }] inspect_source(source) @@ -930,7 +938,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with man+ " do + it 'man+"man8" usage' do source = <<-EOS.undent class Foo < Formula desc "foo" @@ -941,11 +949,11 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - expected_offenses = [{ message: "\"man+\"man8\"\" should be \"man8\"", - severity: :convention, - line: 5, - column: 22, - source: source }] + expected_offenses = [{ message: '"man+"man8"" should be "man8"', + severity: :convention, + line: 5, + column: 22, + source: source }] inspect_source(source) @@ -954,7 +962,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with hardcoded compiler 1 " do + it "hardcoded gcc compiler" do source = <<-EOS.undent class Foo < Formula desc "foo" @@ -965,11 +973,11 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - expected_offenses = [{ message: "Use \"\#{ENV.cc}\" instead of hard-coding \"gcc\"", - severity: :convention, - line: 5, - column: 12, - source: source }] + expected_offenses = [{ message: "Use \"\#{ENV.cc}\" instead of hard-coding \"gcc\"", + severity: :convention, + line: 5, + column: 12, + source: source }] inspect_source(source) @@ -978,7 +986,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with hardcoded compiler 2 " do + it "hardcoded g++ compiler" do source = <<-EOS.undent class Foo < Formula desc "foo" @@ -989,11 +997,11 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - expected_offenses = [{ message: "Use \"\#{ENV.cxx}\" instead of hard-coding \"g++\"", - severity: :convention, - line: 5, - column: 12, - source: source }] + expected_offenses = [{ message: "Use \"\#{ENV.cxx}\" instead of hard-coding \"g++\"", + severity: :convention, + line: 5, + column: 12, + source: source }] inspect_source(source) @@ -1002,7 +1010,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with hardcoded compiler 3 " do + it "hardcoded llvm-g++ compiler" do source = <<-EOS.undent class Foo < Formula desc "foo" @@ -1013,11 +1021,11 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - expected_offenses = [{ message: "Use \"\#{ENV.cxx}\" instead of hard-coding \"llvm-g++\"", - severity: :convention, - line: 5, - column: 28, - source: source }] + expected_offenses = [{ message: "Use \"\#{ENV.cxx}\" instead of hard-coding \"llvm-g++\"", + severity: :convention, + line: 5, + column: 28, + source: source }] inspect_source(source) @@ -1026,7 +1034,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with hardcoded compiler 4 " do + it "hardcoded gcc compiler" do source = <<-EOS.undent class Foo < Formula desc "foo" @@ -1037,11 +1045,11 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - expected_offenses = [{ message: "Use \"\#{ENV.cc}\" instead of hard-coding \"gcc\"", - severity: :convention, - line: 5, - column: 28, - source: source }] + expected_offenses = [{ message: "Use \"\#{ENV.cc}\" instead of hard-coding \"gcc\"", + severity: :convention, + line: 5, + column: 28, + source: source }] inspect_source(source) @@ -1050,7 +1058,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with formula path shortcut long form" do + it "formula path shortcut : man" do source = <<-EOS.undent class Foo < Formula desc "foo" @@ -1061,11 +1069,11 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - expected_offenses = [{ message: "\"\#\{share}/man\" should be \"\#{man}\"", - severity: :convention, - line: 5, - column: 17, - source: source }] + expected_offenses = [{ message: '"#{share}/man" should be "#{man}"', + severity: :convention, + line: 5, + column: 17, + source: source }] inspect_source(source) @@ -1074,7 +1082,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with formula path shortcut long form 1" do + it "formula path shortcut : libexec" do source = <<-EOS.undent class Foo < Formula desc "foo" @@ -1085,11 +1093,11 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - expected_offenses = [{ message: "\"\#\{prefix}/libexec\" should be \"\#{libexec}\"", - severity: :convention, - line: 5, - column: 18, - source: source }] + expected_offenses = [{ message: "\"\#\{prefix}/libexec\" should be \"\#{libexec}\"", + severity: :convention, + line: 5, + column: 18, + source: source }] inspect_source(source) @@ -1098,7 +1106,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with formula path shortcut long form 2" do + it "formula path shortcut : info" do source = <<-EOS.undent class Foo < Formula desc "foo" @@ -1109,11 +1117,11 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - expected_offenses = [{ message: "\"\#\{prefix}/share/info\" should be \"\#{info}\"", - severity: :convention, - line: 5, - column: 47, - source: source }] + expected_offenses = [{ message: "\"\#\{prefix}/share/info\" should be \"\#{info}\"", + severity: :convention, + line: 5, + column: 47, + source: source }] inspect_source(source) @@ -1122,7 +1130,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with formula path shortcut long form 3" do + it "formula path shortcut : man8" do source = <<-EOS.undent class Foo < Formula desc "foo" @@ -1133,11 +1141,11 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - expected_offenses = [{ message: "\"\#\{prefix}/share/man/man8\" should be \"\#{man8}\"", - severity: :convention, - line: 5, - column: 46, - source: source }] + expected_offenses = [{ message: "\"\#\{prefix}/share/man/man8\" should be \"\#{man8}\"", + severity: :convention, + line: 5, + column: 46, + source: source }] inspect_source(source) @@ -1146,7 +1154,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with dependecies which have to vendored" do + it "dependecies which have to vendored" do source = <<-EOS.undent class Foo < Formula desc "foo" @@ -1155,11 +1163,11 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - expected_offenses = [{ message: "lua modules should be vendored rather than use deprecated depends_on \"lpeg\" => :lua51`", - severity: :convention, - line: 4, - column: 24, - source: source }] + expected_offenses = [{ message: "lua modules should be vendored rather than use deprecated depends_on \"lpeg\" => :lua51`", + severity: :convention, + line: 4, + column: 24, + source: source }] inspect_source(source) @@ -1168,7 +1176,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with setting env manually" do + it "manually setting env" do source = <<-EOS.undent class Foo < Formula desc "foo" @@ -1177,11 +1185,11 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - expected_offenses = [{ message: "Use ENV instead of invoking 'export' to modify the environment", - severity: :convention, - line: 4, - column: 10, - source: source }] + expected_offenses = [{ message: "Use ENV instead of invoking 'export' to modify the environment", + severity: :convention, + line: 4, + column: 10, + source: source }] inspect_source(source) @@ -1190,7 +1198,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with dependencies with invalid options" do + it "dependencies with invalid options" do source = <<-EOS.undent class Foo < Formula desc "foo" @@ -1199,11 +1207,11 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - expected_offenses = [{ message: "Dependency foo should not use option with-bar", - severity: :convention, - line: 4, - column: 13, - source: source }] + expected_offenses = [{ message: "Dependency foo should not use option with-bar", + severity: :convention, + line: 4, + column: 13, + source: source }] inspect_source(source) @@ -1212,7 +1220,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with inspecting version" do + it "inspecting version manually" do source = <<-EOS.undent class Foo < Formula desc "foo" @@ -1223,11 +1231,11 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - expected_offenses = [{ message: "Use 'build.head?' instead of inspecting 'version'", - severity: :convention, - line: 4, - column: 5, - source: source }] + expected_offenses = [{ message: "Use 'build.head?' instead of inspecting 'version'", + severity: :convention, + line: 4, + column: 5, + source: source }] inspect_source(source) @@ -1236,7 +1244,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with ENV.fortran" do + it "deprecated ENV.fortran usage" do source = <<-EOS.undent class Foo < Formula desc "foo" @@ -1247,11 +1255,11 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - expected_offenses = [{ message: "Use `depends_on :fortran` instead of `ENV.fortran`", - severity: :convention, - line: 5, - column: 4, - source: source }] + expected_offenses = [{ message: "Use `depends_on :fortran` instead of `ENV.fortran`", + severity: :convention, + line: 5, + column: 4, + source: source }] inspect_source(source) @@ -1260,7 +1268,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with ARGV.include? (--HEAD)" do + it "deprecated ARGV.include? (--HEAD) usage" do source = <<-EOS.undent class Foo < Formula desc "foo" @@ -1271,11 +1279,11 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - expected_offenses = [{ message: "Use \"if build.head?\" instead", - severity: :convention, - line: 5, - column: 26, - source: source }] + expected_offenses = [{ message: 'Use "if build.head?" instead', + severity: :convention, + line: 5, + column: 26, + source: source }] inspect_source(source) @@ -1284,7 +1292,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with MACOS_VERSION const" do + it "deprecated MACOS_VERSION const usage" do source = <<-EOS.undent class Foo < Formula desc "foo" @@ -1295,11 +1303,11 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - expected_offenses = [{ message: "Use MacOS.version instead of MACOS_VERSION", - severity: :convention, - line: 5, - column: 14, - source: source }] + expected_offenses = [{ message: "Use MacOS.version instead of MACOS_VERSION", + severity: :convention, + line: 5, + column: 14, + source: source }] inspect_source(source) @@ -1308,7 +1316,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with if conditional dep" do + it "deprecated if build.with? conditional dependency" do source = <<-EOS.undent class Foo < Formula desc "foo" @@ -1317,11 +1325,11 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - expected_offenses = [{ message: 'Replace depends_on "foo" if build.with? "with-foo" with depends_on "foo" => :optional', - severity: :convention, - line: 4, - column: 2, - source: source }] + expected_offenses = [{ message: 'Replace depends_on "foo" if build.with? "with-foo" with depends_on "foo" => :optional', + severity: :convention, + line: 4, + column: 2, + source: source }] inspect_source(source) @@ -1330,7 +1338,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with unless conditional dep and symbol" do + it "unless conditional dependency with build.without?" do source = <<-EOS.undent class Foo < Formula desc "foo" @@ -1339,11 +1347,11 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - expected_offenses = [{ message: 'Replace depends_on :foo unless build.without? "foo" with depends_on :foo => :recommended', - severity: :convention, - line: 4, - column: 2, - source: source }] + expected_offenses = [{ message: 'Replace depends_on :foo unless build.without? "foo" with depends_on :foo => :recommended', + severity: :convention, + line: 4, + column: 2, + source: source }] inspect_source(source) @@ -1352,7 +1360,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end - it "with unless conditional dep with build.include?" do + it "unless conditional dependency with build.include?" do source = <<-EOS.undent class Foo < Formula desc "foo" @@ -1361,11 +1369,11 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - expected_offenses = [{ message: 'Replace depends_on :foo unless build.include? "without-foo" with depends_on :foo => :recommended', - severity: :convention, - line: 4, - column: 2, - source: source }] + expected_offenses = [{ message: 'Replace depends_on :foo unless build.include? "without-foo" with depends_on :foo => :recommended', + severity: :convention, + line: 4, + column: 2, + source: source }] inspect_source(source) -- cgit v1.2.3