From 81b91434dcda3ccc24267569e71e893a0003056c Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Thu, 17 Dec 2015 14:17:11 -0500 Subject: [PATCH] Do not require a DSL version in cask header Following up on #15782. Casks can now be created with no DSL version in the header. For example: cask 'no-dsl-version' do version :latest ... end Casks with a DSL version in the header are still valid, but the DSL version will be ignored. --- lib/hbc/source/path_base.rb | 11 ++--------- test/cask/dsl_test.rb | 11 +++++------ test/support/Casks/no-dsl-version.rb | 9 +++++++++ 3 files changed, 16 insertions(+), 15 deletions(-) create mode 100644 test/support/Casks/no-dsl-version.rb diff --git a/lib/hbc/source/path_base.rb b/lib/hbc/source/path_base.rb index fae79f14ad39..d8915114b0dd 100644 --- a/lib/hbc/source/path_base.rb +++ b/lib/hbc/source/path_base.rb @@ -46,18 +46,11 @@ def load # munge text cask_contents.sub!(%r{\A(\s*\#[^\n]*\n)+}, ''); - if %r{\A\s*cask\s+:v([\d_]+)(test)?\s+=>\s+([\'\"])(\S+?)\3(?:\s*,\s*|\s+)do\s*\n}.match(cask_contents) - dsl_version_string = $1 - is_test = ! $2.nil? + if %r{\A\s*(test_)?cask\s+(?::v[\d_]+(test)?\s+=>\s+)?([\'\"])(\S+?)\3(?:\s*,\s*|\s+)do\s*\n}.match(cask_contents) + is_test = $1 || $2 header_token = $4 - dsl_version = Gem::Version.new(dsl_version_string.gsub('_','.')) superclass_name = is_test ? 'Hbc::TestCask' : 'Hbc::Cask' cask_contents.sub!(%r{\A[^\n]+\n}, "class #{cask_class_name} < #{superclass_name}\n") - # todo the minimum DSL version should be defined globally elsewhere - minimum_dsl_version = Gem::Version.new('1.0') - unless dsl_version >= minimum_dsl_version - raise Hbc::CaskInvalidError.new(cask_token, "Bad header line: 'v#{dsl_version_string}' is less than required minimum version '#{minimum_dsl_version}'") - end if header_token != cask_token raise Hbc::CaskInvalidError.new(cask_token, "Bad header line: '#{header_token}' does not match file name") end diff --git a/test/cask/dsl_test.rb b/test/cask/dsl_test.rb index 6987608a74d0..fc3c28736133 100644 --- a/test/cask/dsl_test.rb +++ b/test/cask/dsl_test.rb @@ -60,12 +60,11 @@ err.message.must_include 'does not match file name' end - it "requires a valid minimum DSL version in the header" do - err = lambda { - invalid_cask = Hbc.load('invalid/invalid-header-version') - }.must_raise(Hbc::CaskInvalidError) - err.message.must_include 'Bad header line:' - err.message.must_include 'is less than required minimum version' + it "does not require a DSL version in the header" do + test_cask = Hbc.load('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.must_equal '1.2.3' end end diff --git a/test/support/Casks/no-dsl-version.rb b/test/support/Casks/no-dsl-version.rb new file mode 100644 index 000000000000..ee557b1e402a --- /dev/null +++ b/test/support/Casks/no-dsl-version.rb @@ -0,0 +1,9 @@ +test_cask 'no-dsl-version' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url 'http://example.com/TestCask.dmg' + homepage 'http://example.com/' + + app 'TestCask.app' +end