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/conflicts"
|
2017-05-24 13:04:55 +05:30
|
|
|
|
|
|
|
describe RuboCop::Cop::FormulaAudit::Conflicts do
|
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
2020-12-23 18:02:25 -08:00
|
|
|
context "when auditing `conflicts_with`" do
|
2021-01-12 16:15:52 +11:00
|
|
|
it "reports and corrects an offense if reason is capitalized" do
|
2020-07-02 13:20:32 -04:00
|
|
|
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
|
|
|
|
class Foo < Formula
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
conflicts_with "bar", :because => "Reason"
|
|
|
|
^^^^^^^^ 'Reason' from the `conflicts_with` reason should be 'reason'.
|
|
|
|
conflicts_with "baz", :because => "Foo is the formula name which does not require downcasing"
|
|
|
|
end
|
|
|
|
RUBY
|
2021-01-12 16:15:52 +11:00
|
|
|
|
|
|
|
expect_correction(<<~RUBY)
|
|
|
|
class Foo < Formula
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
conflicts_with "bar", :because => "reason"
|
|
|
|
conflicts_with "baz", :because => "Foo is the formula name which does not require downcasing"
|
|
|
|
end
|
|
|
|
RUBY
|
2020-07-02 13:20:32 -04:00
|
|
|
end
|
|
|
|
|
2021-01-12 16:15:52 +11:00
|
|
|
it "reports and corrects an offense if reason ends with a period" do
|
2020-07-02 13:20:32 -04:00
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
class Foo < Formula
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
conflicts_with "bar", "baz", :because => "reason."
|
|
|
|
^^^^^^^^^ `conflicts_with` reason should not end with a period.
|
|
|
|
end
|
|
|
|
RUBY
|
2021-01-12 16:15:52 +11:00
|
|
|
|
|
|
|
expect_correction(<<~RUBY)
|
|
|
|
class Foo < Formula
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
conflicts_with "bar", "baz", :because => "reason"
|
|
|
|
end
|
|
|
|
RUBY
|
2020-07-02 13:20:32 -04:00
|
|
|
end
|
|
|
|
|
2020-12-23 18:02:25 -08:00
|
|
|
it "reports an offense if it is present in a versioned formula" do
|
2017-10-21 03:12:50 +02:00
|
|
|
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo@2.0.rb")
|
2017-05-24 13:04:55 +05:30
|
|
|
class FooAT20 < Formula
|
2018-11-28 20:51:55 +01:00
|
|
|
url 'https://brew.sh/foo-2.0.tgz'
|
2020-07-02 13:20:32 -04:00
|
|
|
conflicts_with "mysql", "mariadb"
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Versioned formulae should not use `conflicts_with`. Use `keg_only :versioned_formula` instead.
|
2017-05-24 13:04:55 +05:30
|
|
|
end
|
2017-10-21 03:12:50 +02:00
|
|
|
RUBY
|
2017-05-24 13:04:55 +05:30
|
|
|
end
|
|
|
|
|
2020-12-23 18:02:25 -08:00
|
|
|
it "reports no offenses if it is not present" do
|
2017-10-21 03:12:50 +02:00
|
|
|
expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/foo@2.0.rb")
|
2017-05-24 13:04:55 +05:30
|
|
|
class FooAT20 < Formula
|
2018-11-28 20:51:55 +01:00
|
|
|
url 'https://brew.sh/foo-2.0.tgz'
|
2020-07-02 13:20:32 -04:00
|
|
|
homepage "https://brew.sh"
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
2017-05-24 13:04:55 +05:30
|
|
|
end
|
|
|
|
end
|