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

ruby-changes:45481

From: nobu <ko1@a...>
Date: Tue, 7 Feb 2017 11:49:10 +0900 (JST)
Subject: [ruby-changes:45481] nobu:r57554 (trunk): test/unit.rb: statistics

nobu	2017-02-07 11:49:04 +0900 (Tue, 07 Feb 2017)

  New Revision: 57554

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57554

  Log:
    test/unit.rb: statistics
    
    * test/lib/test/unit.rb (Test::Unit::Statistics): show statistics.
      only --longest option is implemented right now.

  Modified files:
    trunk/test/lib/test/unit.rb
Index: test/lib/test/unit.rb
===================================================================
--- test/lib/test/unit.rb	(revision 57553)
+++ test/lib/test/unit.rb	(revision 57554)
@@ -573,6 +573,39 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit.rb#L573
       end
     end
 
+    module Statistics
+      def record(suite, method, assertions, time, error)
+        if max = @options[:longest]
+          longest = @longest ||= []
+          if i = longest.empty? ? 0 : longest.bsearch_index {|_,_,_,t,_|t<time}
+            longest[i, 0] = [[suite.name, method, assertions, time, error]]
+            longest[max..-1] = [] if longest.size >= max
+          end
+        end
+        # (((@record ||= {})[suite] ||= {})[method]) = [assertions, time, error]
+        super
+      end
+
+      def run(*args)
+        result = super
+        if @longest
+          @longest.each {|suite, method, assertions, time, error|
+            printf "%5.2fsec(%d): %s#%s\n", time, assertions, suite, method
+          }
+        end
+        result
+      end
+
+      private
+      def setup_options(opts, options)
+        super
+        opts.separator "statistics options:"
+        opts.on '--longest=N', Integer, 'Show longest N tests' do |n|
+          options[:longest] = n
+        end
+      end
+    end
+
     module StatusLine # :nodoc: all
       def terminal_width
         unless @terminal_width ||= nil
@@ -988,6 +1021,7 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit.rb#L1021
       include Test::Unit::Options
       include Test::Unit::StatusLine
       include Test::Unit::Parallel
+      include Test::Unit::Statistics
       include Test::Unit::Skipping
       include Test::Unit::GlobOption
       include Test::Unit::RepeatOption

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

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