Navigation Menu

Skip to content

Commit

Permalink
Colorize summary
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 11, 2012
1 parent ed07f6f commit 49c1be5
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions lib/groonga/tester.rb
Expand Up @@ -1328,10 +1328,11 @@ def initialize(tester)

private
def report_summary(result)
puts(statistics(result))
puts(colorize(statistics(result), result))
pass_ratio = result.pass_ratio
elapsed_time = result.elapsed_time
puts("%.4g%% passed in %.4fs." % [pass_ratio, elapsed_time])
summary = "%.4g%% passed in %.4fs." % [pass_ratio, elapsed_time]
puts(colorize(summary, result))
end

def statistics(result)
Expand All @@ -1354,19 +1355,19 @@ def throughput(result)
end

def report_failure(result)
report_marker(result.status)
report_marker(result)
report_diff(result.expected, result.actual)
report_marker(result.status)
report_marker(result)
end

def report_actual(result)
report_marker(result.status)
report_marker(result)
puts(result.actual)
report_marker(result.status)
report_marker(result)
end

def report_marker(situation)
puts(colorize("=" * @term_width, situation))
def report_marker(result)
puts(colorize("=" * @term_width, result))
end

def report_diff(expected, actual)
Expand All @@ -1391,8 +1392,7 @@ def report_test_result(result, label)
end

def test_result_message(result, label)
situation = result.status
" %7.4fs [%s]" % [result.elapsed_time, colorize(label, situation)]
" %7.4fs [%s]" % [result.elapsed_time, colorize(label, result)]
end

def justify(message, width)
Expand Down Expand Up @@ -1437,18 +1437,22 @@ def string_width(string)
end

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

def colorize(message, situation)
def colorize(message, result)
return message unless @tester.use_color?
case situation
case result_status(result)
when :success
"%s%s%s" % [success_color, message, reset_color]
when :failure
Expand Down Expand Up @@ -1670,7 +1674,7 @@ def finish(result)

private
def report_test(worker, result)
report_marker(result.status)
report_marker(result)
puts("[#{worker.id}] #{worker.suite_name}")
print(" #{worker.test_name}")
report_test_result(result, worker.status)
Expand All @@ -1686,8 +1690,7 @@ def draw

def draw_status_line(worker)
clear_line
situation = result_status(worker.result)
left = "[#{colorize(worker.id, situation)}] "
left = "[#{colorize(worker.id, worker.result)}] "
right = " [#{worker.status}]"
rest_width = @term_width - @current_column
center_width = rest_width - string_width(left) - string_width(right)
Expand Down Expand Up @@ -1719,16 +1722,16 @@ 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 = colorize(finished_mark * progress_width, situation)
progress = colorize(finished_mark * progress_width,
@test_suites_result)
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 = colorize(progress, situation)
progress = colorize(progress, @test_suites_result)
progress << " " * (progress_width - string_width(progress))
end
puts("#{start_mark}#{progress}#{finish_mark}#{statistics}")
Expand Down

0 comments on commit 49c1be5

Please sign in to comment.