Skip to content

Commit ede1289

Browse files
committed
Assertions on non-tty
1 parent 10e290f commit ede1289

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

test/irb/test_color.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def test_colorize
3131
[:CYAN] => "#{CYAN}#{text}#{CLEAR}",
3232
}.each do |seq, result|
3333
assert_equal_with_term(result, text, seq: seq)
34+
35+
assert_equal_with_term(text, text, seq: seq, tty: false)
3436
end
3537
end
3638

@@ -124,6 +126,9 @@ def test_colorize_code
124126
if colorize_code_supported?
125127
assert_equal_with_term(result, code, complete: true)
126128
assert_equal_with_term(result, code, complete: false)
129+
130+
assert_equal_with_term(code, code, complete: true, tty: false)
131+
assert_equal_with_term(code, code, complete: false, tty: false)
127132
else
128133
assert_equal_with_term(code, code)
129134
end
@@ -141,6 +146,8 @@ def test_colorize_code_complete_true
141146
"('foo" => "(#{RED}#{BOLD}'#{CLEAR}#{RED}#{REVERSE}foo#{CLEAR}",
142147
}.each do |code, result|
143148
assert_equal_with_term(result, code, complete: true)
149+
150+
assert_equal_with_term(code, code, complete: true, tty: false)
144151
end
145152
end
146153

@@ -153,8 +160,12 @@ def test_colorize_code_complete_false
153160
if colorize_code_supported?
154161
assert_equal_with_term(result, code, complete: false)
155162

163+
assert_equal_with_term(code, code, complete: false, tty: false)
164+
156165
unless complete_option_supported?
157166
assert_equal_with_term(result, code, complete: true)
167+
168+
assert_equal_with_term(code, code, complete: true, tty: false)
158169
end
159170
else
160171
assert_equal_with_term(code, code)
@@ -194,10 +205,10 @@ def complete_option_supported?
194205
Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0')
195206
end
196207

197-
def with_term
208+
def with_term(tty: true)
198209
stdout = $stdout
199210
io = StringIO.new
200-
def io.tty?; true; end
211+
def io.tty?; true; end if tty
201212
$stdout = io
202213

203214
env = ENV.to_h.dup
@@ -209,8 +220,8 @@ def io.tty?; true; end
209220
ENV.replace(env) if env
210221
end
211222

212-
def assert_equal_with_term(result, code, seq: nil, **opts)
213-
actual = with_term do
223+
def assert_equal_with_term(result, code, seq: nil, tty: true, **opts)
224+
actual = with_term(tty: tty) do
214225
if seq
215226
IRB::Color.colorize(code, seq, **opts)
216227
else

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy