Skip to content

Commit

Permalink
Merge pull request #15901 from jawshooah/no-dsl-version
Browse files Browse the repository at this point in the history
Do not require a DSL version in cask header
  • Loading branch information
jawshooah committed Dec 17, 2015
2 parents cacc43c + 81b9143 commit ceb7af6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
11 changes: 2 additions & 9 deletions lib/hbc/source/path_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions test/cask/dsl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions test/support/Casks/no-dsl-version.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ceb7af6

Please sign in to comment.