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

ruby-changes:21733

From: ryan <ko1@a...>
Date: Fri, 18 Nov 2011 08:02:27 +0900 (JST)
Subject: [ruby-changes:21733] ryan:r33782 (trunk): Imported minitest 2.8.1

ryan	2011-11-18 08:02:16 +0900 (Fri, 18 Nov 2011)

  New Revision: 33782

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

  Log:
    Imported minitest 2.8.1

  Modified files:
    trunk/ChangeLog
    trunk/lib/minitest/README.txt
    trunk/lib/minitest/benchmark.rb
    trunk/lib/minitest/mock.rb
    trunk/lib/minitest/pride.rb
    trunk/lib/minitest/spec.rb
    trunk/lib/minitest/unit.rb
    trunk/test/minitest/test_minitest_mock.rb
    trunk/test/minitest/test_minitest_unit.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 33781)
+++ ChangeLog	(revision 33782)
@@ -1,3 +1,9 @@
+Fri Nov 18 08:00:41 2011  Ryan Davis  <ryan@l...>
+
+	* lib/minitest/*: Imported minitest 2.8.1 (r6750)
+	* test/minitest/*: ditto
+	* configure.in: Improved gcc-llvm error message to help people migrate.
+
 Thu Nov 17 20:43:34 2011  Tanaka Akira  <akr@f...>
 
 	* ext/dbm/extconf.rb: revert a part of the patch in [ruby-dev:41531].
@@ -1305,7 +1311,7 @@
 	* ext/openssl/ossl_ns_spki.c (Init_ossl_ns_spki):  Stub documentation
 	  for Netscape SPKI.
 
-Thu Oct 20 05:13:39 2011  Ryan Davis  <ryan@l...>
+Thu Oct 20 05:13:39 2011  Ryan Davis  <ryand-ruby@z...>
 
 	* lib/minitest/*: Imported minitest 2.6.2 (r6712)
 	* test/minitest/*: ditto
Index: lib/minitest/unit.rb
===================================================================
--- lib/minitest/unit.rb	(revision 33781)
+++ lib/minitest/unit.rb	(revision 33782)
@@ -14,6 +14,18 @@
 
 module MiniTest
 
+  def self.const_missing name # :nodoc:
+    case name
+    when :MINI_DIR then
+      msg = "MiniTest::MINI_DIR was removed. Don't violate other's internals."
+      warn "WAR\NING: #{msg}"
+      warn "WAR\NING: Used by #{caller.first}."
+      const_set :MINI_DIR, "bad value"
+    else
+      super
+    end
+  end
+
   ##
   # Assertion base class
 
@@ -24,22 +36,6 @@
 
   class Skip < Assertion; end
 
-  file = if RUBY_VERSION >= '1.9.0' then  # bt's expanded, but __FILE__ isn't :(
-           File.expand_path __FILE__
-         elsif  __FILE__ =~ /^[^\.]/ then # assume both relative
-           require 'pathname'
-           pwd = Pathname.new Dir.pwd
-           pn = Pathname.new File.expand_path(__FILE__)
-           relpath = pn.relative_path_from(pwd) rescue pn
-           pn = File.join ".", relpath unless pn.relative?
-           pn.to_s
-         else                             # assume both are expanded
-           __FILE__
-         end
-
-  # './lib' in project dir, or '/usr/local/blahblah' if installed
-  MINI_DIR = File.dirname(File.dirname(file)) # :nodoc:
-
   def self.filter_backtrace bt # :nodoc:
     return ["No backtrace"] unless bt
 
@@ -47,11 +43,11 @@
 
     unless $DEBUG then
       bt.each do |line|
-        break if line.rindex MINI_DIR, 0
+        break if line =~ /lib\/minitest/
         new_bt << line
       end
 
-      new_bt = bt.reject { |line| line.rindex MINI_DIR, 0 } if new_bt.empty?
+      new_bt = bt.reject { |line| line =~ /lib\/minitest/ } if new_bt.empty?
       new_bt = bt.dup if new_bt.empty?
     else
       new_bt = bt.dup
@@ -357,10 +353,9 @@
         end
       rescue Exception => e
         details = "#{msg}#{mu_pp(exp)} exception expected, not"
-        bool = exp.any? { |ex|
-          ex.instance_of?(Module) ? e.kind_of?(ex) : ex == e.class
-        }
-        assert(bool, bool ? '' : exception_details(e, details))
+        assert(exp.any? { |ex|
+                 ex.instance_of?(Module) ? e.kind_of?(ex) : ex == e.class
+               }, exception_details(e, details))
 
         return e
       end
@@ -652,7 +647,7 @@
   end
 
   class Unit
-    VERSION = "2.6.1" # :nodoc:
+    VERSION = "2.8.1" # :nodoc:
 
     attr_accessor :report, :failures, :errors, :skips # :nodoc:
     attr_accessor :test_count, :assertion_count       # :nodoc:
@@ -978,7 +973,7 @@
           @passed = nil
           self.setup
           self.run_setup_hooks
-          self.__send__ self.__name__
+          self.run_test self.__name__
           result = "." unless io?
           @passed = true
         rescue *PASSTHROUGH_EXCEPTIONS
@@ -1000,12 +995,19 @@
         result
       end
 
+      alias :run_test :__send__
+
       def initialize name # :nodoc:
         @__name__ = name
         @__io__ = nil
         @passed = nil
+        @@current = self
       end
 
+      def self.current # :nodoc:
+        @@current
+      end
+
       def io
         @__io__ = true
         MiniTest::Unit.output
@@ -1095,17 +1097,17 @@
       # The argument can be any object that responds to #call or a block.
       # That means that this call,
       #
-      #     MiniTest::TestCase.add_setup_hook { puts "foo" }
+      #     MiniTest::Unit::TestCase.add_setup_hook { puts "foo" }
       #
       # ... is equivalent to:
       #
       #     module MyTestSetup
-      #       def call
+      #       def self.call
       #         puts "foo"
       #       end
       #     end
       #
-      #     MiniTest::TestCase.add_setup_hook MyTestSetup
+      #     MiniTest::Unit::TestCase.add_setup_hook MyTestSetup
       #
       # The blocks passed to +add_setup_hook+ take an optional parameter that
       # will be the TestCase instance that is executing the block.
@@ -1144,17 +1146,17 @@
       # The argument can be any object that responds to #call or a block.
       # That means that this call,
       #
-      #     MiniTest::TestCase.add_teardown_hook { puts "foo" }
+      #     MiniTest::Unit::TestCase.add_teardown_hook { puts "foo" }
       #
       # ... is equivalent to:
       #
       #     module MyTestTeardown
-      #       def call
+      #       def self.call
       #         puts "foo"
       #       end
       #     end
       #
-      #     MiniTest::TestCase.add_teardown_hook MyTestTeardown
+      #     MiniTest::Unit::TestCase.add_teardown_hook MyTestTeardown
       #
       # The blocks passed to +add_teardown_hook+ take an optional parameter
       # that will be the TestCase instance that is executing the block.
Index: lib/minitest/pride.rb
===================================================================
--- lib/minitest/pride.rb	(revision 33781)
+++ lib/minitest/pride.rb	(revision 33782)
@@ -95,5 +95,5 @@
   end
 end
 
-klass = ENV['TERM'] =~ /^xterm(-256color)?$/ ? PrideLOL : PrideIO
+klass = ENV['TERM'] =~ /^xterm|-256color$/ ? PrideLOL : PrideIO
 MiniTest::Unit.output = klass.new(MiniTest::Unit.output)
Index: lib/minitest/README.txt
===================================================================
--- lib/minitest/README.txt	(revision 33781)
+++ lib/minitest/README.txt	(revision 33782)
@@ -129,9 +129,7 @@
     # Override self.bench_range or default range is [1, 10, 100, 1_000, 10_000]
     def bench_my_algorithm
       assert_performance_linear 0.9999 do |n| # n is a range value
-        n.times do
-          @obj.my_algorithm
-        end
+        @obj.my_algorithm(n)
       end
     end
   end
Index: lib/minitest/mock.rb
===================================================================
--- lib/minitest/mock.rb	(revision 33781)
+++ lib/minitest/mock.rb	(revision 33782)
@@ -92,7 +92,7 @@
 
       @actual_calls[sym] << {
         :retval => retval,
-        :args => expected_args.zip(args).map { |mod, a| mod if mod === a }
+        :args => expected_args.zip(args).map { |mod, a| mod === a ? mod : a }
       }
 
       retval
Index: lib/minitest/benchmark.rb
===================================================================
--- lib/minitest/benchmark.rb	(revision 33781)
+++ lib/minitest/benchmark.rb	(revision 33782)
@@ -83,8 +83,8 @@
     #
     #   def bench_algorithm
     #     validation = proc { |x, y| ... }
-    #     assert_performance validation do |x|
-    #       @obj.algorithm
+    #     assert_performance validation do |n|
+    #       @obj.algorithm(n)
     #     end
     #   end
 
@@ -127,8 +127,8 @@
     # Eg:
     #
     #   def bench_algorithm
-    #     assert_performance_constant 0.9999 do |x|
-    #       @obj.algorithm
+    #     assert_performance_constant 0.9999 do |n|
+    #       @obj.algorithm(n)
     #     end
     #   end
 
@@ -153,8 +153,8 @@
     # Eg:
     #
     #   def bench_algorithm
-    #     assert_performance_exponential 0.9999 do |x|
-    #       @obj.algorithm
+    #     assert_performance_exponential 0.9999 do |n|
+    #       @obj.algorithm(n)
     #     end
     #   end
 
@@ -173,8 +173,8 @@
     # Eg:
     #
     #   def bench_algorithm
-    #     assert_performance_linear 0.9999 do |x|
-    #       @obj.algorithm
+    #     assert_performance_linear 0.9999 do |n|
+    #       @obj.algorithm(n)
     #     end
     #   end
 
@@ -329,8 +329,8 @@
   # Create a benchmark that verifies that the performance is linear.
   #
   #   describe "my class" do
-  #     bench_performance_linear "fast_algorithm", 0.9999 do
-  #       @obj.fast_algorithm
+  #     bench_performance_linear "fast_algorithm", 0.9999 do |n|
+  #       @obj.fast_algorithm(n)
   #     end
   #   end
 
@@ -344,8 +344,8 @@
   # Create a benchmark that verifies that the performance is constant.
   #
   #   describe "my class" do
-  #     bench_performance_constant "zoom_algorithm!" do
-  #       @obj.zoom_algorithm!
+  #     bench_performance_constant "zoom_algorithm!" do |n|
+  #       @obj.zoom_algorithm!(n)
   #     end
   #   end
 
@@ -359,8 +359,8 @@
   # Create a benchmark that verifies that the performance is exponential.
   #
   #   describe "my class" do
-  #     bench_performance_exponential "algorithm" do
-  #       @obj.algorithm
+  #     bench_performance_exponential "algorithm" do |n|
+  #       @obj.algorithm(n)
   #     end
   #   end
 
Index: lib/minitest/spec.rb
===================================================================
--- lib/minitest/spec.rb	(revision 33781)
+++ lib/minitest/spec.rb	(revision 33782)
@@ -12,7 +12,7 @@
   def infect_an_assertion meth, new_name, dont_flip = false # :nodoc:
     # warn "%-22p -> %p %p" % [meth, new_name, dont_flip]
     self.class_eval <<-EOM
-      def #{new_name} *args, &block
+      def #{new_name} *args
         return MiniTest::Spec.current.#{meth}(*args, &self) if
           Proc === self
         return MiniTest::Spec.current.#{meth}(args.first, self) if
@@ -138,10 +138,6 @@
     @@describe_stack
   end
 
-  def self.current # :nodoc:
-    @@current_spec
-  end
-
   ##
   # Returns the children of this spec.
 
@@ -149,11 +145,6 @@
     @children ||= []
   end
 
-  def initialize name # :nodoc:
-    super
-    @@current_spec = self
-  end
-
   def self.nuke_test_methods! # :nodoc:
     self.public_instance_methods.grep(/^test_/).each do |name|
       self.send :undef_method, name
Index: test/minitest/test_minitest_mock.rb
===================================================================
--- test/minitest/test_minitest_mock.rb	(revision 33781)
+++ test/minitest/test_minitest_mock.rb	(revision 33782)
@@ -147,6 +147,21 @@
     util_verify_bad
   end
 
+  def test_verify_shows_the_actual_arguments_in_the_message
+    mock = MiniTest::Mock.new
+    mock.expect :capitalized, true, ["a"]
+    mock.capitalized "b"
+    e = assert_raises MockExpectationError do
+      mock.verify
+    end
+
+    a = {:retval=>true, :args=>["a"]}
+    b = {:retval=>true, :args=>["b"]}
+
+    expected = "expected capitalized, #{a.inspect}, got [#{b.inspect}]"
+    assert_equal expected, e.message
+  end
+
   def util_verify_bad
     assert_raises MockExpectationError do
       @mock.verify
Index: test/minitest/test_minitest_unit.rb
===================================================================
--- test/minitest/test_minitest_unit.rb	(revision 33781)
+++ test/minitest/test_minitest_unit.rb	(revision 33782)
@@ -6,17 +6,15 @@
 
 require 'stringio'
 require 'pathname'
-require 'minitest/unit'
+require 'minitest/autorun'
 
-MiniTest::Unit.autorun
-
 module MyModule; end
 class AnError < StandardError; include MyModule; end
 class ImmutableString < String; def inspect; super.freeze; end; end
 
 class TestMiniTestUnit < MiniTest::Unit::TestCase
   pwd = Pathname.new(File.expand_path(Dir.pwd))
-  basedir = Pathname.new(File.expand_path(MiniTest::MINI_DIR)) + 'mini'
+  basedir = Pathname.new(File.expand_path("lib/minitest")) + 'mini'
   basedir = basedir.relative_path_from(pwd).to_s
   MINITEST_BASE_DIR = basedir[/\A\./] ? basedir : "./#{basedir}"
   BT_MIDDLE = ["#{MINITEST_BASE_DIR}/test.rb:161:in `each'",
@@ -190,6 +188,38 @@
     assert_equal ex, fu
   end
 
+  def test_run_test
+    tc = Class.new(MiniTest::Unit::TestCase) do
+      attr_reader :foo
+
+      def run_test name
+        @foo = "hi mom!"
+        super
+        @foo = "okay"
+      end
+
+      def test_something
+        assert_equal "hi mom!", foo
+      end
+    end
+
+    Object.const_set(:ATestCase, tc)
+
+    @tu.run %w[--seed 42]
+
+    expected = "Run options: --seed 42
+
+# Running tests:
+
+.
+
+Finished tests in 0.00
+
+1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
+"
+    assert_report expected
+  end
+
   def test_run_error
     tc = Class.new(MiniTest::Unit::TestCase) do
       def test_something
@@ -1210,6 +1240,18 @@
     assert_equal [ATestCase], MiniTest::Unit::TestCase.test_suites
   end
 
+  def test_expectation
+    @assertion_count = 2
+
+    @tc.assert_equal true, 1.must_equal(1)
+  end
+
+  def test_expectation_triggered
+    util_assert_triggered "Expected: 2\n  Actual: 1" do
+      1.must_equal 2
+    end
+  end
+
   def test_flunk
     util_assert_triggered 'Epic Fail!' do
       @tc.flunk

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

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