2020-10-10 14:16:11 +02:00
|
|
|
# typed: false
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-26 19:41:14 +01:00
|
|
|
require "rubocops/dependency_order"
|
2018-02-19 23:40:07 +05:30
|
|
|
|
2018-09-08 15:46:56 +10:00
|
|
|
describe RuboCop::Cop::FormulaAudit::DependencyOrder do
|
2018-02-19 23:40:07 +05:30
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
2020-01-12 10:59:22 -08:00
|
|
|
context "uses_from_macos" do
|
|
|
|
it "wrong conditional uses_from_macos order" do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
class Foo < Formula
|
|
|
|
homepage "https://brew.sh"
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
uses_from_macos "apple" if build.with? "foo"
|
|
|
|
uses_from_macos "foo" => :optional
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ dependency "foo" (line 5) should be put before dependency "apple" (line 4)
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
|
|
|
it "wrong alphabetical uses_from_macos order" do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
class Foo < Formula
|
|
|
|
homepage "https://brew.sh"
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
uses_from_macos "foo"
|
|
|
|
uses_from_macos "bar"
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^ dependency "bar" (line 5) should be put before dependency "foo" (line 4)
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
|
|
|
it "supports requirement constants" do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
class Foo < Formula
|
|
|
|
homepage "https://brew.sh"
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
uses_from_macos FooRequirement
|
|
|
|
uses_from_macos "bar"
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^ dependency "bar" (line 5) should be put before dependency "FooRequirement" (line 4)
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
|
|
|
it "wrong conditional uses_from_macos order with block" do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
class Foo < Formula
|
|
|
|
homepage "https://brew.sh"
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
head do
|
|
|
|
uses_from_macos "apple" if build.with? "foo"
|
|
|
|
uses_from_macos "bar"
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^ dependency "bar" (line 6) should be put before dependency "apple" (line 5)
|
|
|
|
uses_from_macos "foo" => :optional
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ dependency "foo" (line 7) should be put before dependency "apple" (line 5)
|
|
|
|
end
|
|
|
|
uses_from_macos "apple" if build.with? "foo"
|
|
|
|
uses_from_macos "foo" => :optional
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ dependency "foo" (line 10) should be put before dependency "apple" (line 9)
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
|
|
|
it "correct uses_from_macos order for multiple tags" do
|
|
|
|
expect_no_offenses(<<~RUBY)
|
|
|
|
class Foo < Formula
|
|
|
|
homepage "https://brew.sh"
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
uses_from_macos "bar" => [:build, :test]
|
|
|
|
uses_from_macos "foo" => :build
|
|
|
|
uses_from_macos "apple"
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-19 23:40:07 +05:30
|
|
|
context "depends_on" do
|
|
|
|
it "wrong conditional depends_on order" do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
class Foo < Formula
|
2018-11-28 20:51:55 +01:00
|
|
|
homepage "https://brew.sh"
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
2018-02-19 23:40:07 +05:30
|
|
|
depends_on "apple" if build.with? "foo"
|
|
|
|
depends_on "foo" => :optional
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ dependency "foo" (line 5) should be put before dependency "apple" (line 4)
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
|
|
|
it "wrong alphabetical depends_on order" do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
class Foo < Formula
|
2018-11-28 20:51:55 +01:00
|
|
|
homepage "https://brew.sh"
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
2018-02-19 23:40:07 +05:30
|
|
|
depends_on "foo"
|
|
|
|
depends_on "bar"
|
|
|
|
^^^^^^^^^^^^^^^^ dependency "bar" (line 5) should be put before dependency "foo" (line 4)
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
2018-06-11 04:21:02 +02:00
|
|
|
it "supports requirement constants" do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
class Foo < Formula
|
2018-11-28 20:51:55 +01:00
|
|
|
homepage "https://brew.sh"
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
2018-06-11 04:21:02 +02:00
|
|
|
depends_on FooRequirement
|
|
|
|
depends_on "bar"
|
|
|
|
^^^^^^^^^^^^^^^^ dependency "bar" (line 5) should be put before dependency "FooRequirement" (line 4)
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
2018-10-26 19:41:14 +01:00
|
|
|
it "wrong conditional depends_on order with block" do
|
2018-02-19 23:40:07 +05:30
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
class Foo < Formula
|
2018-11-28 20:51:55 +01:00
|
|
|
homepage "https://brew.sh"
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
2018-02-19 23:40:07 +05:30
|
|
|
head do
|
|
|
|
depends_on "apple" if build.with? "foo"
|
|
|
|
depends_on "bar"
|
|
|
|
^^^^^^^^^^^^^^^^ dependency "bar" (line 6) should be put before dependency "apple" (line 5)
|
|
|
|
depends_on "foo" => :optional
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ dependency "foo" (line 7) should be put before dependency "apple" (line 5)
|
|
|
|
end
|
|
|
|
depends_on "apple" if build.with? "foo"
|
|
|
|
depends_on "foo" => :optional
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ dependency "foo" (line 10) should be put before dependency "apple" (line 9)
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
2018-03-28 20:54:39 -05:00
|
|
|
|
|
|
|
it "correct depends_on order for multiple tags" do
|
|
|
|
expect_no_offenses(<<~RUBY)
|
|
|
|
class Foo < Formula
|
2018-11-28 20:51:55 +01:00
|
|
|
homepage "https://brew.sh"
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
2018-03-28 20:54:39 -05:00
|
|
|
depends_on "bar" => [:build, :test]
|
|
|
|
depends_on "foo" => :build
|
|
|
|
depends_on "apple"
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
2018-02-19 23:40:07 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context "autocorrect" do
|
2020-01-12 10:59:22 -08:00
|
|
|
it "wrong conditional uses_from_macos order" do
|
|
|
|
source = <<~RUBY
|
|
|
|
class Foo < Formula
|
|
|
|
homepage "https://brew.sh"
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
uses_from_macos "apple" if build.with? "foo"
|
|
|
|
uses_from_macos "foo" => :optional
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
correct_source = <<~RUBY
|
|
|
|
class Foo < Formula
|
|
|
|
homepage "https://brew.sh"
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
uses_from_macos "foo" => :optional
|
|
|
|
uses_from_macos "apple" if build.with? "foo"
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
corrected_source = autocorrect_source(source)
|
|
|
|
expect(corrected_source).to eq(correct_source)
|
|
|
|
end
|
|
|
|
|
2018-02-19 23:40:07 +05:30
|
|
|
it "wrong conditional depends_on order" do
|
2018-07-11 15:17:40 +02:00
|
|
|
source = <<~RUBY
|
2018-02-19 23:40:07 +05:30
|
|
|
class Foo < Formula
|
2018-11-28 20:51:55 +01:00
|
|
|
homepage "https://brew.sh"
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
2018-02-19 23:40:07 +05:30
|
|
|
depends_on "apple" if build.with? "foo"
|
|
|
|
depends_on "foo" => :optional
|
|
|
|
end
|
2018-07-11 15:17:40 +02:00
|
|
|
RUBY
|
2018-02-19 23:40:07 +05:30
|
|
|
|
2018-07-11 15:17:40 +02:00
|
|
|
correct_source = <<~RUBY
|
2018-02-19 23:40:07 +05:30
|
|
|
class Foo < Formula
|
2018-11-28 20:51:55 +01:00
|
|
|
homepage "https://brew.sh"
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
2018-02-19 23:40:07 +05:30
|
|
|
depends_on "foo" => :optional
|
|
|
|
depends_on "apple" if build.with? "foo"
|
|
|
|
end
|
2018-07-11 15:17:40 +02:00
|
|
|
RUBY
|
2018-02-19 23:40:07 +05:30
|
|
|
|
|
|
|
corrected_source = autocorrect_source(source)
|
|
|
|
expect(corrected_source).to eq(correct_source)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|