From e3df6a9923bc425e214eba16f8813d9d6871b8b0 Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Wed, 19 Nov 2014 10:56:36 -0500 Subject: [PATCH 1/2] fix old-style header line in test suite --- test/support/Casks/with-suite.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/support/Casks/with-suite.rb b/test/support/Casks/with-suite.rb index 2554243fa734..120deb004a8f 100644 --- a/test/support/Casks/with-suite.rb +++ b/test/support/Casks/with-suite.rb @@ -1,4 +1,4 @@ -class WithSuite < TestCask +cask :v1 => 'with-suite' do version '1.2.3' sha256 'd1302a0dc25aff72ad395ed01a830468b92253ffd28269574f3ac0b5eb8aad54' From 6c53607967eed4925c627225f701941a11d72f29 Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Wed, 19 Nov 2014 10:57:39 -0500 Subject: [PATCH 2/2] require new-style header lines and enforce that the cask name (per the header) must match the filename --- lib/cask/source/path_base.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/cask/source/path_base.rb b/lib/cask/source/path_base.rb index ff53988d72cf..f0dd8126e225 100644 --- a/lib/cask/source/path_base.rb +++ b/lib/cask/source/path_base.rb @@ -47,8 +47,15 @@ def load if %r{\A\s*cask\s+:v([\d_]+)(test)?\s+=>\s+([\'\"])(\S+?)\3(?:\s*,\s*|\s+)do\s*\n}.match(cask_string) dsl_version = $1 test_cask = ! $2.nil? + header_name = $4 superclass_name = test_cask ? 'TestCask' : 'Cask' cask_string.sub!(%r{\A[^\n]+\n}, "class #{cask_class_name} < #{superclass_name}\n") + # todo enforce valid DSL version + if header_name != cask_name + raise CaskInvalidError.new(cask_name, "Bad header line: '#{header_name}' does not match file name") + end + else + raise CaskInvalidError.new(cask_name, "Bad header line: parse failed") end # simulate "require" @@ -72,8 +79,12 @@ def load end end + def cask_name + path.basename.to_s.sub(/\.rb/, '') + end + def cask_class_name - path.basename.to_s.sub(/\.rb/, '').split('-').map(&:capitalize).join + cask_name.split('-').map(&:capitalize).join end def to_s