Skip to content

Commit

Permalink
inplace reporter: colorize progress
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 11, 2012
1 parent 6a1c185 commit 423345a
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions lib/groonga/tester.rb
Expand Up @@ -318,16 +318,6 @@ def test_failed(name)
def test_not_checked
@n_not_checked_tests += 1
end

def status
if n_failed_tests > 0
:failure
elsif n_not_checked_tests > 0
:no_check
else
:success
end
end
end

class Worker
Expand Down Expand Up @@ -1446,6 +1436,16 @@ def string_width(string)
string.gsub(/\e\[[0-9;]+m/, "").size
end

def result_status(result)
if result.n_failed_tests > 0
:failure
elsif result.n_not_checked_tests > 0
:no_check
else
:success
end
end

def colorize(message, situation)
return message unless @tester.use_color?
case situation
Expand Down Expand Up @@ -1686,7 +1686,7 @@ def draw

def draw_status_line(worker)
clear_line
situation = worker.result.status
situation = result_status(worker.result)
left = "[#{colorize(worker.id, situation)}] "
right = " [#{worker.status}]"
rest_width = @term_width - @current_column
Expand Down Expand Up @@ -1719,15 +1719,17 @@ def draw_progress_line
progress_width -= finish_mark.bytesize
progress_width -= statistics.bytesize
finished_mark = "-"
situation = result_status(@test_suites_result)
if n_done_tests == n_total_tests
progress = finished_mark * progress_width
progress = colorize(finished_mark * progress_width, situation)
else
current_mark = ">"
finished_marks_width = (progress_width * finished_test_ratio).ceil
finished_marks_width -= current_mark.bytesize
finished_marks_width = [0, finished_marks_width].max
progress = finished_mark * finished_marks_width + current_mark
progress = progress.ljust(progress_width)
progress = colorize(progress, situation)
progress << " " * (progress_width - string_width(progress))
end
puts("#{start_mark}#{progress}#{finish_mark}#{statistics}")
end
Expand Down

0 comments on commit 423345a

Please sign in to comment.