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

ruby-changes:45486

From: nobu <ko1@a...>
Date: Tue, 7 Feb 2017 14:19:35 +0900 (JST)
Subject: [ruby-changes:45486] nobu:r57559 (trunk): test/unit.rb: most-asserted

nobu	2017-02-07 14:19:29 +0900 (Tue, 07 Feb 2017)

  New Revision: 57559

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

  Log:
    test/unit.rb: most-asserted
    
    * test/lib/test/unit.rb (Statistics#record): record most asserted
      tests.

  Modified files:
    trunk/test/lib/test/unit.rb
Index: test/lib/test/unit.rb
===================================================================
--- test/lib/test/unit.rb	(revision 57558)
+++ test/lib/test/unit.rb	(revision 57559)
@@ -587,12 +587,22 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit.rb#L587
     end
 
     module Statistics
+      def update_list(list, rec, max)
+        if i = list.empty? ? 0 : list.bsearch_index {|*a| yield(*a)}
+          list[i, 0] = [rec]
+          list[max..-1] = [] if list.size >= max
+        end
+      end
+
       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
+        if @options.values_at(:longest, :most_asserted).any?
+          @tops ||= {}
+          rec = [suite.name, method, assertions, time, error]
+          if max = @options[:longest]
+            update_list(@tops[:longest] ||= [], rec, max) {|_,_,_,t,_|t<time}
+          end
+          if max = @options[:most_asserted]
+            update_list(@tops[:most_asserted] ||= [], rec, max) {|_,_,a,_,_|a<assertions}
           end
         end
         # (((@record ||= {})[suite] ||= {})[method]) = [assertions, time, error]
@@ -601,10 +611,15 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit.rb#L611
 
       def run(*args)
         result = super
-        if defined?(@longest) and @longest
-          @longest.each {|suite, method, assertions, time, error|
-            printf "%5.2fsec(%d): %s#%s\n", time, assertions, suite, method
-          }
+        if @tops ||= nil
+          @tops.each do |t, list|
+            if list
+              puts "#{t.to_s.tr('_', ' ')} tests:"
+              list.each {|suite, method, assertions, time, error|
+                printf "%5.2fsec(%d): %s#%s\n", time, assertions, suite, method
+              }
+            end
+          end
         end
         result
       end
@@ -616,6 +631,9 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit.rb#L631
         opts.on '--longest=N', Integer, 'Show longest N tests' do |n|
           options[:longest] = n
         end
+        opts.on '--most-asserted=N', Integer, 'Show most asserted N tests' do |n|
+          options[:most_asserted] = n
+        end
       end
     end
 

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

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