mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
lib/test/unit.rb: output in status line
* lib/test/unit.rb (Test::Unit::StatusLineOutput): new class to output in status line. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35578 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
fca2ac964d
commit
fbebe84864
2 changed files with 101 additions and 25 deletions
|
@ -1,4 +1,7 @@
|
||||||
Tue May 8 03:54:06 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Tue May 8 03:54:20 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/test/unit.rb (Test::Unit::StatusLineOutput): new class to output
|
||||||
|
in status line.
|
||||||
|
|
||||||
* test/testunit/test_hideskip.rb (TestHideSkip#test_hideskip):
|
* test/testunit/test_hideskip.rb (TestHideSkip#test_hideskip):
|
||||||
MiniTest#puke now reports Skipped messages only if verbose mode.
|
MiniTest#puke now reports Skipped messages only if verbose mode.
|
||||||
|
|
121
lib/test/unit.rb
121
lib/test/unit.rb
|
@ -65,6 +65,7 @@ module Test
|
||||||
opts.version = MiniTest::Unit::VERSION
|
opts.version = MiniTest::Unit::VERSION
|
||||||
|
|
||||||
options[:retry] = true
|
options[:retry] = true
|
||||||
|
options[:job_status] ||= :replace if @tty
|
||||||
|
|
||||||
opts.on '-h', '--help', 'Display this help.' do
|
opts.on '-h', '--help', 'Display this help.' do
|
||||||
puts opts
|
puts opts
|
||||||
|
@ -375,18 +376,22 @@ module Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def terminal_width
|
def terminal_width
|
||||||
@terminal_width ||=
|
unless @terminal_width
|
||||||
begin
|
begin
|
||||||
require 'io/console'
|
require 'io/console'
|
||||||
$stdout.winsize[1]
|
width = $stdout.winsize[1]
|
||||||
rescue LoadError, NoMethodError
|
rescue LoadError, NoMethodError, Errno::ENOTTY
|
||||||
ENV["COLUMNS"].to_i.nonzero? || 80
|
width = ENV["COLUMNS"].to_i.nonzero? || 80
|
||||||
end
|
end
|
||||||
|
width -= 1 if /mswin|mingw/ =~ RUBY_PLATFORM
|
||||||
|
@terminal_width = width
|
||||||
|
end
|
||||||
|
@terminal_width
|
||||||
end
|
end
|
||||||
|
|
||||||
def del_status_line
|
def del_status_line
|
||||||
return unless @tty
|
return unless @tty
|
||||||
print "\r"+" "*terminal_width+"\r"
|
print "\r"+" "*@status_line_size+"\r"
|
||||||
$stdout.flush
|
$stdout.flush
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -395,15 +400,24 @@ module Test
|
||||||
@status_line_size ||= 0
|
@status_line_size ||= 0
|
||||||
del_status_line
|
del_status_line
|
||||||
$stdout.flush
|
$stdout.flush
|
||||||
line = line[0...@terminal_width]
|
line = line[0...terminal_width]
|
||||||
print line
|
print line
|
||||||
$stdout.flush
|
$stdout.flush
|
||||||
@status_line_size = line.size
|
@status_line_size = line.size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_status(line)
|
||||||
|
return print(line) unless @tty
|
||||||
|
@status_line_size ||= 0
|
||||||
|
line = line[0...(terminal_width-@status_line_size)]
|
||||||
|
print line
|
||||||
|
$stdout.flush
|
||||||
|
@status_line_size += line.size
|
||||||
|
end
|
||||||
|
|
||||||
def jobs_status
|
def jobs_status
|
||||||
return unless @options[:job_status]
|
return unless @options[:job_status]
|
||||||
puts "" unless @options[:verbose]
|
puts "" unless @options[:verbose] or @tty
|
||||||
status_line = @workers.map(&:to_s).join(" ")
|
status_line = @workers.map(&:to_s).join(" ")
|
||||||
if @options[:job_status] == :replace and @tty
|
if @options[:job_status] == :replace and @tty
|
||||||
put_status status_line
|
put_status status_line
|
||||||
|
@ -413,7 +427,7 @@ module Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def del_jobs_status
|
def del_jobs_status
|
||||||
return unless @options[:job_status] == :replace && @jstr_size.nonzero?
|
return unless @options[:job_status] == :replace && @status_line_size.nonzero?
|
||||||
del_status_line
|
del_status_line
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -582,28 +596,23 @@ module Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if @interrupt || !@options[:retry] || @need_quit
|
if !(@interrupt || !@options[:retry] || @need_quit) && @workers
|
||||||
|
@options[:parallel] = false
|
||||||
|
suites, rep = rep.partition {|r| r[:testcase] && r[:file] && !r[:report].empty?}
|
||||||
|
suites.map {|r| r[:file]}.uniq.each {|file| require file}
|
||||||
|
suites.map! {|r| eval("::"+r[:testcase])}
|
||||||
|
puts ""
|
||||||
|
puts "Retrying..."
|
||||||
|
puts ""
|
||||||
|
_run_suites(suites, type)
|
||||||
|
end
|
||||||
|
unless rep.empty?
|
||||||
rep.each do |r|
|
rep.each do |r|
|
||||||
report.push(*r[:report])
|
report.push(*r[:report])
|
||||||
end
|
end
|
||||||
@errors += rep.map{|x| x[:result][0] }.inject(:+)
|
@errors += rep.map{|x| x[:result][0] }.inject(:+)
|
||||||
@failures += rep.map{|x| x[:result][1] }.inject(:+)
|
@failures += rep.map{|x| x[:result][1] }.inject(:+)
|
||||||
@skips += rep.map{|x| x[:result][2] }.inject(:+)
|
@skips += rep.map{|x| x[:result][2] }.inject(:+)
|
||||||
elsif @workers
|
|
||||||
puts ""
|
|
||||||
puts "Retrying..."
|
|
||||||
puts ""
|
|
||||||
rep.each do |r|
|
|
||||||
if r[:testcase] && r[:file] && !r[:report].empty?
|
|
||||||
require r[:file]
|
|
||||||
_run_suite(eval("::"+r[:testcase]),type)
|
|
||||||
else
|
|
||||||
report.push(*r[:report])
|
|
||||||
@errors += r[:result][0]
|
|
||||||
@failures += r[:result][1]
|
|
||||||
@skips += r[:result][2]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if @warnings
|
if @warnings
|
||||||
warn ""
|
warn ""
|
||||||
|
@ -622,6 +631,7 @@ module Test
|
||||||
end
|
end
|
||||||
|
|
||||||
def _run_suites suites, type
|
def _run_suites suites, type
|
||||||
|
_prepare_run(suites, type)
|
||||||
@interrupt = nil
|
@interrupt = nil
|
||||||
result = []
|
result = []
|
||||||
GC.start
|
GC.start
|
||||||
|
@ -645,6 +655,42 @@ module Test
|
||||||
|
|
||||||
alias mini_run_suite _run_suite
|
alias mini_run_suite _run_suite
|
||||||
|
|
||||||
|
def _prepare_run(suites, type)
|
||||||
|
if @tty
|
||||||
|
@verbose ||= !options[:parallel]
|
||||||
|
MiniTest::Unit.output = StatusLineOutput.new(self)
|
||||||
|
end
|
||||||
|
if /\A\/(.*)\/\z/ =~ (filter = options[:filter])
|
||||||
|
options[:filter] = filter = Regexp.new($1)
|
||||||
|
end
|
||||||
|
type = "#{type}_methods"
|
||||||
|
total = if filter
|
||||||
|
suites.inject(0) {|n, suite| n + suite.send(type).grep(filter).size}
|
||||||
|
else
|
||||||
|
suites.inject(0) {|n, suite| n + suite.send(type).size}
|
||||||
|
end
|
||||||
|
@test_count = 0
|
||||||
|
@total_tests = total.to_s(10)
|
||||||
|
end
|
||||||
|
|
||||||
|
def new_test(s)
|
||||||
|
put_status("[#{(@test_count += 1).to_s(10).rjust(@total_tests.size)}/#{@total_tests}] #{s}")
|
||||||
|
end
|
||||||
|
|
||||||
|
def _print(s); $stdout.print(s); end
|
||||||
|
def succeed; del_status_line; end
|
||||||
|
|
||||||
|
def failed(s)
|
||||||
|
$stdout.puts
|
||||||
|
@report_count ||= 0
|
||||||
|
report.each do |msg|
|
||||||
|
next if @options[:hide_skip] and msg.start_with? "Skipped:"
|
||||||
|
msg = msg.split(/$/, 2)
|
||||||
|
$stdout.puts "#{@failed_color}%3d) %s#{@reset_color}%s\n" % [@report_count += 1, *msg]
|
||||||
|
end
|
||||||
|
report.clear
|
||||||
|
end
|
||||||
|
|
||||||
# Overriding of MiniTest::Unit#puke
|
# Overriding of MiniTest::Unit#puke
|
||||||
def puke klass, meth, e
|
def puke klass, meth, e
|
||||||
# TODO:
|
# TODO:
|
||||||
|
@ -662,6 +708,12 @@ module Test
|
||||||
def initialize # :nodoc:
|
def initialize # :nodoc:
|
||||||
super
|
super
|
||||||
@tty = $stdout.tty?
|
@tty = $stdout.tty?
|
||||||
|
if @tty and /mswin|mingw/ !~ RUBY_PLATFORM and /dumb/ !~ ENV["TERM"]
|
||||||
|
@failed_color = "\e[31m"
|
||||||
|
@reset_color = "\e[m"
|
||||||
|
else
|
||||||
|
@failed_color = @reset_color = ""
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def status(*args)
|
def status(*args)
|
||||||
|
@ -677,6 +729,27 @@ module Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class StatusLineOutput < Struct.new(:runner)
|
||||||
|
def puts(*a) $stdout.puts(*a) unless a.empty? end
|
||||||
|
def respond_to_missing?(*a) $stdout.respond_to?(*a) end
|
||||||
|
def method_missing(*a, &b) $stdout.__send__(*a, &b) end
|
||||||
|
|
||||||
|
def print(s)
|
||||||
|
case s
|
||||||
|
when /\A(.*\#.*) = \z/
|
||||||
|
runner.new_test($1)
|
||||||
|
when /\A(.* s) = \z/
|
||||||
|
runner.add_status(" = "+$1.chomp)
|
||||||
|
when /\A\.\z/
|
||||||
|
runner.succeed
|
||||||
|
when /\A[EFS]\z/
|
||||||
|
runner.failed(s)
|
||||||
|
else
|
||||||
|
$stdout.print(s)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class AutoRunner
|
class AutoRunner
|
||||||
class Runner < Test::Unit::Runner
|
class Runner < Test::Unit::Runner
|
||||||
include Test::Unit::RequireFiles
|
include Test::Unit::RequireFiles
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue