From 5b593ebb8958cc57cfbbd7013ca3d275466d66bf Mon Sep 17 00:00:00 2001 From: Joshua Hagins Date: Tue, 30 Aug 2016 21:51:40 -0400 Subject: [PATCH] Allow deprecated hash syntax in Cask headers --- Library/Homebrew/cask/lib/hbc/source/path_base.rb | 4 ++++ Library/Homebrew/cask/test/cask/dsl_test.rb | 9 +++++++++ .../Homebrew/cask/test/support/Casks/with-dsl-version.rb | 9 +++++++++ 3 files changed, 22 insertions(+) create mode 100644 Library/Homebrew/cask/test/support/Casks/with-dsl-version.rb diff --git a/Library/Homebrew/cask/lib/hbc/source/path_base.rb b/Library/Homebrew/cask/lib/hbc/source/path_base.rb index bbb413fd3c..bd85ab425c 100644 --- a/Library/Homebrew/cask/lib/hbc/source/path_base.rb +++ b/Library/Homebrew/cask/lib/hbc/source/path_base.rb @@ -55,6 +55,10 @@ class Hbc::Source::PathBase end def build_cask(cask_class, header_token, &block) + if header_token.is_a?(Hash) + # Cask file is using old `cask :v1 => 'token'` syntax + header_token = header_token.values.first + end raise Hbc::CaskTokenDoesNotMatchError.new(cask_token, header_token) unless cask_token == header_token cask_class.new(cask_token, sourcefile_path: path, &block) end diff --git a/Library/Homebrew/cask/test/cask/dsl_test.rb b/Library/Homebrew/cask/test/cask/dsl_test.rb index ce57e0b078..ccf2f1a248 100644 --- a/Library/Homebrew/cask/test/cask/dsl_test.rb +++ b/Library/Homebrew/cask/test/cask/dsl_test.rb @@ -62,6 +62,15 @@ describe Hbc::DSL do it "does not require a DSL version in the header" do test_cask = Hbc.load("no-dsl-version") + test_cask.token.must_equal "no-dsl-version" + test_cask.url.to_s.must_equal "http://example.com/TestCask.dmg" + test_cask.homepage.must_equal "http://example.com/" + test_cask.version.to_s.must_equal "1.2.3" + end + + it "may use deprecated DSL version hash syntax" do + test_cask = Hbc.load("with-dsl-version") + test_cask.token.must_equal "with-dsl-version" test_cask.url.to_s.must_equal "http://example.com/TestCask.dmg" test_cask.homepage.must_equal "http://example.com/" test_cask.version.to_s.must_equal "1.2.3" diff --git a/Library/Homebrew/cask/test/support/Casks/with-dsl-version.rb b/Library/Homebrew/cask/test/support/Casks/with-dsl-version.rb new file mode 100644 index 0000000000..c16343c4b9 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-dsl-version.rb @@ -0,0 +1,9 @@ +test_cask :v1 => 'with-dsl-version' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url 'http://example.com/TestCask.dmg' + homepage 'http://example.com/' + + app 'TestCask.app' +end