| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							|  |  |  | describe RuboCop::Cop::FormulaAudit::Homepage do | 
					
						
							|  |  |  |   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 | 
					
						
							| 
									
										
										
										
											2021-01-12 15:58:52 +11:00
										 |  |  |         ^^^^^^^^^^^^^^^^^^^ 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" | 
					
						
							|  |  |  |                    ^^^^^^^^^^^^^^^^^^^ The homepage should start with http or https. | 
					
						
							|  |  |  |           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" | 
					
						
							|  |  |  |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Freedesktop homepages should be styled `https://wiki.freedesktop.org/project_name` | 
					
						
							|  |  |  |           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" | 
					
						
							|  |  |  |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Freedesktop homepages should be styled `https://wiki.freedesktop.org/www/Software/project_name` | 
					
						
							|  |  |  |           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" | 
					
						
							|  |  |  |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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" | 
					
						
							|  |  |  |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ GitHub homepages should not end with .git | 
					
						
							|  |  |  |           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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00: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/" | 
					
						
							|  |  |  |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Sourceforge homepages should be `https://foo.sourceforge.io/` | 
					
						
							|  |  |  |             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" | 
					
						
							|  |  |  |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Sourceforge homepages should be `https://foo.sourceforge.io/` | 
					
						
							|  |  |  |             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/" | 
					
						
							|  |  |  |                      ^^^^^^^^^^^^^^^^^^^^ Sourceforge homepages should be `https://foo.sourceforge.io/` | 
					
						
							|  |  |  |             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" | 
					
						
							|  |  |  |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Readthedocs homepages should be `https://foo.readthedocs.io` | 
					
						
							|  |  |  |           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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 15:58:52 +11:00
										 |  |  |         expected_offenses = [{  message:  "Please use https:// for #{homepage}", | 
					
						
							|  |  |  |                                 severity: :convention, | 
					
						
							|  |  |  |                                 line:     2, | 
					
						
							|  |  |  |                                 column:   11, | 
					
						
							|  |  |  |                                 source:   source }] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         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 |