From 92311901c9d85e0e43147386535118b66ca718cd Mon Sep 17 00:00:00 2001 From: Adam Smith Date: Wed, 27 Sep 2017 00:17:47 -0700 Subject: [PATCH 1/2] add available languages to cask info command add language tests for dsl add fixtures, tests for languages info output add extra lines --- Library/Homebrew/cask/lib/hbc/cli/info.rb | 8 +++++ Library/Homebrew/cask/lib/hbc/dsl.rb | 7 ++++ Library/Homebrew/test/cask/cli/info_spec.rb | 32 +++++++++++++++++++ Library/Homebrew/test/cask/dsl_spec.rb | 30 +++++++++++++++++ .../cask/Casks/with-conditional-languages.rb | 9 ++++++ .../fixtures/cask/Casks/with-languages.rb | 18 +++++++++++ 6 files changed, 104 insertions(+) create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/with-conditional-languages.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/with-languages.rb diff --git a/Library/Homebrew/cask/lib/hbc/cli/info.rb b/Library/Homebrew/cask/lib/hbc/cli/info.rb index 9cdada62e8f1e..2b4db953097fe 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/info.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/info.rb @@ -23,6 +23,7 @@ def self.info(cask) installation_info(cask) repo_info(cask) name_info(cask) + language_info(cask) artifact_info(cask) Installer.print_caveats(cask) end @@ -51,6 +52,13 @@ def self.name_info(cask) puts cask.name.empty? ? Formatter.error("None") : cask.name end + def self.language_info(cask) + return if cask.languages.empty? + + ohai "Languages" + puts cask.languages.join(", ") + end + def self.repo_info(cask) user, repo, token = QualifiedToken.parse(Hbc.all_tokens.detect { |t| t.split("/").last == cask.token }) diff --git a/Library/Homebrew/cask/lib/hbc/dsl.rb b/Library/Homebrew/cask/lib/hbc/dsl.rb index 3824b9761fd33..3822c532c4af6 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl.rb @@ -63,6 +63,7 @@ class DSL :gpg, :homepage, :language, + :languages, :name, :sha256, :staged_path, @@ -139,6 +140,12 @@ def language_eval @language = @language_blocks.default.call end + def languages + return [] if @language_blocks.nil? + + @language_blocks.keys.flatten + end + def url(*args, &block) set_unique_stanza(:url, args.empty? && !block_given?) do begin diff --git a/Library/Homebrew/test/cask/cli/info_spec.rb b/Library/Homebrew/test/cask/cli/info_spec.rb index aec7080deae6c..7d6dfd76d40dd 100644 --- a/Library/Homebrew/test/cask/cli/info_spec.rb +++ b/Library/Homebrew/test/cask/cli/info_spec.rb @@ -90,6 +90,38 @@ EOS end + it "should print languages if the Cask provided any" do + expect { + Hbc::CLI::Info.run("with-languages") + }.to output(<<-EOS.undent).to_stdout + with-languages: 1.2.3 + http://example.com/local-caffeine + Not installed + From: https://github.com/caskroom/homebrew-spec/blob/master/Casks/with-languages.rb + ==> Name + None + ==> Languages + zh, en-US + ==> Artifacts + Caffeine.app (App) + EOS + end + + it 'should not print "Languages" section divider if the languages block has no output' do + expect { + Hbc::CLI::Info.run("with-conditional-languages") + }.to output(<<-EOS.undent).to_stdout + with-conditional-languages: 1.2.3 + http://example.com/local-caffeine + Not installed + From: https://github.com/caskroom/homebrew-spec/blob/master/Casks/with-conditional-languages.rb + ==> Name + None + ==> Artifacts + Caffeine.app (App) + EOS + end + describe "when no Cask is specified" do it "raises an exception" do expect { diff --git a/Library/Homebrew/test/cask/dsl_spec.rb b/Library/Homebrew/test/cask/dsl_spec.rb index aec1e917f3a98..c2a7b2367e883 100644 --- a/Library/Homebrew/test/cask/dsl_spec.rb +++ b/Library/Homebrew/test/cask/dsl_spec.rb @@ -177,6 +177,36 @@ expect(cask.call.sha256).to eq("xyz789") expect(cask.call.url.to_s).to eq("https://example.org/en-US.zip") end + + it "returns empty array if no languages specified" do + cask = lambda do + Hbc::Cask.new("cask-with-apps") do + url "https://example.org/file.zip" + end + end + + expect(cask.call.languages).to be_empty + end + + it "returns an array of available languages" do + cask = lambda do + Hbc::Cask.new("cask-with-apps") do + language "zh" do + sha256 "abc123" + "zh-CN" + end + + language "en-US", default: true do + sha256 "xyz789" + "en-US" + end + + url "https://example.org/file.zip" + end + end + + expect(cask.call.languages).to eq(["zh", "en-US"]) + end end describe "app stanza" do diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-conditional-languages.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-conditional-languages.rb new file mode 100644 index 0000000000000..bf3b9b1c40b00 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-conditional-languages.rb @@ -0,0 +1,9 @@ +cask 'with-conditional-languages' do + version '1.2.3' + sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94' + + url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip" + homepage 'http://example.com/local-caffeine' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-languages.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-languages.rb new file mode 100644 index 0000000000000..90ff638468ead --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-languages.rb @@ -0,0 +1,18 @@ +cask 'with-languages' do + version '1.2.3' + + language "zh" do + sha256 "abc123" + "zh-CN" + end + + language "en-US", default: true do + sha256 "xyz789" + "en-US" + end + + url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip" + homepage 'http://example.com/local-caffeine' + + app 'Caffeine.app' +end From 270bf0506a851af4748355791d1875207213466b Mon Sep 17 00:00:00 2001 From: Adam Smith Date: Mon, 2 Oct 2017 11:34:50 -0700 Subject: [PATCH 2/2] stylistic changes for cask info tests --- Library/Homebrew/test/cask/cli/info_spec.rb | 10 +++++----- Library/Homebrew/test/cask/dsl_spec.rb | 2 +- ...h-conditional-languages.rb => without-languages.rb} | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) rename Library/Homebrew/test/support/fixtures/cask/Casks/{with-conditional-languages.rb => without-languages.rb} (85%) diff --git a/Library/Homebrew/test/cask/cli/info_spec.rb b/Library/Homebrew/test/cask/cli/info_spec.rb index 7d6dfd76d40dd..df02bb1e5dcf3 100644 --- a/Library/Homebrew/test/cask/cli/info_spec.rb +++ b/Library/Homebrew/test/cask/cli/info_spec.rb @@ -90,7 +90,7 @@ EOS end - it "should print languages if the Cask provided any" do + it "prints languages specified in the Cask" do expect { Hbc::CLI::Info.run("with-languages") }.to output(<<-EOS.undent).to_stdout @@ -107,14 +107,14 @@ EOS end - it 'should not print "Languages" section divider if the languages block has no output' do + it 'does not print "Languages" section divider if the languages block has no output' do expect { - Hbc::CLI::Info.run("with-conditional-languages") + Hbc::CLI::Info.run("without-languages") }.to output(<<-EOS.undent).to_stdout - with-conditional-languages: 1.2.3 + without-languages: 1.2.3 http://example.com/local-caffeine Not installed - From: https://github.com/caskroom/homebrew-spec/blob/master/Casks/with-conditional-languages.rb + From: https://github.com/caskroom/homebrew-spec/blob/master/Casks/without-languages.rb ==> Name None ==> Artifacts diff --git a/Library/Homebrew/test/cask/dsl_spec.rb b/Library/Homebrew/test/cask/dsl_spec.rb index c2a7b2367e883..7df8de6f81079 100644 --- a/Library/Homebrew/test/cask/dsl_spec.rb +++ b/Library/Homebrew/test/cask/dsl_spec.rb @@ -178,7 +178,7 @@ expect(cask.call.url.to_s).to eq("https://example.org/en-US.zip") end - it "returns empty array if no languages specified" do + it "returns an empty array if no languages are specified" do cask = lambda do Hbc::Cask.new("cask-with-apps") do url "https://example.org/file.zip" diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-conditional-languages.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/without-languages.rb similarity index 85% rename from Library/Homebrew/test/support/fixtures/cask/Casks/with-conditional-languages.rb rename to Library/Homebrew/test/support/fixtures/cask/Casks/without-languages.rb index bf3b9b1c40b00..4c0ce955ab93e 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/with-conditional-languages.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/without-languages.rb @@ -1,4 +1,4 @@ -cask 'with-conditional-languages' do +cask 'without-languages' do version '1.2.3' sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'