Skip to content

Commit

Permalink
* lib/test/unit.rb (terminal_width, del_status_line, put_status):
Browse files Browse the repository at this point in the history
  extract as methods.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35169 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Mar 29, 2012
1 parent aad347f commit 95b30b0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Thu Mar 29 16:35:32 2012 Nobuyoshi Nakada <[email protected]>

* lib/test/unit.rb (terminal_width, del_status_line, put_status):
extract as methods.

Thu Mar 29 10:20:18 2012 Martin Bosslet <[email protected]>

* ext/openssl/ossl_pkcs7.c: fix crash when parsing garbage data.
Expand Down
52 changes: 37 additions & 15 deletions lib/test/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -374,32 +374,47 @@ def after_worker_down(worker, e=nil, c=false)
exit c
end

def terminal_width
@terminal_width ||=
begin
require 'io/console'
$stdout.winsize[1]
rescue LoadError, NoMethodError
ENV["COLUMNS"].to_i.nonzero? || 80
end
end

def del_status_line
return unless @tty
print "\r"+" "*terminal_width+"\r"
$stdout.flush
end

def put_status(line)
return print(line) unless @tty
@status_line_size ||= 0
del_status_line
$stdout.flush
line = line[0...@terminal_width]
print line
$stdout.flush
@status_line_size = line.size
end

def jobs_status
return unless @options[:job_status]
puts "" unless @options[:verbose]
status_line = @workers.map(&:to_s).join(" ")
if @options[:job_status] == :replace and $stdout.tty?
@terminal_width ||=
begin
require 'io/console'
$stdout.winsize[1]
rescue LoadError, NoMethodError
ENV["COLUMNS"].to_i.nonzero? || 80
end
@jstr_size ||= 0
del_jobs_status
$stdout.flush
print status_line[0...@terminal_width]
$stdout.flush
@jstr_size = [status_line.size, @terminal_width].min
if @options[:job_status] == :replace and @tty
put_status status_line
else
puts status_line
end
end

def del_jobs_status
return unless @options[:job_status] == :replace && @jstr_size.nonzero?
print "\r"+" "*@jstr_size+"\r"
del_status_line
end

def after_worker_quit(worker)
Expand Down Expand Up @@ -627,6 +642,8 @@ def _run_suites suites, type
result
end

alias mini_run_suite _run_suite

# Overriding of MiniTest::Unit#puke
def puke klass, meth, e
# TODO:
Expand All @@ -649,6 +666,11 @@ def puke klass, meth, e
e[0, 1]
end

def initialize # :nodoc:
super
@tty = $stdout.tty?
end

def status(*args)
result = super
raise @interrupt if @interrupt
Expand Down
2 changes: 1 addition & 1 deletion lib/test/unit/parallel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class << self
undef autorun
end

alias orig_run_suite _run_suite
alias orig_run_suite mini_run_suite
undef _run_suite
undef _run_suites
undef run
Expand Down

0 comments on commit 95b30b0

Please sign in to comment.