2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-26 19:41:14 +01:00
|
|
|
require "rubocops/class"
|
2017-09-04 13:47:05 +05:30
|
|
|
|
2024-02-18 15:11:11 -08:00
|
|
|
RSpec.describe RuboCop::Cop::FormulaAudit::Test do
|
2018-08-15 19:43:57 -04:00
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
2021-01-12 13:33:23 +11:00
|
|
|
it "reports and corrects an offense when /usr/local/bin is found in test calls" do
|
2018-08-15 19:43:57 -04:00
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
class Foo < Formula
|
2018-11-28 20:51:55 +01:00
|
|
|
url 'https://brew.sh/foo-1.0.tgz'
|
2018-08-15 19:43:57 -04:00
|
|
|
|
|
|
|
test do
|
|
|
|
system "/usr/local/bin/test"
|
2023-04-07 17:16:48 +01:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Test: use \#{bin} instead of /usr/local/bin in system
|
2018-08-15 19:43:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2021-01-12 13:33:23 +11:00
|
|
|
expect_correction(<<~RUBY)
|
2018-08-15 19:43:57 -04:00
|
|
|
class Foo < Formula
|
2018-11-28 20:51:55 +01:00
|
|
|
url 'https://brew.sh/foo-1.0.tgz'
|
2018-08-15 19:43:57 -04:00
|
|
|
|
|
|
|
test do
|
2021-01-12 13:33:23 +11:00
|
|
|
system "\#{bin}/test"
|
2018-08-15 19:43:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
2018-08-16 12:42:45 -04:00
|
|
|
|
2021-01-12 13:33:23 +11:00
|
|
|
it "reports and corrects an offense when passing 0 as the second parameter to shell_output" do
|
2020-04-13 14:34:05 +01:00
|
|
|
expect_offense(<<~RUBY)
|
2018-08-16 12:42:45 -04:00
|
|
|
class Foo < Formula
|
2018-11-28 20:51:55 +01:00
|
|
|
url 'https://brew.sh/foo-1.0.tgz'
|
2018-08-16 12:42:45 -04:00
|
|
|
|
|
|
|
test do
|
2021-01-12 13:33:23 +11:00
|
|
|
shell_output("\#{bin}/test", 0)
|
2023-04-07 17:16:48 +01:00
|
|
|
^ FormulaAudit/Test: Passing 0 to shell_output() is redundant
|
2018-08-16 12:42:45 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2021-01-12 13:33:23 +11:00
|
|
|
expect_correction(<<~RUBY)
|
2018-08-16 12:42:45 -04:00
|
|
|
class Foo < Formula
|
2018-11-28 20:51:55 +01:00
|
|
|
url 'https://brew.sh/foo-1.0.tgz'
|
2018-08-16 12:42:45 -04:00
|
|
|
|
|
|
|
test do
|
2021-01-12 13:33:23 +11:00
|
|
|
shell_output("\#{bin}/test")
|
2018-08-16 12:42:45 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
2017-09-04 13:47:05 +05:30
|
|
|
|
2021-01-12 13:33:23 +11:00
|
|
|
it "reports an offense when there is an empty test block" do
|
|
|
|
expect_offense(<<~RUBY)
|
2017-10-21 03:12:50 +02:00
|
|
|
class Foo < Formula
|
2018-11-28 20:51:55 +01:00
|
|
|
url 'https://brew.sh/foo-1.0.tgz'
|
2020-04-13 14:34:05 +01:00
|
|
|
|
|
|
|
test do
|
2023-04-07 17:16:48 +01:00
|
|
|
^^^^^^^ FormulaAudit/Test: `test do` should not be empty
|
2020-04-13 14:34:05 +01:00
|
|
|
end
|
2017-09-04 13:47:05 +05:30
|
|
|
end
|
2017-10-21 03:12:50 +02:00
|
|
|
RUBY
|
2021-01-12 13:33:23 +11:00
|
|
|
end
|
2018-08-07 03:39:47 +01:00
|
|
|
|
2021-01-12 13:33:23 +11:00
|
|
|
it "reports an offense when test is falsely true" do
|
|
|
|
expect_offense(<<~RUBY)
|
2018-08-07 03:39:47 +01:00
|
|
|
class Foo < Formula
|
2018-11-28 20:51:55 +01:00
|
|
|
url 'https://brew.sh/foo-1.0.tgz'
|
2018-08-07 03:39:47 +01:00
|
|
|
|
|
|
|
test do
|
2023-04-07 17:16:48 +01:00
|
|
|
^^^^^^^ FormulaAudit/Test: `test do` should contain a real test
|
2021-01-12 13:33:23 +11:00
|
|
|
true
|
2018-08-07 03:39:47 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
2020-04-13 14:34:05 +01:00
|
|
|
end
|