Permalink
Browse files

kern/minitest-reporters#103: Switching from PowerBar to ruby-progressbar

PowerBar seems to be a bit defunct (last updated a year ago, years-old
issues sitting open). But, most importantly, the `ProgressReporter`
makes my tests run 50% slower than any other reporter. That doesn’t
seem right—whatever is being done to generate the progress bar couldn’t
possibly be complicated enough to increase the test run time by 50%.

Since PowerBar is defunct I figured the easiest way is to just switch
to something actively developed, like ruby-progressbar, and that did
the trick. Test run times with the `ProgressReporter` now average the
same as the other reporters.

The output will almost be completely identical. The one change I made
is that now only the progress bar will be colored. Previously the
entire line would be green, and then change to yellow or red if there
was a skip or failure. Now only the progress bar itself will change
color, which makes the output visually easier to read.
  • Loading branch information...
1 parent 333c44b commit 25ac5cd5de6d1610fcdcb725ab007412e3b55ef3 @brandonweiss brandonweiss committed Apr 21, 2014
Showing with 20 additions and 26 deletions.
  1. +19 −25 lib/minitest/reporters/progress_reporter.rb
  2. +1 −1 minitest-reporters.gemspec
@@ -1,5 +1,5 @@
require 'ansi/code'
-require 'powerbar'
+require 'ruby-progressbar'
module Minitest
module Reporters
@@ -14,52 +14,53 @@ class ProgressReporter < BaseReporter
include RelativePosition
include ANSI::Code
- INFO_PADDING = 2
+ PROGRESS_MARK = '='
def initialize(options = {})
super
@detailed_skip = options.fetch(:detailed_skip, true)
- @progress = PowerBar.new(:msg => "0/#{count}")
- @progress.settings.tty.finite.output = lambda { |s| print(s) }
- @progress.settings.tty.finite.template.barchar = "="
- @progress.settings.tty.finite.template.padchar = " "
- @progress.settings.tty.finite.template.pre = "\e[1000D#{GREEN}"
- @progress.settings.tty.finite.template.post = CLEAR
+ @progress = ProgressBar.create({
+ total: total_count,
+ starting_at: count,
+ progress_mark: green(PROGRESS_MARK),
+ remainder_mark: ' ',
+ format: ' %C/%c: [%B] %p%% %a, %e',
+ autostart: false
+ })
end
def start
super
puts 'Started'
puts
+ @progress.start
show
end
def record(test)
super
if (test.skipped? && @detailed_skip) || test.failure
- wipe
print_colored_status(test)
print_test_with_time(test)
puts
print_info(test.failure, test.error?) if test.failure
puts
end
- if test.skipped? && color != RED
- self.color = YELLOW
+ if test.skipped? && color != "red"
+ self.color = "yellow"
elsif test.failure
- self.color = RED
+ self.color = "red"
end
show
end
def report
super
- @progress.close
+ @progress.finish
- wipe
puts
puts('Finished in %.5fs' % total_time)
print('%d tests, %d assertions, ' % [count, assertions])
@@ -73,15 +74,8 @@ def report
def show
return if count == 0
- @progress.show({
- :msg => "#{total_count}/#{count}",
- :done => count,
- :total => total_count,
- }, true)
- end
-
- def wipe
- @progress.wipe
+ @progress.total = total_count
+ @progress.increment
end
def print_test_with_time(test)
@@ -90,12 +84,12 @@ def print_test_with_time(test)
end
def color
- @color ||= GREEN
+ @color ||= "green"
end
def color=(color)
@color = color
- @progress.scope.template.pre = "\e[1000D#{@color}"
+ @progress.progress_mark = send(color, PROGRESS_MARK)
end
end
end
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
s.add_dependency 'minitest', '>= 5.0'
s.add_dependency 'ansi'
- s.add_dependency 'powerbar'
+ s.add_dependency 'ruby-progressbar'
s.add_dependency 'builder'
s.add_development_dependency 'maruku'

0 comments on commit 25ac5cd

Please sign in to comment.