Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include test casks in the cask style check. #6482

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Library/.rubocop_cask.yml
Expand Up @@ -3,6 +3,8 @@ inherit_from: ./.rubocop_shared.yml
Cask/HomepageMatchesUrl:
Description: 'Ensure that the homepage and url match, otherwise add a comment. More info at https://github.com/Homebrew/homebrew-cask/blob/master/doc/cask_language_reference/stanzas/url.md#when-url-and-homepage-hostnames-differ-add-a-comment'
Enabled: true
Exclude:
- '**/test/support/fixtures/cask/Casks/**/*.rb'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Cask/HomepageMatchesUrl cop was failing (bad URI(is not URI?)) with any test cask that included a url with ”file://...“. To not make this pull request too big, I thought it would make sense to exclude this check for now in the test cask directory and follow up with a fix to enable this cop after. What do you think?


Cask/HomepageUrlTrailingSlash:
Description: 'Ensure that the homepage url has a slash after the domain name.'
Expand Down
9 changes: 8 additions & 1 deletion Library/Homebrew/cask/cmd/style.rb
Expand Up @@ -31,7 +31,7 @@ def install_rubocop

def cask_paths
@cask_paths ||= if args.empty?
Tap.map(&:cask_dir).select(&:directory?)
Tap.map(&:cask_dir).select(&:directory?).concat(test_cask_paths)
elsif args.any? { |file| File.exist?(file) }
args.map { |path| Pathname(path).expand_path }
else
Expand All @@ -51,6 +51,13 @@ def default_args
]
end

def test_cask_paths
[
Pathname.new("#{HOMEBREW_LIBRARY}/Homebrew/test/support/fixtures/cask/Casks"),
Pathname.new("#{HOMEBREW_LIBRARY}/Homebrew/test/support/fixtures/third-party/Casks"),
]
end

def normal_args
default_args + ["--parallel"]
end
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/test/cask/cmd/home_spec.rb
Expand Up @@ -10,13 +10,13 @@
it_behaves_like "a command that handles invalid options"

it "opens the homepage for the specified Cask" do
expect(described_class).to receive(:open_url).with("https://brew.sh")
expect(described_class).to receive(:open_url).with("https://brew.sh/")
described_class.run("local-caffeine")
end

it "works for multiple Casks" do
expect(described_class).to receive(:open_url).with("https://brew.sh")
expect(described_class).to receive(:open_url).with("https://brew.sh")
expect(described_class).to receive(:open_url).with("https://brew.sh/")
expect(described_class).to receive(:open_url).with("https://brew.sh/")
described_class.run("local-caffeine", "local-transmission")
end

Expand Down
14 changes: 7 additions & 7 deletions Library/Homebrew/test/cask/cmd/info_spec.rb
Expand Up @@ -12,7 +12,7 @@
described_class.run("local-caffeine")
}.to output(<<~EOS).to_stdout
local-caffeine: 1.2.3
https://brew.sh
https://brew.sh/
Not installed
From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/local-caffeine.rb
==> Name
Expand Down Expand Up @@ -41,7 +41,7 @@
let(:expected_output) {
<<~EOS
local-caffeine: 1.2.3
https://brew.sh
https://brew.sh/
Not installed
From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/local-caffeine.rb
==> Name
Expand All @@ -50,7 +50,7 @@
Caffeine.app (App)

local-transmission: 2.61
https://brew.sh
https://brew.sh/
Not installed
From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/local-transmission.rb
==> Name
Expand All @@ -72,7 +72,7 @@
described_class.run("with-caveats")
}.to output(<<~EOS).to_stdout
with-caveats: 1.2.3
https://brew.sh
https://brew.sh/
Not installed
From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/with-caveats.rb
==> Name
Expand All @@ -97,7 +97,7 @@
described_class.run("with-conditional-caveats")
}.to output(<<~EOS).to_stdout
with-conditional-caveats: 1.2.3
https://brew.sh
https://brew.sh/
Not installed
From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/with-conditional-caveats.rb
==> Name
Expand All @@ -112,7 +112,7 @@
described_class.run("with-languages")
}.to output(<<~EOS).to_stdout
with-languages: 1.2.3
https://brew.sh
https://brew.sh/
Not installed
From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/with-languages.rb
==> Name
Expand All @@ -129,7 +129,7 @@
described_class.run("without-languages")
}.to output(<<~EOS).to_stdout
without-languages: 1.2.3
https://brew.sh
https://brew.sh/
Not installed
From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/without-languages.rb
==> Name
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/cask/cmd/internal_stanza_spec.rb
Expand Up @@ -5,7 +5,7 @@
command = described_class.new("homepage", "local-caffeine")
expect {
command.run
}.to output("https://brew.sh\n").to_stdout
}.to output("https://brew.sh/\n").to_stdout
end

it "raises an exception when stanza is unknown/unsupported" do
Expand Down
8 changes: 6 additions & 2 deletions Library/Homebrew/test/cask/cmd/style_spec.rb
Expand Up @@ -80,8 +80,12 @@
end

it {
expect(subject).to contain_exactly(a_path_ending_with("/homebrew/homebrew-cask/Casks"),
a_path_ending_with("/third-party/homebrew-tap/Casks"))
expect(subject).to contain_exactly(
a_path_ending_with("/homebrew/homebrew-cask/Casks"),
a_path_ending_with("/third-party/homebrew-tap/Casks"),
a_path_ending_with("/Homebrew/test/support/fixtures/cask/Casks"),
a_path_ending_with("/Homebrew/test/support/fixtures/third-party/Casks"),
)
}
end

