[前][次][番号順一覧][スレッド一覧]

ruby-changes:23523

From: nobu <ko1@a...>
Date: Tue, 8 May 2012 03:51:46 +0900 (JST)
Subject: [ruby-changes:23523] nobu:r35574 (trunk): sample/test.rb: refine output

nobu	2012-05-08 03:51:26 +0900 (Tue, 08 May 2012)

  New Revision: 35574

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35574

  Log:
    sample/test.rb: refine output
    
    * sample/test.rb (PROGRESS): refine output.

  Modified files:
    trunk/ChangeLog
    trunk/sample/test.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35573)
+++ ChangeLog	(revision 35574)
@@ -1,3 +1,7 @@
+Tue May  8 03:51:19 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* sample/test.rb (PROGRESS): refine output.
+
 Tue May  8 02:34:26 2012  NARUSE, Yui  <naruse@r...>
 
 	* lib/minitest/unit.rb (assert_match): refix of r35563.
Index: sample/test.rb
===================================================================
--- sample/test.rb	(revision 35573)
+++ sample/test.rb	(revision 35574)
@@ -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 @@
   $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 @@
 
 test_ok true   # reach here or dumps core
 
+PROGRESS.finish
 if $failed > 0
   printf "not ok/test: %d failed %d\n", $ntest, $failed
 else

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]