Skip to content

Commit

Permalink
Print status in green when there are no problems.
Browse files Browse the repository at this point in the history
  • Loading branch information
kentaroi committed Dec 6, 2013
1 parent c740dd9 commit 8843863
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
5 changes: 4 additions & 1 deletion lib/minitest/ansi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module MiniTest
class ANSI < ::SimpleDelegator
include ANSIVersion

STATUS_REGEX = /\d+ tests, \d+ assertions, (\d+) failures, (\d+) errors, (\d+) skips/
TEST_REGEX = /\d+(\)| tests)/
MAPPING = [
[/[1-9]\d*\)? (F|f)ailures?/, :yellow],
Expand Down Expand Up @@ -35,7 +36,9 @@ def print(*args)

def puts(*args)
str = args.first
if str && (str =~ TEST_REGEX) != nil
if str && (str =~ STATUS_REGEX) != nil && ($1 == '0' && $2 == '0' && $3 == '0')
str.replace(::ANSI.green{ str })
elsif str && (str =~ TEST_REGEX) != nil
MAPPING.each do |regex, color|
str.gsub!(regex, ::ANSI[color] + "\\0" + ::ANSI[:clear])
end
Expand Down
11 changes: 3 additions & 8 deletions test/lib/minitest/ansi_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,9 @@ def assert_puts(input, output)
assert_puts '5 tests, 2 skips', "5 tests, \e[36m2 skips\e[0m"
end

it 'does not colorize when there are no problems' do
input = '99 tests, 0 failures, 0 errors, 0 skips'
subject.puts input
subject.rewind
output = subject.read
output.wont_match "\e[33m"
output.wont_match "\e[36m"
output.wont_match "\e[31m"
it 'print the line in green when there are no problems' do
input = '99 tests, 99 assertions, 0 failures, 0 errors, 0 skips'
assert_puts input, "\e[32m#{input}\e[0m"
end
end
end
Expand Down

0 comments on commit 8843863

Please sign in to comment.