245 lines
7.2 KiB
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: false
# frozen_string_literal: true
require "rubocops/text"
describe RuboCop::Cop::FormulaAudit::Text do
subject(:cop) { described_class.new }
context "when auditing formula text" do
it 'reports an offense if `require "formula"` is present' do
2020-07-06 10:26:21 -04:00
expect_offense(<<~RUBY)
require "formula"
^^^^^^^^^^^^^^^^^ `require "formula"` is now unnecessary
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
homepage "https://brew.sh"
end
RUBY
2021-01-12 12:01:29 +11:00
expect_correction(<<~RUBY)
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
homepage "https://brew.sh"
end
RUBY
2020-07-06 10:26:21 -04:00
end
it "reports an offense if both openssl and libressl are dependencies" do
2017-10-21 03:12:50 +02:00
expect_offense(<<~RUBY)
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
homepage "https://brew.sh"
depends_on "openssl"
depends_on "libressl" => :optional
2017-10-21 03:12:50 +02:00
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Formulae should not depend on both OpenSSL and LibreSSL (even optionally).
end
2017-10-21 03:12:50 +02:00
RUBY
2017-10-21 03:12:50 +02:00
expect_offense(<<~RUBY)
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
homepage "https://brew.sh"
depends_on "openssl"
depends_on "libressl"
2017-10-21 03:12:50 +02:00
^^^^^^^^^^^^^^^^^^^^^ Formulae should not depend on both OpenSSL and LibreSSL (even optionally).
end
2017-10-21 03:12:50 +02:00
RUBY
end
it "reports an offense if veclibfort is used instead of OpenBLAS (in homebrew/core)" do
expect_offense(<<~RUBY, "/homebrew-core/")
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
homepage "https://brew.sh"
depends_on "veclibfort"
^^^^^^^^^^^^^^^^^^^^^^^ Formulae in homebrew/core should use OpenBLAS as the default serial linear algebra library.
end
RUBY
end
it "reports an offense if lapack is used instead of OpenBLAS (in homebrew/core)" do
expect_offense(<<~RUBY, "/homebrew-core/")
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
homepage "https://brew.sh"
depends_on "lapack"
^^^^^^^^^^^^^^^^^^^ Formulae in homebrew/core should use OpenBLAS as the default serial linear algebra library.
end
RUBY
end
it "reports an offense if `go get` is executed" do
2017-10-21 03:12:50 +02:00
expect_offense(<<~RUBY)
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
homepage "https://brew.sh"
def install
system "go", "get", "bar"
2017-10-31 01:01:42 +00:00
^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use `go get`. Please ask upstream to implement Go vendoring
end
end
2017-10-21 03:12:50 +02:00
RUBY
end
it "reports an offense if `xcodebuild` is executed" do
2017-10-21 03:12:50 +02:00
expect_offense(<<~RUBY)
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
homepage "https://brew.sh"
def install
system "xcodebuild", "foo", "bar"
2022-12-13 10:54:22 +00:00
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use "xcodebuild *args" instead of "system 'xcodebuild', *args"
end
end
2017-10-21 03:12:50 +02:00
RUBY
end
it "reports an offense if `plist_options` are not defined when using a formula-defined `plist`", :ruby23 do
2017-10-21 03:12:50 +02:00
expect_offense(<<~RUBY)
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
homepage "https://brew.sh"
def install
system "xcodebuild", "foo", "bar"
2022-12-13 10:54:22 +00:00
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use "xcodebuild *args" instead of "system 'xcodebuild', *args"
end
2017-10-15 02:28:32 +02:00
def plist
2017-10-21 03:12:50 +02:00
^^^^^^^^^ Please set plist_options when using a formula-defined plist.
2017-10-15 02:28:32 +02:00
<<~XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.nrpe.agent</string>
</dict>
</plist>
XML
end
end
2017-10-15 02:28:32 +02:00
RUBY
end
it 'reports an offense if `require "language/go"` is present' do
2017-10-21 03:12:50 +02:00
expect_offense(<<~RUBY)
require "language/go"
2017-10-21 03:12:50 +02:00
^^^^^^^^^^^^^^^^^^^^^ require "language/go" is unnecessary unless using `go_resource`s
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
homepage "https://brew.sh"
def install
system "go", "get", "bar"
2017-10-31 01:01:42 +00:00
^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use `go get`. Please ask upstream to implement Go vendoring
end
end
2017-10-21 03:12:50 +02:00
RUBY
end
it "reports an offense if `Formula.factory(name)` is present" do
2017-10-21 03:12:50 +02:00
expect_offense(<<~RUBY)
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
homepage "https://brew.sh"
def install
Formula.factory(name)
2022-12-13 10:54:22 +00:00
^^^^^^^^^^^^^^^^^^^^^ "Formula.factory(name)" is deprecated in favor of "Formula[name]"
end
end
2017-10-21 03:12:50 +02:00
RUBY
end
it "reports an offense if `dep ensure` is used without `-vendor-only`" do
expect_offense(<<~RUBY)
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
homepage "https://brew.sh"
def install
system "dep", "ensure"
2022-12-13 10:54:22 +00:00
^^^^^^^^^^^^^^^^^^^^^^ use "dep", "ensure", "-vendor-only"
end
end
RUBY
end
it "reports an offense if `cargo build` is executed" do
expect_offense(<<~RUBY)
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
homepage "https://brew.sh"
def install
system "cargo", "build"
2022-12-13 10:54:22 +00:00
^^^^^^^^^^^^^^^^^^^^^^^ use "cargo", "install", *std_cargo_args
end
end
RUBY
end
2020-07-03 16:27:35 -04:00
it "doesn't reports an offense if `cargo build` is executed with --lib" do
expect_no_offenses(<<~RUBY)
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
homepage "https://brew.sh"
def install
system "cargo", "build", "--lib"
end
end
RUBY
end
it "reports an offense if `make` calls are not separated" do
2020-07-03 16:27:35 -04:00
expect_offense(<<~RUBY)
class Foo < Formula
def install
system "make && make install"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use separate `make` calls
end
end
RUBY
end
it "reports an offense if paths are concatenated in string interpolation" do
expect_offense(<<~RUBY)
class Foo < Formula
def install
ohai "foo \#{bar + "baz"}"
^^^^^^^^^^^^^^ Do not concatenate paths in string interpolation
end
end
RUBY
end
it 'reports an offense if `prefix + "bin"` is present' do
2020-07-05 15:02:47 -04:00
expect_offense(<<~RUBY)
class Foo < Formula
def install
ohai prefix + "bin"
^^^^^^^^^^^^^^ Use `bin` instead of `prefix + "bin"`
end
end
RUBY
expect_offense(<<~RUBY)
class Foo < Formula
def install
ohai prefix + "bin/foo"
^^^^^^^^^^^^^^^^^^ Use `bin` instead of `prefix + "bin"`
end
end
RUBY
end
end
end