Expand Down
Expand Up @@ -3,7 +3,7 @@
sha256 'badbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadb'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://brew.sh'
homepage 'https://brew.sh/'

app 'Caffeine.app'
end
Expand Up @@ -3,6 +3,6 @@

url do
# to be lazily evaluated
fail 'Boom'
raise 'Boom'
end
end
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://brew.sh'
homepage 'https://brew.sh/'

installer manual: 'Caffeine.app'

Expand Down
@@ -1,9 +1,9 @@
cask => 'invalid-header-format' do
cask 'invalid-header-format', :invalid do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't an auto-fix, but with cask =>, Rubocop was unable to parse the invalid Ruby.

version '1.2.3'
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://brew.sh'
homepage 'https://brew.sh/'

app 'Caffeine.app'
end
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://brew.sh'
homepage 'https://brew.sh/'

app 'Caffeine.app'
end
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://brew.sh'
homepage 'https://brew.sh/'

app 'Caffeine.app'
end
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://brew.sh'
homepage 'https://brew.sh/'
homepage 'https://www.brew.sh/local-caffeine'

app 'Caffeine.app'
Expand Down
Expand Up @@ -4,7 +4,7 @@

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
url 'https://brew.sh/caffeine.zip'
homepage 'https://brew.sh'
homepage 'https://brew.sh/'

app 'Caffeine.app'
end
Expand Up @@ -4,7 +4,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://brew.sh'
homepage 'https://brew.sh/'

app 'Caffeine.app'
end
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://brew.sh'
homepage 'https://brew.sh/'

app 'Caffeine.app'
end
@@ -1,10 +1,10 @@
cask 'local-transmission' do
name 'Transmission'
version '2.61'
sha256 'e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68'

url "file://#{TEST_FIXTURE_DIR}/cask/transmission-2.61.dmg"
homepage 'https://brew.sh'
name 'Transmission'
homepage 'https://brew.sh/'

app 'Transmission.app'
end
Expand Up @@ -2,7 +2,7 @@
version '1.2.3'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://brew.sh'
homepage 'https://brew.sh/'

app 'Caffeine.app'
end
@@ -1,5 +1,5 @@
cask 'missing-url' do
version '1.2.3'

homepage 'https://brew.sh'
homepage 'https://brew.sh/'
end
@@ -1,4 +1,4 @@
cask 'missing-version' do
url 'https://localhost/something.dmg'
homepage 'https://brew.sh'
url 'https://brew.sh/TestCask.dmg'
homepage 'https://brew.sh/'
end
Expand Up @@ -3,7 +3,7 @@
sha256 :no_check

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://brew.sh'
homepage 'https://brew.sh/'

app 'Caffeine.app'
end
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://brew.sh'
homepage 'https://brew.sh/'

app 'Caffeine.app'
end
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://brew.sh'
homepage 'https://brew.sh/'

app 'Caffeine.app'
end
Expand Up @@ -3,7 +3,7 @@
sha256 'e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68'

url "file://#{TEST_FIXTURE_DIR}/cask/transmission-2.61.dmg"
homepage 'https://brew.sh'
homepage 'https://brew.sh/'

app 'Transmission.app'
end
Expand Up @@ -3,7 +3,7 @@
sha256 :no_check

url "file://#{TEST_FIXTURE_DIR}/cask/caffeines.zip"
homepage 'https://brew.sh'
homepage 'https://brew.sh/'

app 'Caffeine Mini.app'
app 'Caffeine Pro.app'
Expand Down
Expand Up @@ -3,7 +3,7 @@
sha256 :no_check

url "file://#{TEST_FIXTURE_DIR}/cask/caffeines.zip"
homepage 'https://brew.sh'
homepage 'https://brew.sh/'

app 'Caffeine Mini.app'
app 'Caffeine Pro.app'
Expand Down
Expand Up @@ -3,7 +3,7 @@
sha256 'e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68'

url "file://#{TEST_FIXTURE_DIR}/cask/transmission-2.61.dmg"
homepage 'https://brew.sh'
homepage 'https://brew.sh/'

app 'container'
end
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://brew.sh'
homepage 'https://brew.sh/'

app 'Caffeine.app', target: 'AnotherName.app'
end
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://brew.sh'
homepage 'https://brew.sh/'

app 'Caffeine.app'

Expand Down
Expand Up @@ -3,12 +3,12 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://brew.sh'
homepage 'https://brew.sh/'

app 'Caffeine.app'

# a do block may print and use a DSL
caveats do
puts 'This caveat is conditional' if false # rubocop:disable Lint/LiteralInCondition
puts 'This caveat is conditional' if false # rubocop:disable Lint/LiteralAsCondition
end
end
Expand Up @@ -7,7 +7,7 @@

pkg 'MyFancyPkg/Fancy.pkg'

uninstall script: { executable: 'MyFancyPkg/FancyUninstaller.tool', args: %w[--please] },
uninstall script: { executable: 'MyFancyPkg/FancyUninstaller.tool', args: ['--please'] },
quit: 'my.fancy.package.app',
login_item: 'Fancy',
delete: [
Expand Down
Expand Up @@ -3,7 +3,7 @@
sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'

url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://brew.sh'
homepage 'https://brew.sh/'

installer manual: 'Caffeine.app'
end