diff options
10 files changed, 117 insertions, 3 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb b/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb index badd549ce..3f63dae8f 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb @@ -37,7 +37,7 @@ module Hbc end def summarize - to_h.map { |key, val| [*val].map { |v| "#{key.inspect} => #{v.inspect}" }.join(", ") }.join(", ") + to_h.flat_map { |key, val| [*val].map { |v| "#{key.inspect} => #{v.inspect}" } }.join(", ") end private @@ -253,7 +253,7 @@ module Hbc end def trash_paths(*paths, command: nil, **_) - command.run!("/usr/bin/osascript", args: ["-e", <<-'EOS'.undent, *paths]) + result = command.run!("/usr/bin/osascript", args: ["-e", <<-'EOS'.undent, *paths]) on run argv repeat with i from 1 to (count argv) set item i of argv to (item i of argv as POSIX file) @@ -267,7 +267,7 @@ module Hbc set trashedItem to POSIX path of (item i of trashedItems as string) set output to output & trashedItem if i < count trashedItems then - set output to output & (do shell script "printf \"\\0\"") + set output to output & character id 0 end if end repeat @@ -275,6 +275,9 @@ module Hbc end tell end run EOS + + # Remove AppleScript's automatic newline. + result.tap { |r| r.stdout.sub!(/\n$/, "") } end def uninstall_rmdir(*directories, command: nil, **_) diff --git a/Library/Homebrew/cask/lib/hbc/artifact/nested_container.rb b/Library/Homebrew/cask/lib/hbc/artifact/nested_container.rb index 81adf9029..c9fd3dc27 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/nested_container.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/nested_container.rb @@ -16,6 +16,10 @@ module Hbc private + def summarize + path.relative_path_from(cask.staged_path).to_s + end + def extract(command: nil, verbose: nil, **_) container = Container.for_path(path, command) diff --git a/Library/Homebrew/cask/lib/hbc/cli/info.rb b/Library/Homebrew/cask/lib/hbc/cli/info.rb index 9cdada62e..2b4db9530 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/info.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/info.rb @@ -23,6 +23,7 @@ module Hbc installation_info(cask) repo_info(cask) name_info(cask) + language_info(cask) artifact_info(cask) Installer.print_caveats(cask) end @@ -51,6 +52,13 @@ module Hbc 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 1d048bffd..8d5b6c9a9 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl.rb @@ -63,6 +63,7 @@ module Hbc :gpg, :homepage, :language, + :languages, :name, :sha256, :staged_path, @@ -145,6 +146,12 @@ module Hbc @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/keg_relocate.rb b/Library/Homebrew/keg_relocate.rb index 085748632..71773db81 100644 --- a/Library/Homebrew/keg_relocate.rb +++ b/Library/Homebrew/keg_relocate.rb @@ -124,6 +124,7 @@ class Keg next true if pn.symlink? next true if pn.directory? next false if pn.basename.to_s == "orig-prefix.txt" # for python virtualenvs + next true if pn == self/".brew/#{name}.rb" next true if Metafiles::EXTENSIONS.include?(pn.extname) if pn.text_executable? text_files << pn diff --git a/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb b/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb index 06eec4a01..4fdab60d0 100644 --- a/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb +++ b/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb @@ -149,6 +149,8 @@ shared_examples "#uninstall_phase or #zap_phase" do end [:delete, :trash].each do |directive| + next if directive == :trash && ENV["HOMEBREW_TESTS_COVERAGE"].nil? + context "using :#{directive}" do let(:dir) { TEST_TMPDIR } let(:absolute_path) { Pathname.new("#{dir}/absolute_path") } diff --git a/Library/Homebrew/test/cask/cli/info_spec.rb b/Library/Homebrew/test/cask/cli/info_spec.rb index aec7080de..df02bb1e5 100644 --- a/Library/Homebrew/test/cask/cli/info_spec.rb +++ b/Library/Homebrew/test/cask/cli/info_spec.rb @@ -90,6 +90,38 @@ describe Hbc::CLI::Info, :cask do EOS end + it "prints languages specified in the Cask" 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 'does not print "Languages" section divider if the languages block has no output' do + expect { + Hbc::CLI::Info.run("without-languages") + }.to output(<<-EOS.undent).to_stdout + without-languages: 1.2.3 + http://example.com/local-caffeine + Not installed + From: https://github.com/caskroom/homebrew-spec/blob/master/Casks/without-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 aec1e917f..7df8de6f8 100644 --- a/Library/Homebrew/test/cask/dsl_spec.rb +++ b/Library/Homebrew/test/cask/dsl_spec.rb @@ -177,6 +177,36 @@ describe Hbc::DSL, :cask do expect(cask.call.sha256).to eq("xyz789") expect(cask.call.url.to_s).to eq("https://example.org/en-US.zip") end + + 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" + 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-languages.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-languages.rb new file mode 100644 index 000000000..90ff63846 --- /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 diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/without-languages.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/without-languages.rb new file mode 100644 index 000000000..4c0ce955a --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/without-languages.rb @@ -0,0 +1,9 @@ +cask 'without-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 |
