Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FnControlOption committed Aug 3, 2022
1 parent cf6a687 commit b8271b2
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions Library/Homebrew/test/rubocops/dependency_order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,34 @@ class Foo < Formula
end
RUBY
end

it "reports and corrects wrong conditional order within a system block" do
expect_offense(<<~RUBY)
class Foo < Formula
homepage "https://brew.sh"
url "https://brew.sh/foo-1.0.tgz"
on_arm 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
end
RUBY

expect_correction(<<~RUBY)
class Foo < Formula
homepage "https://brew.sh"
url "https://brew.sh/foo-1.0.tgz"
on_arm do
uses_from_macos "bar"
uses_from_macos "foo" => :optional
uses_from_macos "apple" if build.with? "foo"
end
end
RUBY
end
end

context "when auditing `depends_on`" do
Expand Down Expand Up @@ -224,5 +252,33 @@ class Foo < Formula
end
RUBY
end

it "reports and corrects wrong conditional order within a system block" do
expect_offense(<<~RUBY)
class Foo < Formula
homepage "https://brew.sh"
url "https://brew.sh/foo-1.0.tgz"
on_linux 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
end
RUBY

expect_correction(<<~RUBY)
class Foo < Formula
homepage "https://brew.sh"
url "https://brew.sh/foo-1.0.tgz"
on_linux do
depends_on "bar"
depends_on "foo" => :optional
depends_on "apple" if build.with? "foo"
end
end
RUBY
end
end
end

0 comments on commit b8271b2

Please sign in to comment.