aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew/test')
-rw-r--r--Library/Homebrew/test/dev-cmd/audit_spec.rb94
-rw-r--r--Library/Homebrew/test/rubocops/components_order_cop_spec.rb116
-rw-r--r--Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb87
3 files changed, 203 insertions, 94 deletions
diff --git a/Library/Homebrew/test/dev-cmd/audit_spec.rb b/Library/Homebrew/test/dev-cmd/audit_spec.rb
index d07d9d72b..9afb7954a 100644
--- a/Library/Homebrew/test/dev-cmd/audit_spec.rb
+++ b/Library/Homebrew/test/dev-cmd/audit_spec.rb
@@ -148,100 +148,6 @@ describe FormulaAuditor do
fa.audit_file
expect(fa.problems).to eq([])
end
-
- specify "strict: ordering issue" do
- fa = formula_auditor "foo", <<-EOS.undent, strict: true
- class Foo < Formula
- url "http://example.com/foo-1.0.tgz"
- homepage "http://example.com"
- end
- EOS
-
- fa.audit_file
- expect(fa.problems)
- .to eq(["`homepage` (line 3) should be put before `url` (line 2)"])
- end
-
- specify "strict: resource placement" do
- fa = formula_auditor "foo", <<-EOS.undent, strict: true
- class Foo < Formula
- url "https://example.com/foo-1.0.tgz"
-
- resource "foo2" do
- url "https://example.com/foo-2.0.tgz"
- end
-
- depends_on "openssl"
- end
- EOS
-
- fa.audit_file
- expect(fa.problems)
- .to eq(["`depends_on` (line 8) should be put before `resource` (line 4)"])
- end
-
- specify "strict: plist placement" do
- fa = formula_auditor "foo", <<-EOS.undent, strict: true
- class Foo < Formula
- url "https://example.com/foo-1.0.tgz"
-
- test do
- expect(shell_output("./dogs")).to match("Dogs are terrific")
- end
-
- def plist
- end
- end
- EOS
-
- fa.audit_file
- expect(fa.problems)
- .to eq(["`plist block` (line 8) should be put before `test block` (line 4)"])
- end
-
- specify "strict: url outside of stable block" do
- fa = formula_auditor "foo", <<-EOS.undent, strict: true
- class Foo < Formula
- url "http://example.com/foo-1.0.tgz"
- stable do
- # stuff
- end
- end
- EOS
-
- fa.audit_file
- expect(fa.problems).to eq(["`url` should be put inside `stable block`"])
- end
-
- specify "strict: head and head do" do
- fa = formula_auditor "foo", <<-EOS.undent, strict: true
- class Foo < Formula
- head "http://example.com/foo.git"
- head do
- # stuff
- end
- end
- EOS
-
- fa.audit_file
- expect(fa.problems).to eq(["Should not have both `head` and `head do`"])
- end
-
- specify "strict: bottle and bottle do" do
- fa = formula_auditor "foo", <<-EOS.undent, strict: true
- class Foo < Formula
- url "http://example.com/foo-1.0.tgz"
- bottle do
- # bottles go here
- end
- bottle :unneeded
- end
- EOS
-
- fa.audit_file
- expect(fa.problems)
- .to eq(["Should not have `bottle :unneeded/:disable` and `bottle do`"])
- end
end
describe "#audit_class" do
diff --git a/Library/Homebrew/test/rubocops/components_order_cop_spec.rb b/Library/Homebrew/test/rubocops/components_order_cop_spec.rb
new file mode 100644
index 000000000..a424da863
--- /dev/null
+++ b/Library/Homebrew/test/rubocops/components_order_cop_spec.rb
@@ -0,0 +1,116 @@
+require "rubocop"
+require "rubocop/rspec/support"
+require_relative "../../extend/string"
+require_relative "../../rubocops/components_order_cop"
+
+describe RuboCop::Cop::Homebrew::FormulaComponentsOrder do
+ subject(:cop) { described_class.new }
+
+ context "When auditing formula components order" do
+ it "When url precedes homepage" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url "http://example.com/foo-1.0.tgz"
+ homepage "http://example.com"
+ end
+ EOS
+
+ expected_offenses = [{ message: "`homepage` (line 3) should be put before `url` (line 2)",
+ severity: :convention,
+ line: 3,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "When `resource` precedes `depends_on`" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url "https://example.com/foo-1.0.tgz"
+
+ resource "foo2" do
+ url "https://example.com/foo-2.0.tgz"
+ end
+
+ depends_on "openssl"
+ end
+ EOS
+
+ expected_offenses = [{ message: "`depends_on` (line 8) should be put before `resource` (line 4)",
+ severity: :convention,
+ line: 8,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "When `test` precedes `plist`" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url "https://example.com/foo-1.0.tgz"
+
+ test do
+ expect(shell_output("./dogs")).to match("Dogs are terrific")
+ end
+
+ def plist
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "`plist` (line 8) should be put before `test` (line 4)",
+ severity: :convention,
+ line: 8,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "When only one of many `depends_on` precedes `conflicts_with`" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ depends_on "autoconf" => :build
+ conflicts_with "visionmedia-watch"
+ depends_on "automake" => :build
+ depends_on "libtool" => :build
+ depends_on "pkg-config" => :build
+ depends_on "gettext"
+ end
+ EOS
+
+ expected_offenses = [{ message: "`depends_on` (line 4) should be put before `conflicts_with` (line 3)",
+ 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
+
+ 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
+end
diff --git a/Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb b/Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb
new file mode 100644
index 000000000..5637330d8
--- /dev/null
+++ b/Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb
@@ -0,0 +1,87 @@
+require "rubocop"
+require "rubocop/rspec/support"
+require_relative "../../extend/string"
+require_relative "../../rubocops/components_redundancy_cop"
+
+describe RuboCop::Cop::Homebrew::ComponentsRedundancy do
+ subject(:cop) { described_class.new }
+
+ context "When auditing formula components common errors" do
+ it "When url outside stable block" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url "http://example.com/foo-1.0.tgz"
+ stable do
+ # stuff
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "`url` should be put inside `stable` block",
+ severity: :convention,
+ line: 2,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "When both `head` and `head do` are present" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ head "http://example.com/foo.git"
+ head do
+ # stuff
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "`head` and `head do` should not be simultaneously present",
+ severity: :convention,
+ line: 3,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "When both `bottle :modifier` and `bottle do` are present" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url "http://example.com/foo-1.0.tgz"
+ bottle do
+ # bottles go here
+ end
+ bottle :unneeded
+ end
+ EOS
+
+ expected_offenses = [{ message: "`bottle :modifier` and `bottle do` should not be simultaneously present",
+ severity: :convention,
+ line: 3,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ 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
+end