class Grntest::Reporters::InplaceReporter

Public Class Methods

new(tester) click to toggle source
Calls superclass method Grntest::Reporters::BaseReporter::new
# File lib/grntest/reporters/inplace-reporter.rb, line 22
def initialize(tester)
  super
  @last_redraw_time = Time.now
  @minimum_redraw_interval = 0.1
end

Public Instance Methods

on_finish(result) click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 91
def on_finish(result)
  draw
  puts
  report_summary(result)
end
on_start(result) click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 28
def on_start(result)
  @test_suites_result = result
end
on_suite_finish(worker) click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 83
def on_suite_finish(worker)
  redraw
end
on_suite_start(worker) click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 35
def on_suite_start(worker)
  redraw
end
on_test_failure(worker, result) click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 47
def on_test_failure(worker, result)
  redraw do
    report_test(worker, result)
    report_failure(result)
  end
end
on_test_finish(worker, result) click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 79
def on_test_finish(worker, result)
  redraw
end
on_test_leak(worker, result) click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 54
def on_test_leak(worker, result)
  redraw do
    report_test(worker, result)
    report_marker(result)
    report_actual(result) unless result.checked?
  end
end
on_test_no_check(worker, result) click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 72
def on_test_no_check(worker, result)
  redraw do
    report_test(worker, result)
    report_actual(result)
  end
end
on_test_omission(worker, result) click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 62
def on_test_omission(worker, result)
  redraw do
    report_test(worker, result)
    report_actual(result)
  end
end
on_test_omission_suppressed(worker, result) click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 69
def on_test_omission_suppressed(worker, result)
end
on_test_start(worker) click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 39
def on_test_start(worker)
  redraw
end
on_test_success(worker, result) click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 43
def on_test_success(worker, result)
  redraw
end
on_worker_finish(worker) click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 87
def on_worker_finish(worker)
  redraw
end
on_worker_start(worker) click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 32
def on_worker_start(worker)
end

Private Instance Methods

clear_line() click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 183
def clear_line
  print(" " * @term_width)
  print("\r")
  reset_current_column
end
draw() click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 98
def draw
  draw_statistics_header_line
  @test_suites_result.workers.each do |worker|
    draw_status_line(worker)
    draw_test_line(worker)
  end
  draw_progress_line
end
draw_progress_line() click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 131
def draw_progress_line
  n_done_tests = @test_suites_result.n_tests
  n_total_tests = @test_suites_result.n_total_tests
  if n_total_tests.zero?
    finished_test_ratio = 0.0
  else
    finished_test_ratio = n_done_tests.to_f / n_total_tests
  end

  start_mark = "|"
  finish_mark = "|"
  statistics = " [%3d%%]" % (finished_test_ratio * 100)

  progress_width = @term_width
  progress_width -= start_mark.bytesize
  progress_width -= finish_mark.bytesize
  progress_width -= statistics.bytesize
  finished_mark = "-"
  if n_done_tests == n_total_tests
    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, @test_suites_result)
    progress << " " * (progress_width - string_width(progress))
  end
  puts("#{start_mark}#{progress}#{finish_mark}#{statistics}")
end
draw_statistics_header_line() click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 107
def draw_statistics_header_line
  puts(statistics_header)
end
draw_status_line(worker) click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 111
def draw_status_line(worker)
  clear_line
  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)
  center = justify(worker.suite_name, center_width)
  puts("#{left}#{center}#{right}")
end
draw_test_line(worker) click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 121
def draw_test_line(worker)
  clear_line
  if worker.test_name
    label = "  #{worker.test_name}"
  else
    label = statistics(worker.result)
  end
  puts(justify(label, @term_width))
end
n_progress_lines() click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 201
def n_progress_lines
  1
end
n_statistics_header_line() click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 193
def n_statistics_header_line
  1
end
n_using_lines() click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 189
def n_using_lines
  n_statistics_header_line + n_worker_lines * n_workers + n_progress_lines
end
n_worker_lines() click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 197
def n_worker_lines
  2
end
n_workers() click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 205
def n_workers
  @tester.n_workers
end
redraw() { || ... } click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 164
def redraw
  synchronize do
    unless block_given?
      return if Time.now - @last_redraw_time < @minimum_redraw_interval
    end
    draw
    if block_given?
      yield
    else
      up_n_lines(n_using_lines)
    end
    @last_redraw_time = Time.now
  end
end
up_n_lines(n) click to toggle source
# File lib/grntest/reporters/inplace-reporter.rb, line 179
def up_n_lines(n)
  print("\e[1A" * n)
end