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

ruby-changes:28501

From: ryan <ko1@a...>
Date: Thu, 2 May 2013 13:48:57 +0900 (JST)
Subject: [ruby-changes:28501] ryan:r40553 (trunk): Imported minitest 4.7.4 (r8483)

ryan	2013-05-02 13:48:43 +0900 (Thu, 02 May 2013)

  New Revision: 40553

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

  Log:
    Imported minitest 4.7.4 (r8483)

  Modified files:
    trunk/ChangeLog
    trunk/lib/minitest/README.txt
    trunk/lib/minitest/benchmark.rb
    trunk/lib/minitest/hell.rb
    trunk/lib/minitest/mock.rb
    trunk/lib/minitest/parallel_each.rb
    trunk/lib/minitest/spec.rb
    trunk/lib/minitest/unit.rb
    trunk/test/minitest/test_minitest_benchmark.rb
    trunk/test/minitest/test_minitest_mock.rb
    trunk/test/minitest/test_minitest_spec.rb
    trunk/test/minitest/test_minitest_unit.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40552)
+++ ChangeLog	(revision 40553)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu May  2 13:42:42 2013  Ryan Davis  <ryand-ruby@z...>
+
+	* lib/minitest/*: Imported minitest 4.7.4 (r8483)
+	* test/minitest/*: ditto
+
 Thu May  2 11:32:22 2013  NAKAMURA Usaku  <usa@r...>
 
 	* win32/win32.c (poll_child_status): [experimental] set the cause of
Index: lib/minitest/unit.rb
===================================================================
--- lib/minitest/unit.rb	(revision 40552)
+++ lib/minitest/unit.rb	(revision 40553)
@@ -5,10 +5,8 @@ https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L5
 # File a patch instead and assign it to Ryan Davis.
 ######################################################################
 
-require 'optparse'
-require 'rbconfig'
-require 'thread' # required for 1.8
-require 'minitest/parallel_each'
+require "optparse"
+require "rbconfig"
 
 ##
 # Minimal (mostly drop-in) replacement for test-unit.
@@ -40,6 +38,9 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L38
   class Skip < Assertion; end
 
   class << self
+    ##
+    # Filter object for backtraces.
+
     attr_accessor :backtrace_filter
   end
 
@@ -87,16 +88,17 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L88
     # figure out what diff to use.
 
     def self.diff
-      @diff = if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ then
+      @diff = if (RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ &&
+                  system("diff.exe", __FILE__, __FILE__)) then
                 "diff.exe -u"
+              elsif Minitest::Unit::Guard.maglev? then # HACK
+                "diff -u"
+              elsif system("gdiff", __FILE__, __FILE__)
+                "gdiff -u" # solaris and kin suck
+              elsif system("diff", __FILE__, __FILE__)
+                "diff -u"
               else
-                if system("gdiff", __FILE__, __FILE__)
-                  "gdiff -u" # solaris and kin suck
-                elsif system("diff", __FILE__, __FILE__)
-                  "diff -u"
-                else
-                  nil
-                end
+                nil
               end unless defined? @diff
 
       @diff
@@ -177,8 +179,8 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L179
     # newlines and makes hex-values generic (like object_ids). This
     # uses mu_pp to do the first pass and then cleans it up.
 
-    def mu_pp_for_diff obj # TODO: possibly rename
-      mu_pp(obj).gsub(/\\n/, "\n").gsub(/0x[a-f0-9]+/m, '0xXXXXXX')
+    def mu_pp_for_diff obj
+      mu_pp(obj).gsub(/\\n/, "\n").gsub(/:0x[a-fA-F0-9]{4,}/m, ':0xXXXXXX')
     end
 
     def _assertions= n # :nodoc:
@@ -203,18 +205,6 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L205
     end
 
     ##
-    # Fails unless the block returns a true value.
-    #
-    # NOTE: This method is deprecated, use assert. It will be removed
-    # on 2013-01-01."
-
-    def assert_block msg = nil
-      warn "NOTE: MiniTest::Unit::TestCase#assert_block is deprecated, use assert. It will be removed on 2013-01-01. Called from #{caller.first}"
-      msg = message(msg) { "Expected block to return true value" }
-      assert yield, msg
-    end
-
-    ##
     # Fails unless +obj+ is empty.
 
     def assert_empty obj, msg = nil
@@ -237,7 +227,7 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L227
 
     def assert_equal exp, act, msg = nil
       msg = message(msg, "") { diff exp, act }
-      assert(exp == act, msg)
+      assert exp == act, msg
     end
 
     ##
@@ -248,7 +238,9 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L238
 
     def assert_in_delta exp, act, delta = 0.001, msg = nil
       n = (exp - act).abs
-      msg = message(msg) { "Expected |#{exp} - #{act}| (#{n}) to be < #{delta}"}
+      msg = message(msg) {
+        "Expected |#{exp} - #{act}| (#{n}) to be <= #{delta}"
+      }
       assert delta >= n, msg
     end
 
@@ -562,6 +554,7 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L554
 
     def message msg = nil, ending = ".", &default
       proc {
+        msg = msg.call.chomp(".") if Proc === msg
         custom_message = "#{msg}.\n" unless msg.nil? or msg.to_s.empty?
         "#{custom_message}#{default.call}#{ending}"
       }
@@ -611,9 +604,9 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L604
     def refute_in_delta exp, act, delta = 0.001, msg = nil
       n = (exp - act).abs
       msg = message(msg) {
-        "Expected |#{exp} - #{act}| (#{n}) to not be < #{delta}"
+        "Expected |#{exp} - #{act}| (#{n}) to not be <= #{delta}"
       }
-      refute delta > n, msg
+      refute delta >= n, msg
     end
 
     ##
@@ -723,10 +716,18 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L716
 
     def skip msg = nil, bt = caller
       msg ||= "Skipped, no message given"
+      @skip = true
       raise MiniTest::Skip, msg, bt
     end
 
     ##
+    # Was this testcase skipped? Meant for #teardown.
+
+    def skipped?
+      defined?(@skip) and @skip
+    end
+
+    ##
     # Takes a block and wraps it with the runner's shared mutex.
 
     def synchronize
@@ -737,16 +738,28 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L738
   end
 
   class Unit # :nodoc:
-    VERSION = "4.3.2" # :nodoc:
+    VERSION = "4.7.4" # :nodoc:
 
     attr_accessor :report, :failures, :errors, :skips # :nodoc:
-    attr_accessor :test_count, :assertion_count       # :nodoc:
+    attr_accessor :assertion_count                    # :nodoc:
+    attr_writer   :test_count                         # :nodoc:
     attr_accessor :start_time                         # :nodoc:
     attr_accessor :help                               # :nodoc:
     attr_accessor :verbose                            # :nodoc:
     attr_writer   :options                            # :nodoc:
 
     ##
+    # :attr:
+    #
+    # if true, installs an "INFO" signal handler (only available to BSD and
+    # OS X users) which prints diagnostic information about the test run.
+    #
+    # This is auto-detected by default but may be overridden by custom
+    # runners.
+
+    attr_accessor :info_signal
+
+    ##
     # Lazy accessor for options.
 
     def options
@@ -847,6 +860,10 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L860
       output.print(*a)
     end
 
+    def test_count # :nodoc:
+      @test_count ||= 0
+    end
+
     ##
     # Runner for a given +type+ (eg, test vs bench).
 
@@ -888,15 +905,13 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L905
     end
 
     ##
-    # Runs all the +suites+ for a given +type+. Runs suites declaring
-    # a test_order of +:parallel+ in parallel, and everything else
-    # serial.
+    # Runs all the +suites+ for a given +type+.
+    #
+    # NOTE: this method is redefined in parallel_each.rb, which is
+    # loaded if a test-suite calls parallelize_me!.
 
     def _run_suites suites, type
-      parallel, serial = suites.partition { |s| s.test_order == :parallel }
-
-      ParallelEach.new(parallel).map { |suite| _run_suite suite, type } +
-        serial.map { |suite| _run_suite suite, type }
+      suites.map { |suite| _run_suite suite, type }
     end
 
     ##
@@ -909,7 +924,13 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L924
       filter = options[:filter] || '/./'
       filter = Regexp.new $1 if filter =~ /\/(.*)\//
 
-      assertions = suite.send("#{type}_methods").grep(filter).map { |method|
+      all_test_methods = suite.send "#{type}_methods"
+
+      filtered_test_methods = all_test_methods.find_all { |m|
+        filter === m || filter === "#{suite}##{m}"
+      }
+
+      assertions = filtered_test_methods.map { |method|
         inst = suite.new method
         inst._assertions = 0
 
@@ -929,7 +950,7 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L950
     end
 
     ##
-    # Record the result of a single run. Makes it very easy to gather
+    # Record the result of a single test. Makes it very easy to gather
     # information. Eg:
     #
     #   class StatisticsRecorder < MiniTest::Unit
@@ -939,6 +960,11 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L960
     #   end
     #
     #   MiniTest::Unit.runner = StatisticsRecorder.new
+    #
+    # NOTE: record might be sent more than once per test.  It will be
+    # sent once with the results from the test itself.  If there is a
+    # failure or error in teardown, it will be sent again with the
+    # error or failure.
 
     def record suite, method, assertions, time, error
     end
@@ -961,14 +987,14 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L987
           when MiniTest::Skip then
             @skips += 1
             return "S" unless @verbose
-            "Skipped:\n#{meth}(#{klass}) [#{location e}]:\n#{e.message}\n"
+            "Skipped:\n#{klass}##{meth} [#{location e}]:\n#{e.message}\n"
           when MiniTest::Assertion then
             @failures += 1
-            "Failure:\n#{meth}(#{klass}) [#{location e}]:\n#{e.message}\n"
+            "Failure:\n#{klass}##{meth} [#{location e}]:\n#{e.message}\n"
           else
             @errors += 1
             bt = MiniTest::filter_backtrace(e.backtrace).join "\n    "
-            "Error:\n#{meth}(#{klass}):\n#{e.class}: #{e.message}\n    #{bt}\n"
+            "Error:\n#{klass}##{meth}:\n#{e.class}: #{e.message}\n    #{bt}\n"
           end
       @report << e
       e[0, 1]
@@ -978,11 +1004,16 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L1004
       @report = []
       @errors = @failures = @skips = 0
       @verbose = false
-      @mutex = Mutex.new
+      @mutex = defined?(Mutex) ? Mutex.new : nil
+      @info_signal = Signal.list['INFO']
     end
 
     def synchronize # :nodoc:
-      @mutex.synchronize { yield }
+      if @mutex then
+        @mutex.synchronize { yield }
+      else
+        yield
+      end
     end
 
     def process_args args = [] # :nodoc:
@@ -1039,7 +1070,8 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L1070
     # Top level driver, controls all output and filtering.
 
     def _run args = []
-      self.options = process_args args
+      args = process_args args # ARGH!! blame test/unit process_args
+      self.options.merge! args
 
       puts "Run options: #{help}"
 
@@ -1048,7 +1080,7 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L1080
         break unless report.empty?
       end
 
-      return failures + errors if @test_count > 0 # or return nil...
+      return failures + errors if self.test_count > 0 # or return nil...
     rescue Interrupt
       abort 'Interrupted'
     end
@@ -1095,6 +1127,15 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L1127
       ##
       # Is this running on mri?
 
+      def maglev? platform = defined?(RUBY_ENGINE) && RUBY_ENGINE
+        "maglev" == platform
+      end
+
+      module_function :maglev?
+
+      ##
+      # Is this running on mri?
+
       def mri? platform = RUBY_DESCRIPTION
         /^ruby/ =~ platform
       end
@@ -1183,79 +1224,6 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L1224
       def after_teardown; end
     end
 
-    module Deprecated # :nodoc:
-
-      ##
-      # This entire module is deprecated and slated for removal on 2013-01-01.
-
-      module Hooks
-        def run_setup_hooks # :nodoc:
-          _run_hooks self.class.setup_hooks
-        end
-
-        def _run_hooks hooks # :nodoc:
-          hooks.each do |hook|
-            if hook.respond_to?(:arity) && hook.arity == 1
-              hook.call(self)
-            else
-              hook.call
-            end
-          end
-        end
-
-        def run_teardown_hooks # :nodoc:
-          _run_hooks self.class.teardown_hooks.reverse
-        end
-      end
-
-      ##
-      # This entire module is deprecated and slated for removal on 2013-01-01.
-
-      module HooksCM
-        ##
-        # Adds a block of code that will be executed before every
-        # TestCase is run.
-        #
-        # NOTE: This method is deprecated, use before/after_setup. It
-        # will be removed on 2013-01-01.
-
-        def add_setup_hook arg=nil, &block
-          warn "NOTE: MiniTest::Unit::TestCase.add_setup_hook is deprecated, use before/after_setup via a module (and call super!). It will be removed on 2013-01-01. Called from #{caller.first}"
-          hook = arg || block
-          @setup_hooks << hook
-        end
-
-        def setup_hooks # :nodoc:
-          if superclass.respond_to? :setup_hooks then
-            superclass.setup_hooks
-          else
-            []
-          end + @setup_hooks
-        end
-
-        ##
-        # Adds a block of code that will be executed after every
-        # TestCase is run.
-        #
-        # NOTE: This method is deprecated, use before/after_teardown. It
-        # will be removed on 2013-01-01.
-
-        def add_teardown_hook arg=nil, &block
-          warn "NOTE: MiniTest::Unit::TestCase#add_teardown_hook is deprecated, use before/after_teardown. It will be removed on 2013-01-01. Called from #{caller.first}"
-          hook = arg || block
-          @teardown_hooks << hook
-        end
-
-        def teardown_hooks # :nodoc:
-          if superclass.respond_to? :teardown_hooks then
-            superclass.teardown_hooks
-          else
-            []
-          end + @teardown_hooks
-        end
-      end
-    end
-
     ##
     # Subclass TestCase to create your own tests. Typically you'll want a
     # TestCase subclass per implementation class.
@@ -1264,8 +1232,6 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L1232
 
     class TestCase
       include LifecycleHooks
-      include Deprecated::Hooks
-      extend  Deprecated::HooksCM # UGH... I can't wait 'til 2013!
       include Guard
       extend Guard
 
@@ -1274,8 +1240,6 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L1240
       PASSTHROUGH_EXCEPTIONS = [NoMemoryError, SignalException,
                                 Interrupt, SystemExit] # :nodoc:
 
-      SUPPORTS_INFO_SIGNAL = Signal.list['INFO'] # :nodoc:
-
       ##
       # Runs the tests reporting the status to +runner+
 
@@ -1288,7 +1252,7 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L1252
           time = runner.start_time ? Time.now - runner.start_time : 0
           warn "Current Test: %s#%s %.2fs" % [self.class, self.__name__, time]
           runner.status $stderr
-        end if SUPPORTS_INFO_SIGNAL
+        end if runner.info_signal
 
         start_time = Time.now
 
@@ -1306,7 +1270,7 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L1270
         rescue *PASSTHROUGH_EXCEPTIONS
           raise
         rescue Exception => e
-          @passed = false
+          @passed = Skip === e
           time = Time.now - start_time
           runner.record self.class, self.__name__, self._assertions, time, e
           result = runner.puke self.class, self.__name__, e
@@ -1318,10 +1282,11 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L1282
               raise
             rescue Exception => e
               @passed = false
+              runner.record self.class, self.__name__, self._assertions, time, e
               result = runner.puke self.class, self.__name__, e
             end
           end
-          trap 'INFO', 'DEFAULT' if SUPPORTS_INFO_SIGNAL
+          trap 'INFO', 'DEFAULT' if runner.info_signal
         end
         result
       end
@@ -1332,11 +1297,11 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L1297
         @__name__ = name
         @__io__ = nil
         @passed = nil
-        @@current = self
+        @@current = self # FIX: make thread local
       end
 
       def self.current # :nodoc:
-        @@current
+        @@current # FIX: make thread local
       end
 
       ##
@@ -1392,6 +1357,8 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L1357
       # and your tests are awesome.
 
       def self.parallelize_me!
+        require "minitest/parallel_each"
+
         class << self
           undef_method :test_order if method_defined? :test_order
           define_method :test_order do :parallel end
@@ -1400,7 +1367,6 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L1367
 
       def self.inherited klass # :nodoc:
         @@test_suites[klass] = true
-        klass.reset_setup_teardown_hooks
         super
       end
 
@@ -1448,30 +1414,9 @@ module MiniTest https://github.com/ruby/ruby/blob/trunk/lib/minitest/unit.rb#L1414
 
       def teardown; end
 
-      def self.reset_setup_teardown_hooks # :nodoc:
-        # also deprecated... believe it.
-        @setup_hooks = []
-        @teardown_hooks = []
-      end
-
-      reset_setup_teardown_hooks
-
       include MiniTest::Assertions
     end # class TestCase
   end # class Unit
 end # module MiniTest
 
 Minitest = MiniTest # :nodoc: because ugh... I typo this all the time
-
-if $DEBUG then
-  module Test                # :nodoc:
-    module Unit              # :nodoc:
-      class TestCase         # :nodoc:
-        def self.inherited x # :nodoc:
-          # this helps me ferret out porting issues
-          raise "Using minitest and test/unit in the same process: #{x}"
-        end
-      end
-    end
-  end
-end
Index: lib/minitest/hell.rb
===================================================================
--- lib/minitest/hell.rb	(revision 40552)
+++ lib/minitest/hell.rb	(revision 40553)
@@ -5,12 +5,16 @@ https://github.com/ruby/ruby/blob/trunk/lib/minitest/hell.rb#L5
 # File a patch instead and assign it to Ryan Davis.
 ######################################################################
 
-class Minitest::Unit::TestCase # :nodoc:
+require "minitest/parallel_each"
+
+# :stopdoc:
+class Minitest::Unit::TestCase
   class << self
     alias :old_test_order :test_order
 
-    def test_order # :nodoc:
+    def test_order
       :parallel
     end
   end
 end
+# :startdoc:
Index: lib/minitest/README.txt
===================================================================
--- lib/minitest/README.txt	(revision 40552)
+++ lib/minitest/README.txt	(revision 40553)
@@ -104,7 +104,7 @@ Given that you'd like to test the follow https://github.com/ruby/ruby/blob/trunk/lib/minitest/README.txt#L104
     def test_that_it_will_not_blend
       refute_match /^no/i, @meme.will_it_blend?
     end
-    
+
     def test_that_will_be_skipped
       skip "test this later"
     end
@@ -221,6 +221,14 @@ Output is tab-delimited to make it easy https://github.com/ruby/ruby/blob/trunk/lib/minitest/README.txt#L221
     end
   end
 
+A note on stubbing: In order to stub a method, the method must
+actually exist prior to stubbing. Use a singleton method to create a
+new non-existing method:
+
+  def obj_under_test.fake_method
+    ...
+  end
+
 === Customizable Test Runner Types:
 
 MiniTest::Unit.runner=(runner) provides an easy way of creating custom
@@ -273,54 +281,113 @@ fixture loading: https://github.com/ruby/ruby/blob/trunk/lib/minitest/README.txt#L281
 
   MiniTest::Unit.runner = MiniTestWithTransactions::Unit.new
 
+== FAQ
+
+=== How to test SimpleDelegates?
+
+The following implementation and test:
+
+    class Worker < SimpleDelegat (... truncated)

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

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