Skip to content

Commit

Permalink
Merge pull request #6306 from rolandwalker/install_script_improvements
Browse files Browse the repository at this point in the history
make `install_script` stanza more robust
  • Loading branch information
rolandwalker committed Sep 25, 2014
2 parents de55766 + 6d622ed commit 83efd96
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
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

0 comments on commit 83efd96

Please sign in to comment.