From 8da4634bc31db3e8ec4f20ef734aac1e3053dc14 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 7 May 2012 18:51:26 +0000 Subject: 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 --- ChangeLog | 4 ++++ sample/test.rb | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1ebba7ae97..3bf244ac13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Tue May 8 03:51:19 2012 Nobuyoshi Nakada + + * sample/test.rb (PROGRESS): refine output. + Tue May 8 02:34:26 2012 NARUSE, Yui * lib/minitest/unit.rb (assert_match): refix of r35563. 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 -- cgit v1.2.3