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

make install_script stanza more robust #6306

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/cask/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,16 @@ def self.ordinary_artifact_types
end

def install_script(*args)
executable = args.shift
args = Hash.new(*args)
args.merge!({ :executable => executable })
unless args.length > 0
raise CaskInvalidError.new(self.title, "'install_script' stanza requires an argument")
end
executable = args.shift if args[0].kind_of? String
if args.length > 0
args = Hash.new().merge(*args)
else
args = Hash.new()
end
args.merge!({ :executable => executable }) if executable
artifacts[:install_script] << args
end

Expand Down
6 changes: 5 additions & 1 deletion test/cask/dsl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,11 @@ def caveats; <<-EOS.undent
describe "install_script stanza" do
it "allows install_script to be specified" do
cask = Cask.load('with-install-script')
cask.artifacts[:install_script].first[:executable].must_equal '/usr/bin/true'
# the sorts are needed to force the order for Ruby 1.8
cask.artifacts[:install_script].sort{ |a,b| a[:executable] <=> b[:executable] }.first[:executable].must_equal '/usr/bin/false'
cask.artifacts[:install_script].sort{ |a,b| a[:executable] <=> b[:executable] }.first[:args].must_equal ['--flag']
cask.artifacts[:install_script].sort{ |a,b| a[:executable] <=> b[:executable] }.to_a[1][:executable].must_equal '/usr/bin/true'
cask.artifacts[:install_script].sort{ |a,b| a[:executable] <=> b[:executable] }.to_a[1][:args].must_equal ['--flag']
end
end

Expand Down
6 changes: 5 additions & 1 deletion test/support/Casks/with-install-script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ class WithInstallScript < TestCask
homepage 'http://example.com/with-install-script'
version '1.2.3'
sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853'
install_script '/usr/bin/true'
install_script '/usr/bin/true',
:args => ['--flag']
# acceptable alternate form
install_script :executable => '/usr/bin/false',
:args => ['--flag']
end