2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-26 19:41:14 +01:00
|
|
|
require "rubocops/homepage"
|
2017-05-14 13:49:42 +05:30
|
|
|
|
2024-02-18 15:11:11 -08:00
|
|
|
RSpec.describe RuboCop::Cop::FormulaAudit::Homepage do
|
2017-05-14 13:49:42 +05:30
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
2021-01-14 18:55:31 -08:00
|
|
|
context "when auditing homepage" do
|
2021-01-12 15:58:52 +11:00
|
|
|
it "reports an offense when there is no homepage" do
|
|
|
|
expect_offense(<<~RUBY)
|
2017-05-14 13:49:42 +05:30
|
|
|
class Foo < Formula
|
2023-04-07 17:16:48 +01:00
|
|
|
^^^^^^^^^^^^^^^^^^^ FormulaAudit/Homepage: Formula should have a homepage.
|
2018-11-28 20:51:55 +01:00
|
|
|
url 'https://brew.sh/foo-1.0.tgz'
|
2017-05-14 13:49:42 +05:30
|
|
|
end
|
2018-07-11 15:17:40 +02:00
|
|
|
RUBY
|
2021-01-12 15:58:52 +11:00
|
|
|
end
|
2017-05-14 13:49:42 +05:30
|
|
|
|
2021-01-12 15:58:52 +11:00
|
|
|
it "reports an offense when the homepage is not HTTP or HTTPS" do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
class Foo < Formula
|
|
|
|
homepage "ftp://brew.sh/foo"
|
2025-05-30 16:42:32 -04:00
|
|
|
^^^^^^^^^^^^^^^^^^^ FormulaAudit/Homepage: The `homepage` should start with http or https.
|
2021-01-12 15:58:52 +11:00
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
2017-05-14 13:49:42 +05:30
|
|
|
|
2021-01-12 15:58:52 +11:00
|
|
|
it "reports an offense for freedesktop.org wiki pages" do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
class Foo < Formula
|
|
|
|
homepage "http://www.freedesktop.org/wiki/bar"
|
2025-05-30 16:42:32 -04:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Homepage: Freedesktop homepages should be styled: https://wiki.freedesktop.org/project_name
|
2021-01-12 15:58:52 +11:00
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
2017-05-14 13:49:42 +05:30
|
|
|
|
2021-01-12 15:58:52 +11:00
|
|
|
it "reports an offense for freedesktop.org software wiki pages" do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
class Foo < Formula
|
|
|
|
homepage "http://www.freedesktop.org/wiki/Software/baz"
|
2025-05-30 16:42:32 -04:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Homepage: Freedesktop homepages should be styled: https://wiki.freedesktop.org/www/Software/project_name
|
2021-01-12 15:58:52 +11:00
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
end
|
|
|
|
RUBY
|
2017-05-14 13:49:42 +05:30
|
|
|
end
|
|
|
|
|
2021-01-12 15:58:52 +11:00
|
|
|
it "reports and corrects Google Code homepages" do
|
|
|
|
expect_offense(<<~RUBY)
|
2017-05-14 13:49:42 +05:30
|
|
|
class Foo < Formula
|
2021-01-12 15:58:52 +11:00
|
|
|
homepage "https://code.google.com/p/qux"
|
2023-04-07 17:16:48 +01:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Homepage: Google Code homepages should end with a slash
|
2018-11-28 20:51:55 +01:00
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
2017-05-14 13:49:42 +05:30
|
|
|
end
|
2018-07-11 15:17:40 +02:00
|
|
|
RUBY
|
2017-05-14 13:49:42 +05:30
|
|
|
|
2021-01-12 15:58:52 +11:00
|
|
|
expect_correction(<<~RUBY)
|
|
|
|
class Foo < Formula
|
|
|
|
homepage "https://code.google.com/p/qux/"
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
2017-05-14 13:49:42 +05:30
|
|
|
|
2021-01-12 15:58:52 +11:00
|
|
|
it "reports and corrects GitHub homepages" do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
class Foo < Formula
|
|
|
|
homepage "https://github.com/foo/bar.git"
|
2023-04-07 17:16:48 +01:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Homepage: GitHub homepages should not end with .git
|
2021-01-12 15:58:52 +11:00
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
expect_correction(<<~RUBY)
|
|
|
|
class Foo < Formula
|
|
|
|
homepage "https://github.com/foo/bar"
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
2017-05-14 13:49:42 +05:30
|
|
|
|
2025-05-30 16:42:32 -04:00
|
|
|
describe "for SourceForge" do
|
2021-01-12 15:58:52 +11:00
|
|
|
correct_formula = <<~RUBY
|
|
|
|
class Foo < Formula
|
|
|
|
homepage "https://foo.sourceforge.io/"
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
it "reports and corrects [1]" do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
class Foo < Formula
|
|
|
|
homepage "http://foo.sourceforge.net/"
|
2025-05-30 16:42:32 -04:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Homepage: SourceForge homepages should be: https://foo.sourceforge.io/
|
2021-01-12 15:58:52 +11:00
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
expect_correction(correct_formula)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "reports and corrects [2]" do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
class Foo < Formula
|
|
|
|
homepage "http://foo.sourceforge.net"
|
2025-05-30 16:42:32 -04:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Homepage: SourceForge homepages should be: https://foo.sourceforge.io/
|
2021-01-12 15:58:52 +11:00
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
expect_correction(correct_formula)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "reports and corrects [3]" do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
class Foo < Formula
|
|
|
|
homepage "http://foo.sf.net/"
|
2025-05-30 16:42:32 -04:00
|
|
|
^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Homepage: SourceForge homepages should be: https://foo.sourceforge.io/
|
2021-01-12 15:58:52 +11:00
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
expect_correction(correct_formula)
|
2017-05-14 13:49:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-12 15:58:52 +11:00
|
|
|
it "reports and corrects readthedocs.org pages" do
|
|
|
|
expect_offense(<<~RUBY)
|
|
|
|
class Foo < Formula
|
|
|
|
homepage "https://foo.readthedocs.org"
|
2025-05-30 16:42:32 -04:00
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Homepage: Readthedocs homepages should be: https://foo.readthedocs.io
|
2021-01-12 15:58:52 +11:00
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
expect_correction(<<~RUBY)
|
|
|
|
class Foo < Formula
|
|
|
|
homepage "https://foo.readthedocs.io"
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
|
|
|
it "reports an offense for HTTP homepages" do
|
2017-05-14 13:49:42 +05:30
|
|
|
formula_homepages = {
|
2021-01-12 15:58:52 +11:00
|
|
|
"sf" => "http://foo.sourceforge.io/",
|
2018-11-02 17:18:07 +00:00
|
|
|
"corge" => "http://savannah.nongnu.org/corge",
|
2017-05-14 13:49:42 +05:30
|
|
|
"grault" => "http://grault.github.io/",
|
|
|
|
"garply" => "http://www.gnome.org/garply",
|
2018-11-02 17:18:07 +00:00
|
|
|
"waldo" => "http://www.gnu.org/waldo",
|
2021-01-12 15:58:52 +11:00
|
|
|
"dotgit" => "http://github.com/quux",
|
2017-05-14 13:49:42 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
formula_homepages.each do |name, homepage|
|
2018-07-11 15:17:40 +02:00
|
|
|
source = <<~RUBY
|
2017-05-14 13:49:42 +05:30
|
|
|
class #{name.capitalize} < Formula
|
|
|
|
homepage "#{homepage}"
|
2018-11-28 20:51:55 +01:00
|
|
|
url "https://brew.sh/#{name}-1.0.tgz"
|
2017-05-14 13:49:42 +05:30
|
|
|
end
|
2018-07-11 15:17:40 +02:00
|
|
|
RUBY
|
2017-05-14 13:49:42 +05:30
|
|
|
|
2023-04-07 17:16:48 +01:00
|
|
|
expected_offenses = [{ message: "FormulaAudit/Homepage: Please use https:// for #{homepage}",
|
2021-01-12 15:58:52 +11:00
|
|
|
severity: :convention,
|
|
|
|
line: 2,
|
|
|
|
column: 11,
|
2024-03-07 16:20:20 +00:00
|
|
|
source: }]
|
2021-01-12 15:58:52 +11:00
|
|
|
|
|
|
|
expected_offenses.zip([inspect_source(source).last]).each do |expected, actual|
|
|
|
|
expect(actual.message).to eq(expected[:message])
|
|
|
|
expect(actual.severity).to eq(expected[:severity])
|
|
|
|
expect(actual.line).to eq(expected[:line])
|
|
|
|
expect(actual.column).to eq(expected[:column])
|
2017-05-14 13:49:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|