From 13488183bd3fe9d0f8e84d66075c9c7d4cdc931d Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Fri, 20 Jan 2017 12:27:49 +0000 Subject: [PATCH 1/4] emoji: remove hack required for Ruby 1.8.7 Since this hack is no longer required, and `Emoji.tick` and `.cross` are only called in one place, I think it's better to just inline them there rather than having methods on `Emoji` that just return a one-character String. --- Library/Homebrew/emoji.rb | 12 +----------- Library/Homebrew/utils.rb | 4 ++-- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/Library/Homebrew/emoji.rb b/Library/Homebrew/emoji.rb index 8c58ca8952..43fa781e6b 100644 --- a/Library/Homebrew/emoji.rb +++ b/Library/Homebrew/emoji.rb @@ -1,17 +1,7 @@ module Emoji class << self - def tick - # necessary for 1.8.7 unicode handling since many installs are on 1.8.7 - @tick ||= ["2714".hex].pack("U*") - end - - def cross - # necessary for 1.8.7 unicode handling since many installs are on 1.8.7 - @cross ||= ["2718".hex].pack("U*") - end - def install_badge - ENV["HOMEBREW_INSTALL_BADGE"] || "\xf0\x9f\x8d\xba" + ENV["HOMEBREW_INSTALL_BADGE"] || "🍺" end def enabled? diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 614d50eeae..70d2787d97 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -106,7 +106,7 @@ def pretty_installed(f) if !$stdout.tty? f.to_s elsif Emoji.enabled? - "#{Tty.bold}#{f} #{Formatter.success(Emoji.tick)}#{Tty.reset}" + "#{Tty.bold}#{f} #{Formatter.success("✔")}#{Tty.reset}" else Formatter.success("#{Tty.bold}#{f} (installed)#{Tty.reset}") end @@ -116,7 +116,7 @@ def pretty_uninstalled(f) if !$stdout.tty? f.to_s elsif Emoji.enabled? - "#{Tty.bold}#{f} #{Formatter.error(Emoji.cross)}#{Tty.reset}" + "#{Tty.bold}#{f} #{Formatter.error("✘")}#{Tty.reset}" else Formatter.error("#{Tty.bold}#{f} (uninstalled)#{Tty.reset}") end From b0fea9eb6c7dfc39bbd8083180a7156b9b859571 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Fri, 20 Jan 2017 12:30:47 +0000 Subject: [PATCH 2/4] fileutils: update Ruby documentation URL --- Library/Homebrew/extend/fileutils.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/fileutils.rb b/Library/Homebrew/extend/fileutils.rb index 4f20d36a3b..287a1408f4 100644 --- a/Library/Homebrew/extend/fileutils.rb +++ b/Library/Homebrew/extend/fileutils.rb @@ -3,7 +3,7 @@ require "tmpdir" require "etc" # Homebrew extends Ruby's `FileUtils` to make our code more readable. -# @see http://ruby-doc.org/stdlib-1.8.7/libdoc/fileutils/rdoc/FileUtils.html Ruby's FileUtils API +# @see http://ruby-doc.org/stdlib-2.0.0/libdoc/fileutils/rdoc/FileUtils.html Ruby's FileUtils API module FileUtils # Create a temporary directory then yield. When the block returns, # recursively delete the temporary directory. Passing opts[:retain] From 65dde58057029d473be9175444b333525fe82850 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Fri, 20 Jan 2017 17:27:08 +0000 Subject: [PATCH 3/4] =?UTF-8?q?tests:=20add=20some=20emoji=20tests=20?= =?UTF-8?q?=F0=9F=92=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Library/Homebrew/test/emoji_test.rb | 11 +++++++++++ Library/Homebrew/test/utils_test.rb | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 Library/Homebrew/test/emoji_test.rb diff --git a/Library/Homebrew/test/emoji_test.rb b/Library/Homebrew/test/emoji_test.rb new file mode 100644 index 0000000000..ea68db8f6e --- /dev/null +++ b/Library/Homebrew/test/emoji_test.rb @@ -0,0 +1,11 @@ +require "testing_env" +require "emoji" + +class EmojiTest < Homebrew::TestCase + def test_install_badge + assert_equal "🍺", Emoji.install_badge + + ENV["HOMEBREW_INSTALL_BADGE"] = "foo" + assert_equal "foo", Emoji.install_badge + end +end diff --git a/Library/Homebrew/test/utils_test.rb b/Library/Homebrew/test/utils_test.rb index 520cd4fcdd..7ae5793e2b 100644 --- a/Library/Homebrew/test/utils_test.rb +++ b/Library/Homebrew/test/utils_test.rb @@ -9,6 +9,14 @@ class UtilTests < Homebrew::TestCase @dir = Pathname.new(mktmpdir) end + # Helper for matching escape sequences. + def e(code) + /(\e\[\d+m)*\e\[#{code}m/ + end + + # Helper for matching that style is reset at the end of a string. + Z = /(\e\[\d+m)*\e\[0m\Z/ + def test_ofail shutup { ofail "foo" } assert Homebrew.failed? @@ -22,11 +30,25 @@ class UtilTests < Homebrew::TestCase end def test_pretty_installed + $stdout.stubs(:tty?).returns true + ENV.delete("HOMEBREW_NO_EMOJI") + assert_match(/\A#{e 1}foo #{e 32}✔#{Z}/, pretty_installed("foo")) + + ENV["HOMEBREW_NO_EMOJI"] = "1" + assert_match(/\A#{e 1}foo \(installed\)#{Z}/, pretty_installed("foo")) + $stdout.stubs(:tty?).returns false assert_equal "foo", pretty_installed("foo") end def test_pretty_uninstalled + $stdout.stubs(:tty?).returns true + ENV.delete("HOMEBREW_NO_EMOJI") + assert_match(/\A#{e 1}foo #{e 31}✘#{Z}/, pretty_uninstalled("foo")) + + ENV["HOMEBREW_NO_EMOJI"] = "1" + assert_match(/\A#{e 1}foo \(uninstalled\)#{Z}/, pretty_uninstalled("foo")) + $stdout.stubs(:tty?).returns false assert_equal "foo", pretty_uninstalled("foo") end From 5480a84114243fcd0aedda3a650b23b59ae91b2c Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Mon, 23 Jan 2017 18:24:31 +0000 Subject: [PATCH 4/4] tests: give `e` helper in UtilTests a better name --- Library/Homebrew/test/utils_test.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/test/utils_test.rb b/Library/Homebrew/test/utils_test.rb index 7ae5793e2b..1f2fb7b55f 100644 --- a/Library/Homebrew/test/utils_test.rb +++ b/Library/Homebrew/test/utils_test.rb @@ -9,14 +9,10 @@ class UtilTests < Homebrew::TestCase @dir = Pathname.new(mktmpdir) end - # Helper for matching escape sequences. - def e(code) + def esc(code) /(\e\[\d+m)*\e\[#{code}m/ end - # Helper for matching that style is reset at the end of a string. - Z = /(\e\[\d+m)*\e\[0m\Z/ - def test_ofail shutup { ofail "foo" } assert Homebrew.failed? @@ -32,10 +28,12 @@ class UtilTests < Homebrew::TestCase def test_pretty_installed $stdout.stubs(:tty?).returns true ENV.delete("HOMEBREW_NO_EMOJI") - assert_match(/\A#{e 1}foo #{e 32}✔#{Z}/, pretty_installed("foo")) + tty_with_emoji_output = /\A#{esc 1}foo #{esc 32}✔#{esc 0}\Z/ + assert_match tty_with_emoji_output, pretty_installed("foo") ENV["HOMEBREW_NO_EMOJI"] = "1" - assert_match(/\A#{e 1}foo \(installed\)#{Z}/, pretty_installed("foo")) + tty_no_emoji_output = /\A#{esc 1}foo \(installed\)#{esc 0}\Z/ + assert_match tty_no_emoji_output, pretty_installed("foo") $stdout.stubs(:tty?).returns false assert_equal "foo", pretty_installed("foo") @@ -44,10 +42,12 @@ class UtilTests < Homebrew::TestCase def test_pretty_uninstalled $stdout.stubs(:tty?).returns true ENV.delete("HOMEBREW_NO_EMOJI") - assert_match(/\A#{e 1}foo #{e 31}✘#{Z}/, pretty_uninstalled("foo")) + tty_with_emoji_output = /\A#{esc 1}foo #{esc 31}✘#{esc 0}\Z/ + assert_match tty_with_emoji_output, pretty_uninstalled("foo") ENV["HOMEBREW_NO_EMOJI"] = "1" - assert_match(/\A#{e 1}foo \(uninstalled\)#{Z}/, pretty_uninstalled("foo")) + tty_no_emoji_output = /\A#{esc 1}foo \(uninstalled\)#{esc 0}\Z/ + assert_match tty_no_emoji_output, pretty_uninstalled("foo") $stdout.stubs(:tty?).returns false assert_equal "foo", pretty_uninstalled("foo")