2017-07-29 16:36:32 +05:30
|
|
|
require "rubocop"
|
|
|
|
require "rubocop/rspec/support"
|
|
|
|
require_relative "../../extend/string"
|
|
|
|
require_relative "../../rubocops/lines_cop"
|
|
|
|
|
|
|
|
describe RuboCop::Cop::FormulaAudit::Lines do
|
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
|
|
|
context "When auditing lines" do
|
2017-10-21 12:50:49 +05:30
|
|
|
it "correctable deprecated dependencies usage" do
|
2017-07-29 16:36:32 +05:30
|
|
|
formulae = [{
|
|
|
|
"dependency" => :automake,
|
|
|
|
"correct" => "automake",
|
|
|
|
}, {
|
|
|
|
"dependency" => :autoconf,
|
|
|
|
"correct" => "autoconf",
|
|
|
|
}, {
|
|
|
|
"dependency" => :libtool,
|
|
|
|
"correct" => "libtool",
|
|
|
|
}, {
|
|
|
|
"dependency" => :apr,
|
|
|
|
"correct" => "apr-util",
|
|
|
|
}, {
|
|
|
|
"dependency" => :tex,
|
|
|
|
}]
|
|
|
|
|
|
|
|
formulae.each do |formula|
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
|
|
|
class Foo < Formula
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
depends_on :#{formula["dependency"]}
|
|
|
|
end
|
2017-07-29 16:36:32 +05:30
|
|
|
EOS
|
|
|
|
if formula.key?("correct")
|
|
|
|
offense = ":#{formula["dependency"]} is deprecated. Usage should be \"#{formula["correct"]}\""
|
|
|
|
else
|
|
|
|
offense = ":#{formula["dependency"]} is deprecated"
|
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: offense,
|
|
|
|
severity: :convention,
|
|
|
|
line: 3,
|
|
|
|
column: 2,
|
|
|
|
source: source }]
|
2017-07-29 16:36:32 +05:30
|
|
|
|
2017-10-07 22:31:23 +02:00
|
|
|
inspect_source(source)
|
2017-07-29 16:36:32 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses.reverse).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-02 23:49:51 +05:30
|
|
|
|
|
|
|
describe RuboCop::Cop::FormulaAudit::ClassInheritance do
|
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
|
|
|
context "When auditing lines" do
|
2017-10-21 12:50:49 +05:30
|
|
|
it "inconsistent space in class inheritance" do
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
2017-08-02 23:49:51 +05:30
|
|
|
class Foo<Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Use a space in class inheritance: class Foo < Formula",
|
|
|
|
severity: :convention,
|
|
|
|
line: 1,
|
|
|
|
column: 10,
|
|
|
|
source: source }]
|
2017-08-02 23:49:51 +05:30
|
|
|
|
2017-10-21 01:39:04 +05:30
|
|
|
inspect_source(source, "/homebrew-core/Formula/foo.rb")
|
2017-08-02 23:49:51 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe RuboCop::Cop::FormulaAudit::Comments do
|
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
|
|
|
context "When auditing formula" do
|
2017-10-21 12:50:49 +05:30
|
|
|
it "commented cmake call" do
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
2017-08-02 23:49:51 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
# system "cmake", ".", *std_cmake_args
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Please remove default template comments",
|
|
|
|
severity: :convention,
|
|
|
|
line: 4,
|
|
|
|
column: 2,
|
|
|
|
source: source }]
|
2017-08-02 23:49:51 +05:30
|
|
|
|
2017-10-07 22:31:23 +02:00
|
|
|
inspect_source(source)
|
2017-08-02 23:49:51 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "default template comments" do
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
2017-08-02 23:49:51 +05:30
|
|
|
class Foo < Formula
|
|
|
|
# PLEASE REMOVE
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Please remove default template comments",
|
|
|
|
severity: :convention,
|
|
|
|
line: 2,
|
|
|
|
column: 2,
|
|
|
|
source: source }]
|
2017-08-02 23:49:51 +05:30
|
|
|
|
2017-10-07 22:31:23 +02:00
|
|
|
inspect_source(source)
|
2017-08-02 23:49:51 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "commented out depends_on" do
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
2017-08-02 23:49:51 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
# depends_on "foo"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: 'Commented-out dependency "foo"',
|
|
|
|
severity: :convention,
|
|
|
|
line: 4,
|
|
|
|
column: 2,
|
|
|
|
source: source }]
|
2017-08-02 23:49:51 +05:30
|
|
|
|
2017-10-07 22:31:23 +02:00
|
|
|
inspect_source(source)
|
2017-08-02 23:49:51 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
describe RuboCop::Cop::FormulaAudit::AssertStatements do
|
2017-08-02 23:49:51 +05:30
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "assert ...include usage" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
assert File.read("inbox").include?("Sample message 1")
|
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
EOS
|
2017-08-02 23:49:51 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Use `assert_match` instead of `assert ...include?`",
|
|
|
|
severity: :convention,
|
|
|
|
line: 4,
|
|
|
|
column: 9,
|
|
|
|
source: source }]
|
2017-08-02 23:49:51 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
inspect_source(source)
|
2017-08-02 23:49:51 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
2017-08-02 23:49:51 +05:30
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
end
|
2017-08-02 23:49:51 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "assert ...exist? without a negation" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
assert File.exist? "default.ini"
|
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
EOS
|
2017-08-02 23:49:51 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: 'Use `assert_predicate <path_to_file>, :exist?` instead of `assert File.exist? "default.ini"`',
|
|
|
|
severity: :convention,
|
|
|
|
line: 4,
|
|
|
|
column: 9,
|
|
|
|
source: source }]
|
2017-08-02 23:49:51 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
inspect_source(source)
|
2017-08-02 23:49:51 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
2017-08-02 23:49:51 +05:30
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
end
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "assert ...exist? with a negation" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
assert !File.exist?("default.ini")
|
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
EOS
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: 'Use `refute_predicate <path_to_file>, :exist?` instead of `assert !File.exist?("default.ini")`',
|
|
|
|
severity: :convention,
|
|
|
|
line: 4,
|
|
|
|
column: 9,
|
|
|
|
source: source }]
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
inspect_source(source)
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
2017-08-05 14:58:09 +05:30
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
end
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "assert ...executable? without a negation" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
assert File.executable? f
|
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
EOS
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Use `assert_predicate <path_to_file>, :executable?` instead of `assert File.executable? f`",
|
|
|
|
severity: :convention,
|
|
|
|
line: 4,
|
|
|
|
column: 9,
|
|
|
|
source: source }]
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
inspect_source(source)
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
2017-08-05 14:58:09 +05:30
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
end
|
|
|
|
end
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
describe RuboCop::Cop::FormulaAudit::OptionDeclarations do
|
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
|
|
|
it "unless build.without? conditional" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
def post_install
|
|
|
|
return unless build.without? "bar"
|
2017-08-05 14:58:09 +05:30
|
|
|
end
|
2017-10-21 13:26:25 +05:30
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
EOS
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: 'Use if build.with? "bar" instead of unless build.without? "bar"',
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 18,
|
|
|
|
source: source }]
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
inspect_source(source)
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
2017-08-05 14:58:09 +05:30
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
end
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "unless build.with? conditional" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
def post_install
|
|
|
|
return unless build.with? "bar"
|
2017-08-05 14:58:09 +05:30
|
|
|
end
|
2017-10-21 13:26:25 +05:30
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
EOS
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: 'Use if build.without? "bar" instead of unless build.with? "bar"',
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 18,
|
|
|
|
source: source }]
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
inspect_source(source)
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
2017-08-05 14:58:09 +05:30
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
end
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "negated build.with? conditional" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
def post_install
|
|
|
|
return if !build.with? "bar"
|
2017-08-05 14:58:09 +05:30
|
|
|
end
|
2017-10-21 13:26:25 +05:30
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
EOS
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Don't negate 'build.with?': use 'build.without?'",
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 14,
|
|
|
|
source: source }]
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
inspect_source(source)
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
2017-08-05 14:58:09 +05:30
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
end
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "negated build.without? conditional" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
def post_install
|
|
|
|
return if !build.without? "bar"
|
2017-08-05 14:58:09 +05:30
|
|
|
end
|
2017-10-21 13:26:25 +05:30
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
EOS
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Don't negate 'build.without?': use 'build.with?'",
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 14,
|
|
|
|
source: source }]
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
inspect_source(source)
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
2017-08-05 14:58:09 +05:30
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
end
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "unnecessary build.without? conditional" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
def post_install
|
|
|
|
return if build.without? "--without-bar"
|
2017-08-05 14:58:09 +05:30
|
|
|
end
|
2017-10-21 13:26:25 +05:30
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
EOS
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Don't duplicate 'without': Use `build.without? \"bar\"` to check for \"--without-bar\"",
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 30,
|
|
|
|
source: source }]
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
inspect_source(source)
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
2017-08-05 14:58:09 +05:30
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
end
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "unnecessary build.with? conditional" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
def post_install
|
|
|
|
return if build.with? "--with-bar"
|
2017-09-10 18:55:01 +00:00
|
|
|
end
|
2017-10-21 13:26:25 +05:30
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
EOS
|
2017-09-10 18:55:01 +00:00
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Don't duplicate 'with': Use `build.with? \"bar\"` to check for \"--with-bar\"",
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 27,
|
|
|
|
source: source }]
|
|
|
|
|
|
|
|
inspect_source(source)
|
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
2017-09-10 18:55:01 +00:00
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
end
|
2017-09-10 18:55:01 +00:00
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "build.include? conditional" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
def post_install
|
|
|
|
return if build.include? "without-bar"
|
2017-08-05 14:58:09 +05:30
|
|
|
end
|
2017-10-21 13:26:25 +05:30
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
EOS
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Use build.without? \"bar\" instead of build.include? 'without-bar'",
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 30,
|
|
|
|
source: source }]
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
inspect_source(source)
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
2017-08-05 14:58:09 +05:30
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
end
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "build.include? with dashed args conditional" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
def post_install
|
|
|
|
return if build.include? "--bar"
|
2017-08-05 14:58:09 +05:30
|
|
|
end
|
2017-10-21 13:26:25 +05:30
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
EOS
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Reference 'bar' without dashes",
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 30,
|
|
|
|
source: source }]
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
inspect_source(source)
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
2017-08-05 14:58:09 +05:30
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
end
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "def options usage" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
2017-10-21 12:50:49 +05:30
|
|
|
|
2017-10-21 13:26:25 +05:30
|
|
|
def options
|
|
|
|
[["--bar", "desc"]]
|
2017-08-05 14:58:09 +05:30
|
|
|
end
|
2017-10-21 13:26:25 +05:30
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
EOS
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Use new-style option definitions",
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 2,
|
|
|
|
source: source }]
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
inspect_source(source)
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
2017-08-05 14:58:09 +05:30
|
|
|
end
|
2017-10-21 12:50:49 +05:30
|
|
|
end
|
|
|
|
end
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
describe RuboCop::Cop::FormulaAudit::Miscellaneous do
|
|
|
|
subject(:cop) { described_class.new }
|
2017-09-10 18:55:01 +00:00
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
context "When auditing formula" do
|
|
|
|
it "FileUtils usage" do
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
2017-08-05 14:58:09 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
2017-10-21 12:50:49 +05:30
|
|
|
FileUtils.mv "hello"
|
2017-08-05 14:58:09 +05:30
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Don't need 'FileUtils.' before mv",
|
|
|
|
severity: :convention,
|
|
|
|
line: 4,
|
|
|
|
column: 2,
|
|
|
|
source: source }]
|
2017-08-05 14:58:09 +05:30
|
|
|
|
2017-10-07 22:31:23 +02:00
|
|
|
inspect_source(source)
|
2017-08-05 14:58:09 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
2017-08-12 23:28:08 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "long inreplace block vars" do
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
2017-08-12 23:28:08 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
2017-10-21 12:50:49 +05:30
|
|
|
inreplace "foo" do |longvar|
|
|
|
|
somerandomCall(longvar)
|
|
|
|
end
|
2017-08-12 23:28:08 +05:30
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "\"inreplace <filenames> do |s|\" is preferred over \"|longvar|\".",
|
|
|
|
severity: :convention,
|
|
|
|
line: 4,
|
|
|
|
column: 2,
|
|
|
|
source: source }]
|
2017-10-21 01:39:04 +05:30
|
|
|
|
|
|
|
inspect_source(source)
|
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-21 13:26:25 +05:30
|
|
|
it "an invalid rebuild statement" do
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
2017-10-21 01:39:04 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
2017-10-21 12:50:49 +05:30
|
|
|
bottle do
|
|
|
|
rebuild 0
|
|
|
|
sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra
|
|
|
|
end
|
2017-10-21 01:39:04 +05:30
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "'rebuild 0' should be removed",
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 4,
|
|
|
|
source: source }]
|
2017-10-21 01:39:04 +05:30
|
|
|
|
|
|
|
inspect_source(source)
|
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "OS.linux? check" do
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
2017-10-21 01:39:04 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
2017-10-21 12:50:49 +05:30
|
|
|
bottle do
|
|
|
|
if OS.linux?
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra
|
|
|
|
end
|
2017-10-21 01:39:04 +05:30
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Don't use OS.linux?; Homebrew/core only supports macOS",
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 7,
|
|
|
|
source: source }]
|
2017-10-21 01:39:04 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
inspect_source(source, "/homebrew-core/")
|
2017-10-21 01:39:04 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "fails_with :llvm block" do
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
2017-10-21 01:39:04 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
2017-10-21 12:50:49 +05:30
|
|
|
bottle do
|
|
|
|
sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra
|
|
|
|
end
|
|
|
|
fails_with :llvm do
|
|
|
|
build 2335
|
|
|
|
cause "foo"
|
|
|
|
end
|
2017-10-21 01:39:04 +05:30
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "'fails_with :llvm' is now a no-op so should be removed",
|
|
|
|
severity: :convention,
|
|
|
|
line: 7,
|
|
|
|
column: 2,
|
|
|
|
source: source }]
|
2017-08-12 23:28:08 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-12 23:28:08 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-21 13:26:25 +05:30
|
|
|
it "def test's deprecated usage" do
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
2017-08-12 23:28:08 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
2017-10-21 12:50:49 +05:30
|
|
|
|
|
|
|
def test
|
|
|
|
assert_equals "1", "1"
|
|
|
|
end
|
2017-08-12 23:28:08 +05:30
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Use new-style test definitions (test do)",
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 2,
|
|
|
|
source: source }]
|
2017-08-12 23:28:08 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-12 23:28:08 +05:30
|
|
|
|
2017-08-13 14:50:29 +05:30
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
2017-10-12 00:29:19 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "deprecated skip_clean call" do
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
2017-08-13 14:50:29 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
2017-10-21 12:50:49 +05:30
|
|
|
skip_clean :all
|
2017-08-13 14:50:29 +05:30
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-15 02:28:32 +02:00
|
|
|
expected_offenses = [{ message: <<~EOS.chomp,
|
|
|
|
`skip_clean :all` is deprecated; brew no longer strips symbols
|
|
|
|
Pass explicit paths to prevent Homebrew from removing empty folders.
|
2017-10-21 12:50:49 +05:30
|
|
|
EOS
|
|
|
|
severity: :convention,
|
|
|
|
line: 4,
|
|
|
|
column: 2,
|
|
|
|
source: source }]
|
2017-08-13 14:50:29 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-13 14:50:29 +05:30
|
|
|
|
2017-08-12 23:28:08 +05:30
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
2017-08-14 00:02:44 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "build.universal? deprecated usage" do
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
2017-08-14 00:02:44 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
2017-10-21 12:50:49 +05:30
|
|
|
if build.universal?
|
|
|
|
"foo"
|
|
|
|
end
|
2017-08-14 00:02:44 +05:30
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "macOS has been 64-bit only since 10.6 so build.universal? is deprecated.",
|
|
|
|
severity: :convention,
|
|
|
|
line: 4,
|
|
|
|
column: 5,
|
|
|
|
source: source }]
|
2017-08-14 00:02:44 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-14 00:02:44 +05:30
|
|
|
|
2017-08-14 01:09:06 +05:30
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
2017-10-12 00:29:19 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "build.universal? deprecation exempted formula" do
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
2017-10-21 12:50:49 +05:30
|
|
|
class Wine < Formula
|
2017-08-14 01:09:06 +05:30
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
2017-10-21 12:50:49 +05:30
|
|
|
if build.universal?
|
|
|
|
"foo"
|
|
|
|
end
|
2017-08-14 01:09:06 +05:30
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
inspect_source(source, "/homebrew-core/Formula/wine.rb")
|
2017-10-09 14:20:08 -04:00
|
|
|
expect(cop.offenses).to be_empty
|
2017-08-14 01:25:44 +05:30
|
|
|
end
|
2017-10-12 00:29:19 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "deprecated ENV.universal_binary usage" do
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
2017-08-14 01:25:44 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
2017-10-21 12:50:49 +05:30
|
|
|
if build?
|
|
|
|
ENV.universal_binary
|
|
|
|
end
|
2017-08-14 01:25:44 +05:30
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "macOS has been 64-bit only since 10.6 so ENV.universal_binary is deprecated.",
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 5,
|
|
|
|
source: source }]
|
2017-08-14 01:25:44 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-14 01:25:44 +05:30
|
|
|
|
2017-08-14 00:02:44 +05:30
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
2017-08-14 01:52:48 +05:30
|
|
|
|
2017-10-21 13:26:25 +05:30
|
|
|
it "ENV.universal_binary deprecation exempted formula" do
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
2017-10-08 21:46:32 -04:00
|
|
|
class Wine < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
if build?
|
2017-10-21 13:26:25 +05:30
|
|
|
ENV.universal_binary
|
2017-10-08 21:46:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
|
|
|
inspect_source(source, "/homebrew-core/Formula/wine.rb")
|
2017-10-09 14:20:08 -04:00
|
|
|
expect(cop.offenses).to be_empty
|
2017-10-08 21:46:32 -04:00
|
|
|
end
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "deprecated ENV.x11 usage" do
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
2017-08-14 01:52:48 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
2017-10-21 12:50:49 +05:30
|
|
|
if build?
|
|
|
|
ENV.x11
|
2017-08-14 01:52:48 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: 'Use "depends_on :x11" instead of "ENV.x11"',
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 5,
|
|
|
|
source: source }]
|
2017-08-14 01:52:48 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-14 01:52:48 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
2017-08-14 01:55:47 +05:30
|
|
|
|
2017-10-21 13:26:25 +05:30
|
|
|
it "install_name_tool usage instead of ruby-macho" do
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
2017-08-14 01:55:47 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
2017-10-21 12:50:49 +05:30
|
|
|
system "install_name_tool", "-id"
|
2017-08-14 01:55:47 +05:30
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: 'Use ruby-macho instead of calling "install_name_tool"',
|
|
|
|
severity: :convention,
|
|
|
|
line: 4,
|
|
|
|
column: 10,
|
|
|
|
source: source }]
|
2017-08-14 01:55:47 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-14 01:55:47 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
2017-08-14 02:14:20 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "ruby-macho alternatives audit exempted formula" do
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
2017-10-21 12:50:49 +05:30
|
|
|
class Cctools < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
system "install_name_tool", "-id"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
|
|
|
inspect_source(source, "/homebrew-core/Formula/cctools.rb")
|
2017-10-21 13:26:25 +05:30
|
|
|
expect(cop.offenses).to be_empty
|
2017-10-21 12:50:49 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "npm install without language::Node args" do
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
2017-08-14 02:14:20 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
2017-10-21 12:50:49 +05:30
|
|
|
system "npm", "install"
|
2017-08-14 02:14:20 +05:30
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Use Language::Node for npm install args",
|
|
|
|
severity: :convention,
|
|
|
|
line: 4,
|
|
|
|
column: 2,
|
|
|
|
source: source }]
|
2017-08-14 02:14:20 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-14 02:14:20 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
2017-08-14 02:18:46 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "npm install without language::Node args in kibana(exempted formula)" do
|
2017-10-15 02:28:32 +02:00
|
|
|
source = <<~EOS
|
2017-10-21 12:50:49 +05:30
|
|
|
class KibanaAT44 < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
system "npm", "install"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
|
|
|
inspect_source(source, "/homebrew-core/Formula/kibana@4.4.rb")
|
2017-10-21 13:26:25 +05:30
|
|
|
expect(cop.offenses).to be_empty
|
2017-10-21 12:50:49 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "depends_on with an instance as argument" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-14 02:18:46 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
2017-10-21 12:50:49 +05:30
|
|
|
depends_on FOO::BAR.new
|
2017-08-14 02:18:46 +05:30
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "`depends_on` can take requirement classes instead of instances",
|
|
|
|
severity: :convention,
|
|
|
|
line: 4,
|
|
|
|
column: 13,
|
|
|
|
source: source }]
|
2017-08-14 02:18:46 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-14 02:18:46 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
2017-08-14 02:32:29 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "old style OS check" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-14 02:32:29 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
2017-10-21 12:50:49 +05:30
|
|
|
depends_on :foo if MacOS.snow_leopard?
|
2017-08-14 02:32:29 +05:30
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "\"MacOS.snow_leopard?\" is deprecated, use a comparison to MacOS.version instead",
|
|
|
|
severity: :convention,
|
|
|
|
line: 4,
|
|
|
|
column: 21,
|
|
|
|
source: source }]
|
2017-08-14 02:32:29 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-14 02:32:29 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
2017-08-14 02:43:54 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "non glob DIR usage" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-14 02:43:54 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
2017-10-21 12:50:49 +05:30
|
|
|
rm_rf Dir["src/{llvm,test,librustdoc,etc/snapshot.pyc}"]
|
|
|
|
rm_rf Dir["src/snapshot.pyc"]
|
2017-08-14 02:43:54 +05:30
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: 'Dir(["src/snapshot.pyc"]) is unnecessary; just use "src/snapshot.pyc"',
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 13,
|
|
|
|
source: source }]
|
2017-08-14 02:43:54 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-14 02:43:54 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
2017-08-14 02:47:29 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "system call to fileUtils Method" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-14 02:47:29 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
2017-10-21 12:50:49 +05:30
|
|
|
system "mkdir", "foo"
|
2017-08-14 02:47:29 +05:30
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: 'Use the `mkdir` Ruby method instead of `system "mkdir", "foo"`',
|
|
|
|
severity: :convention,
|
|
|
|
line: 4,
|
|
|
|
column: 10,
|
|
|
|
source: source }]
|
2017-08-14 02:47:29 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-14 02:47:29 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
2017-08-14 02:49:52 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "top-level function def outside class body" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-10-21 12:50:49 +05:30
|
|
|
def test
|
|
|
|
nil
|
|
|
|
end
|
2017-08-14 02:49:52 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Define method test in the class body, not at the top-level",
|
|
|
|
severity: :convention,
|
|
|
|
line: 1,
|
|
|
|
column: 0,
|
|
|
|
source: source }]
|
2017-08-14 02:49:52 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-14 02:49:52 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
2017-08-14 15:22:44 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "Using ARGV to check options" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-14 15:22:44 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
2017-08-14 20:10:45 +05:30
|
|
|
def install
|
2017-08-14 15:22:44 +05:30
|
|
|
verbose = ARGV.verbose?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Use build instead of ARGV to check options",
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 14,
|
|
|
|
source: source }]
|
2017-08-14 15:22:44 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-14 15:22:44 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
2017-08-14 15:41:03 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it 'man+"man8" usage' do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-14 15:41:03 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
2017-08-14 20:10:45 +05:30
|
|
|
def install
|
2017-08-14 15:41:03 +05:30
|
|
|
man1.install man+"man8" => "faad.1"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: '"man+"man8"" should be "man8"',
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 22,
|
|
|
|
source: source }]
|
2017-08-14 15:41:03 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-14 15:41:03 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
2017-08-14 19:58:39 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "hardcoded gcc compiler" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-14 19:58:39 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
2017-08-14 20:10:45 +05:30
|
|
|
def install
|
2017-08-14 19:58:39 +05:30
|
|
|
system "/usr/bin/gcc", "foo"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Use \"\#{ENV.cc}\" instead of hard-coding \"gcc\"",
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 12,
|
|
|
|
source: source }]
|
2017-08-14 19:58:39 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-14 19:58:39 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "hardcoded g++ compiler" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-14 19:58:39 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
2017-08-14 20:10:45 +05:30
|
|
|
def install
|
2017-08-14 19:58:39 +05:30
|
|
|
system "/usr/bin/g++", "-o", "foo", "foo.cc"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Use \"\#{ENV.cxx}\" instead of hard-coding \"g++\"",
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 12,
|
|
|
|
source: source }]
|
2017-08-14 19:58:39 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-14 19:58:39 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
2017-08-14 20:10:45 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "hardcoded llvm-g++ compiler" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-14 20:10:45 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
def install
|
|
|
|
ENV["COMPILER_PATH"] = "/usr/bin/llvm-g++"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Use \"\#{ENV.cxx}\" instead of hard-coding \"llvm-g++\"",
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 28,
|
|
|
|
source: source }]
|
2017-08-14 20:10:45 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-14 20:10:45 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "hardcoded gcc compiler" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-14 20:10:45 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
def install
|
|
|
|
ENV["COMPILER_PATH"] = "/usr/bin/gcc"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Use \"\#{ENV.cc}\" instead of hard-coding \"gcc\"",
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 28,
|
|
|
|
source: source }]
|
2017-08-14 20:10:45 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-14 20:10:45 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
2017-08-14 21:34:01 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "formula path shortcut : man" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-14 21:34:01 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
def install
|
|
|
|
mv "\#{share}/man", share
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: '"#{share}/man" should be "#{man}"',
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 17,
|
|
|
|
source: source }]
|
2017-08-14 21:34:01 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-14 21:34:01 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
2017-08-14 22:44:28 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "formula path shortcut : libexec" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-14 22:44:28 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
def install
|
|
|
|
mv "\#{prefix}/libexec", share
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "\"\#\{prefix}/libexec\" should be \"\#{libexec}\"",
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 18,
|
|
|
|
source: source }]
|
2017-08-14 22:44:28 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-14 22:44:28 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "formula path shortcut : info" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-14 22:44:28 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
def install
|
|
|
|
system "./configure", "--INFODIR=\#{prefix}/share/info"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "\"\#\{prefix}/share/info\" should be \"\#{info}\"",
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 47,
|
|
|
|
source: source }]
|
2017-08-14 22:44:28 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-14 22:44:28 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
2017-10-12 00:29:19 +05:30
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "formula path shortcut : man8" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-14 22:44:28 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
def install
|
|
|
|
system "./configure", "--MANDIR=\#{prefix}/share/man/man8"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "\"\#\{prefix}/share/man/man8\" should be \"\#{man8}\"",
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 46,
|
|
|
|
source: source }]
|
2017-08-14 22:44:28 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-14 22:44:28 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "dependecies which have to vendored" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-14 23:05:00 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
depends_on "lpeg" => :lua51
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "lua modules should be vendored rather than use deprecated depends_on \"lpeg\" => :lua51`",
|
|
|
|
severity: :convention,
|
|
|
|
line: 4,
|
|
|
|
column: 24,
|
|
|
|
source: source }]
|
2017-08-14 23:05:00 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-14 23:05:00 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "manually setting env" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-14 23:32:06 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
system "export", "var=value"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Use ENV instead of invoking 'export' to modify the environment",
|
|
|
|
severity: :convention,
|
|
|
|
line: 4,
|
|
|
|
column: 10,
|
|
|
|
source: source }]
|
2017-08-14 23:32:06 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-14 23:32:06 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "dependencies with invalid options" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-15 00:05:50 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
depends_on "foo" => "with-bar"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Dependency foo should not use option with-bar",
|
|
|
|
severity: :convention,
|
|
|
|
line: 4,
|
|
|
|
column: 13,
|
|
|
|
source: source }]
|
2017-08-15 00:05:50 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-15 00:05:50 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "inspecting version manually" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-15 00:29:58 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
if version == "HEAD"
|
|
|
|
foo()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Use 'build.head?' instead of inspecting 'version'",
|
|
|
|
severity: :convention,
|
|
|
|
line: 4,
|
|
|
|
column: 5,
|
|
|
|
source: source }]
|
2017-08-15 00:29:58 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-15 00:29:58 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "deprecated ENV.fortran usage" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-15 00:32:34 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
test do
|
|
|
|
ENV.fortran
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Use `depends_on :fortran` instead of `ENV.fortran`",
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 4,
|
|
|
|
source: source }]
|
2017-08-15 00:32:34 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-15 00:32:34 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "deprecated ARGV.include? (--HEAD) usage" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-15 00:36:37 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
test do
|
|
|
|
head = ARGV.include? "--HEAD"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: 'Use "if build.head?" instead',
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 26,
|
|
|
|
source: source }]
|
2017-08-15 00:36:37 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-15 00:36:37 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "deprecated MACOS_VERSION const usage" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-15 00:42:56 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
test do
|
|
|
|
version = MACOS_VERSION
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: "Use MacOS.version instead of MACOS_VERSION",
|
|
|
|
severity: :convention,
|
|
|
|
line: 5,
|
|
|
|
column: 14,
|
|
|
|
source: source }]
|
2017-08-15 00:42:56 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-15 00:42:56 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "deprecated if build.with? conditional dependency" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-15 16:09:32 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
depends_on "foo" if build.with? "with-foo"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: 'Replace depends_on "foo" if build.with? "with-foo" with depends_on "foo" => :optional',
|
|
|
|
severity: :convention,
|
|
|
|
line: 4,
|
|
|
|
column: 2,
|
|
|
|
source: source }]
|
2017-08-15 16:09:32 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-15 16:09:32 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "unless conditional dependency with build.without?" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-15 16:09:32 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
depends_on :foo unless build.without? "foo"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: 'Replace depends_on :foo unless build.without? "foo" with depends_on :foo => :recommended',
|
|
|
|
severity: :convention,
|
|
|
|
line: 4,
|
|
|
|
column: 2,
|
|
|
|
source: source }]
|
2017-08-15 16:09:32 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-15 16:09:32 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
it "unless conditional dependency with build.include?" do
|
2017-10-21 13:26:25 +05:30
|
|
|
source = <<~EOS
|
2017-08-15 16:09:32 +05:30
|
|
|
class Foo < Formula
|
|
|
|
desc "foo"
|
|
|
|
url 'http://example.com/foo-1.0.tgz'
|
|
|
|
depends_on :foo unless build.include? "without-foo"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
|
2017-10-21 12:50:49 +05:30
|
|
|
expected_offenses = [{ message: 'Replace depends_on :foo unless build.include? "without-foo" with depends_on :foo => :recommended',
|
|
|
|
severity: :convention,
|
|
|
|
line: 4,
|
|
|
|
column: 2,
|
|
|
|
source: source }]
|
2017-08-15 16:09:32 +05:30
|
|
|
|
2017-10-12 00:29:19 +05:30
|
|
|
inspect_source(source)
|
2017-08-15 16:09:32 +05:30
|
|
|
|
|
|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
|
|
|
expect_offense(expected, actual)
|
|
|
|
end
|
|
|
|
end
|
2017-08-02 23:49:51 +05:30
|
|
|
end
|
|
|
|
end
|