Navigation Menu

Skip to content

Commit

Permalink
Show progress line
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 11, 2012
1 parent 047b99a commit c79a3a1
Showing 1 changed file with 41 additions and 7 deletions.
48 changes: 41 additions & 7 deletions lib/groonga/tester.rb
Expand Up @@ -231,6 +231,8 @@ def command_exist?(name)
class Worker
attr_reader :id, :tester, :test_suites_rusult, :reporter
attr_reader :suite_name, :test_script_path, :status
attr_reader :n_tests, :n_passed_tests, :n_failed_tests
attr_reader :n_not_checked_tests, :elapsed_time
def initialize(id, tester, test_suites_result, reporter)
@id = id
@tester = tester
Expand Down Expand Up @@ -434,15 +436,16 @@ def run_test_suites(test_suites)
queue << [suite_name, test_script_path]
end
end
@tester.n_workers.times do
queue << nil
end

workers = []
@tester.n_workers.times do |i|
workers << Worker.new(i, @tester, @result, @reporter)
end
@reporter.start(workers.dup)
@reporter.start(workers.dup, queue.size)

@tester.n_workers.times do
queue << nil
end

succeeded = true
worker_threads = []
Expand Down Expand Up @@ -1378,7 +1381,7 @@ def initialize(tester)
super
end

def start(workers)
def start(workers, n_tests)
end

def start_worker(worker)
Expand Down Expand Up @@ -1439,8 +1442,9 @@ def initialize(tester)
@workers = nil
end

def start(workers)
def start(workers, n_tests)
@workers = workers
@n_tests = n_tests
end

def start_worker(worker)
Expand Down Expand Up @@ -1496,6 +1500,7 @@ def draw
draw_status_line(worker)
draw_test_line(worker)
end
draw_progress_line
end

def draw_status_line(worker)
Expand All @@ -1518,6 +1523,27 @@ def draw_test_line(worker)
puts(justify(label, @term_width))
end

def draw_progress_line
n_done_tests = @workers.collect(&:n_tests).inject(&:+)
finished_test_ratio = n_done_tests.to_f / @n_tests

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
if n_done_tests == @n_tests
progress = "=" * progress_width
else
progress = "=" * (progress_width * finished_test_ratio).ceil + ">"
progress = progress.ljust(progress_width)
end
puts("#{start_mark}#{progress}#{finish_mark}#{statistics}")
end

def redraw
@mutex.synchronize do
draw
Expand All @@ -1540,7 +1566,15 @@ def clear_line
end

def n_using_lines
2 * n_workers
n_worker_lines * n_workers + n_progress_lines
end

def n_worker_lines
2
end

def n_progress_lines
1
end

def n_workers
Expand Down

0 comments on commit c79a3a1

Please sign in to comment.