summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--sample/test.rb51
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 <nobu@ruby-lang.org>
+
+ * sample/test.rb (PROGRESS): refine output.
+
Tue May 8 02:34:26 2012 NARUSE, Yui <naruse@ruby-lang.org>
* 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