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

ruby-changes:45094

From: nobu <ko1@a...>
Date: Sat, 24 Dec 2016 09:51:05 +0900 (JST)
Subject: [ruby-changes:45094] nobu:r57167 (trunk): test/unit.rb: --repeat-count option

nobu	2016-12-24 09:50:59 +0900 (Sat, 24 Dec 2016)

  New Revision: 57167

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

  Log:
    test/unit.rb: --repeat-count option
    
    * test/lib/test/unit.rb (Test::Unit::RepeatOption): --repeat-count
      option to repeat COUNT times while success.

  Modified files:
    trunk/test/lib/minitest/unit.rb
    trunk/test/lib/test/unit.rb
Index: test/lib/minitest/unit.rb
===================================================================
--- test/lib/minitest/unit.rb	(revision 57166)
+++ test/lib/minitest/unit.rb	(revision 57167)
@@ -872,35 +872,45 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/test/lib/minitest/unit.rb#L872
       suites = TestCase.send "#{type}_suites"
       return if suites.empty?
 
-      start = Time.now
-
       puts
       puts "# Running #{type}s:"
       puts
 
       @test_count, @assertion_count = 0, 0
+      test_count = assertion_count = 0
       sync = output.respond_to? :"sync=" # stupid emacs
       old_sync, output.sync = output.sync, true if sync
 
-      results = _run_suites suites, type
-
-      @test_count      = results.inject(0) { |sum, (tc, _)| sum + tc }
-      @assertion_count = results.inject(0) { |sum, (_, ac)| sum + ac }
+      count = 0
+      begin
+        start = Time.now
+
+        results = _run_suites suites, type
+
+        @test_count      = results.inject(0) { |sum, (tc, _)| sum + tc }
+        @assertion_count = results.inject(0) { |sum, (_, ac)| sum + ac }
+        test_count      += @test_count
+        assertion_count += @assertion_count
+        t = Time.now - start
+        count += 1
+        unless @repeat_count
+          puts
+          puts
+        end
+        puts "Finished%s %ss in %.6fs, %.4f tests/s, %.4f assertions/s.\n" %
+             [(@repeat_count ? "(#{count}/#{@repeat_count}) " : ""), type,
+               t, @test_count.fdiv(t), @assertion_count.fdiv(t)]
+      end while @repeat_count && count < @repeat_count && report.empty?
 
       output.sync = old_sync if sync
 
-      t = Time.now - start
-
-      puts
-      puts
-      puts "Finished #{type}s in %.6fs, %.4f tests/s, %.4f assertions/s." %
-        [t, test_count / t, assertion_count / t]
-
       report.each_with_index do |msg, i|
         puts "\n%3d) %s" % [i + 1, msg]
       end
 
       puts
+      @test_count      = test_count
+      @assertion_count = assertion_count
 
       status
     end
Index: test/lib/test/unit.rb
===================================================================
--- test/lib/test/unit.rb	(revision 57166)
+++ test/lib/test/unit.rb	(revision 57167)
@@ -853,6 +853,22 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit.rb#L853
       end
     end
 
+    module RepeatOption # :nodoc: all
+      def setup_options(parser, options)
+        super
+        options[:repeat_count] = nil
+        parser.separator "repeat options:"
+        parser.on '--repeat-count=NUM', "Number of times to repeat", Integer do |n|
+          options[:repeat_count] = n
+        end
+      end
+
+      def _run_anything(type)
+        @repeat_count = @options[:repeat_count]
+        super
+      end
+    end
+
     module ExcludesOption # :nodoc: all
       class ExcludedMethods < Struct.new(:excludes)
         def exclude(name, reason)
@@ -922,6 +938,7 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit.rb#L938
       include Test::Unit::Parallel
       include Test::Unit::Skipping
       include Test::Unit::GlobOption
+      include Test::Unit::RepeatOption
       include Test::Unit::LoadPathOption
       include Test::Unit::GCStressOption
       include Test::Unit::ExcludesOption

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

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