summaryrefslogtreecommitdiff
path: root/test/irb
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2019-04-25 23:53:57 +0900
committerTakashi Kokubun <takashikkbn@gmail.com>2019-04-26 00:47:43 +0900
commit0c54d2e2c7697aa5d6a1315b79c16b88d34f5e81 (patch)
treec3b0b9e1cdc7108c20a74fcf330a1b82d417e6ca /test/irb
parent022cbb278f381e5774a5d0277a83127c6f6b4802 (diff)
Force IRB::Color to recognize TERM
Closes: https://github.com/ruby/ruby/pull/2150
Diffstat (limited to 'test/irb')
-rw-r--r--test/irb/test_color.rb20
1 files changed, 19 insertions, 1 deletions
diff --git a/test/irb/test_color.rb b/test/irb/test_color.rb
index 088611c645..d5f9286e36 100644
--- a/test/irb/test_color.rb
+++ b/test/irb/test_color.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: false
require 'test/unit'
require 'irb/color'
+require 'stringio'
module TestIRB
class TestColor < Test::Unit::TestCase
@@ -23,7 +24,7 @@ module TestIRB
'ERB.new("a#{nil}b", trim_mode: "-")' => "#{BLUE}#{BOLD}#{UNDERLINE}ERB#{CLEAR}.new(#{RED}\"#{CLEAR}#{RED}a#{CLEAR}#{RED}\#{#{CLEAR}#{CYAN}#{BOLD}nil#{CLEAR}#{RED}}#{CLEAR}#{RED}b#{CLEAR}#{RED}\"#{CLEAR}, #{MAGENTA}trim_mode:#{CLEAR} #{RED}\"#{CLEAR}#{RED}-#{CLEAR}#{RED}\"#{CLEAR})",
"# comment" => "#{BLUE}#{BOLD}# comment#{CLEAR}",
}.each do |code, result|
- assert_equal(result, IRB::Color.colorize_code(code))
+ assert_equal(result, with_term { IRB::Color.colorize_code(code) })
end
end
@@ -40,5 +41,22 @@ module TestIRB
assert_equal(result, IRB::Color.inspect_colorable?(object))
end
end
+
+ private
+
+ def with_term
+ stdout = $stdout
+ io = StringIO.new
+ def io.tty?; true; end
+ $stdout = io
+
+ env = ENV.to_h.dup
+ ENV['TERM'] = 'xterm-256color'
+
+ yield
+ ensure
+ $stdout = stdout
+ ENV.replace(env) if env
+ end
end
end