summaryrefslogtreecommitdiff
path: root/sample
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-05-07 18:51:26 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-05-07 18:51:26 +0000
commit8da4634bc31db3e8ec4f20ef734aac1e3053dc14 (patch)
treeff7104bcf3f308a2821fb0723638ca5f589b38da /sample
parent9c4fc91c6b98b8ebacc599ae2eadb1eea503fa93 (diff)
downloadruby-8da4634bc31db3e8ec4f20ef734aac1e3053dc14.tar.gz
sample/test.rb: refine output
* sample/test.rb (PROGRESS): refine output. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35574 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample')
-rw-r--r--sample/test.rb51
1 files changed, 49 insertions, 2 deletions
diff --git a/sample/test.rb b/sample/test.rb
index 4e934f1f84..cfc02dd9b8 100644
--- a/sample/test.rb
+++ b/sample/test.rb
@@ -4,9 +4,55 @@
$testnum=0
$ntest=0
$failed = 0
+PROGRESS = Object.new
+PROGRESS.instance_eval do
+ @count = 0
+ @rotator = %w[- \\ | /]
+ @bs = "\b" * @rotator[0].size
+ @tty = STDERR.tty?
+ if @tty and /mswin|mingw/ !~ RUBY_PLATFORM and /dumb/ !~ ENV["TERM"]
+ @passed = "\e[32m"
+ @failed = "\e[31m"
+ @reset = "\e[m"
+ else
+ @passed = @failed = @reset = ""
+ end
+
+ if @tty
+ def self.pass
+ STDERR.print "#{@bs}#{@rotator[(@count += 1) % @rotator.size]}"
+ end
+ def self.fail
+ @ok = false
+ STDERR.print "#{@bs}#{@failed}F#{@reset}#{@rotator[@count % @rotator.size]}"
+ end
+ def self.init
+ @ok = true
+ STDERR.print " "
+ end
+ def self.finish
+ STDERR.print "#{@bs}#{' ' * @bs.size}#{@bs}#{@passed}#{@ok ? 'OK' : ''} #{$testnum}#{@reset}"
+ end
+ else
+ def self.pass
+ STDERR.print "."
+ end
+ def self.fail
+ STDERR.print "F"
+ end
+ def self.init
+ end
+ def self.finish
+ end
+ end
+end
def test_check(what)
+ unless $ntest.zero?
+ PROGRESS.finish
+ end
STDERR.print "\nsample/test.rb:#{what} "
+ PROGRESS.init
$what = what
$testnum = 0
end
@@ -16,10 +62,10 @@ def test_ok(cond,n=1)
$ntest+=1
where = (st = caller(n)) ? st[0] : "caller error! (n=#{n}, trace=#{caller(0).join(', ')}"
if cond
- STDERR.print "."
+ PROGRESS.pass
printf "ok %d (%s)\n", $testnum, where
else
- STDERR.print "F"
+ PROGRESS.fail
printf "not ok %s %d -- %s\n", $what, $testnum, where
$failed+=1
end
@@ -2259,6 +2305,7 @@ ObjectSpace.each_object{|o|
test_ok true # reach here or dumps core
+PROGRESS.finish
if $failed > 0
printf "not ok/test: %d failed %d\n", $ntest, $failed
else