Skip to content

Commit

Permalink
Fix color expectations when $stdout.tty? is false
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbrictson committed Jul 15, 2015
1 parent 20db92a commit 5a40985
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions test/airbrussh/formatter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,15 @@ def command_failed(exit_status)
:bold_yellow => "1;33;49"
}.each do |color, code|
define_method(color) do |string|
color_if_legacy(string, code)
color_if_expected(string, code)
end
end

def color_if_legacy(text, color)
# SSHKit versions up to 1.7.1 added colors to the log file even though it did not have a tty.
# Versions after this don't, so we must match output both with, and without colors
# depending on the SSHKit version.
# Whether or not SSHKit emits color depends on the test environment. SSHKit
# versions up to 1.7.1 added colors to the log file, but only if
# `$stdout.tty?` is true. Later versions never output color to the log file.
def color_if_expected(text, color)
return text unless $stdout.tty?
if sshkit_after?("1.7.1") || sshkit_master?
text
else
Expand Down

0 comments on commit 5a40985

Please sign in to comment.