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

ruby-changes:9095

From: akr <ko1@a...>
Date: Thu, 11 Dec 2008 19:40:48 +0900 (JST)
Subject: [ruby-changes:9095] Ruby:r20632 (trunk): * lib/test/unit/assertions.rb: extracted from lib/test/unit.rb.

akr	2008-12-11 19:40:24 +0900 (Thu, 11 Dec 2008)

  New Revision: 20632

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

  Log:
    * lib/test/unit/assertions.rb: extracted from lib/test/unit.rb.
      lib/test/unit/testcase.rb: ditto.
      at asakusa.rb.  [ruby-core:20014]

  Added directories:
    trunk/lib/test/unit/
  Added files:
    trunk/lib/test/unit/assertions.rb
    trunk/lib/test/unit/testcase.rb
  Modified files:
    trunk/ChangeLog
    trunk/lib/test/unit.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 20631)
+++ ChangeLog	(revision 20632)
@@ -1,3 +1,9 @@
+Thu Dec 11 19:31:45 2008  Tanaka Akira  <akr@f...>
+
+	* lib/test/unit/assertions.rb: extracted from lib/test/unit.rb.
+	  lib/test/unit/testcase.rb: ditto.
+	  at asakusa.rb.  [ruby-core:20014]
+
 Thu Dec 11 19:23:09 2008  Tanaka Akira  <akr@f...>
 
 	* test/ruby/test_io.rb (test_dup_many): extracted from test_dup.
Index: lib/test/unit/assertions.rb
===================================================================
--- lib/test/unit/assertions.rb	(revision 0)
+++ lib/test/unit/assertions.rb	(revision 20632)
@@ -0,0 +1,110 @@
+require 'minitest/unit'
+require 'pp'
+
+module Test
+  module Unit
+    module Assertions
+      include MiniTest::Assertions
+
+      def mu_pp(obj)
+        obj.pretty_inspect.chomp
+      end
+
+      def assert_raise(*args, &b)
+        assert_raises(*args, &b)
+      end
+
+      def assert_nothing_raised(*args)
+        if Module === args.last
+          msg = nil
+        else
+          msg = args.pop
+        end
+        begin
+          yield
+        rescue Exception => e
+          if ((args.empty? && !e.instance_of?(MiniTest::Assertion)) ||
+              args.any? {|a| a.instance_of?(Module) ? e.is_a?(a) : e.class == a })
+            msg = message(msg) { "Exception raised:\n<#{mu_pp(e)}>" }
+            raise MiniTest::Assertion, msg.call, e.backtrace
+          else
+            raise
+          end
+        end
+        nil
+      end
+
+      def assert_nothing_thrown(msg=nil)
+        begin
+          yield
+        rescue ArgumentError => error
+          raise error if /\Auncaught throw (.+)\z/m !~ error.message
+          msg = message(msg) { "<#{$1}> was thrown when nothing was expected" }
+          flunk(msg)
+        end
+        assert(true, "Expected nothing to be thrown")
+      end
+
+      def assert_equal(exp, act, msg = nil)
+        msg = message(msg) {
+          exp_str = mu_pp(exp)
+          act_str = mu_pp(act)
+          exp_comment = ''
+          act_comment = ''
+          if exp_str == act_str
+            if exp.is_a?(String) && act.is_a?(String)
+              exp_comment = " (#{exp.encoding})"
+              act_comment = " (#{act.encoding})"
+            elsif exp.is_a?(Time) && act.is_a?(Time)
+              exp_comment = " (nsec=#{exp.nsec})"
+              act_comment = " (nsec=#{act.nsec})"
+            end
+          elsif !Encoding.compatible?(exp_str, act_str)
+            if exp.is_a?(String) && act.is_a?(String)
+              exp_str = exp.dump
+              act_str = act.dump
+              exp_comment = " (#{exp.encoding})"
+              act_comment = " (#{act.encoding})"
+            else
+              exp_str = exp_str.dump
+              act_str = act_str.dump
+            end
+          end
+          "<#{exp_str}>#{exp_comment} expected but was\n<#{act_str}>#{act_comment}"
+        }
+        assert(exp == act, msg)
+      end
+
+      def assert_not_nil(exp, msg=nil)
+        msg = message(msg) { "<#{mu_pp(exp)}> expected to not be nil" }
+        assert(!exp.nil?, msg)
+      end
+
+      def assert_not_equal(exp, act, msg=nil)
+        msg = message(msg) { "<#{mu_pp(exp)}> expected to be != to\n<#{mu_pp(act)}>" }
+        assert(exp != act, msg)
+      end
+
+      def assert_no_match(regexp, string, msg=nil)
+        assert_instance_of(Regexp, regexp, "The first argument to assert_no_match should be a Regexp.")
+        msg = message(msg) { "<#{mu_pp(regexp)}> expected to not match\n<#{mu_pp(string)}>" }
+        assert(regexp !~ string, msg)
+      end
+
+      def assert_not_same(expected, actual, message="")
+        msg = message(msg) { build_message(message, <<EOT, expected, expected.__id__, actual, actual.__id__) }
+<?>
+with id <?> expected to not be equal\\? to
+<?>
+with id <?>.
+EOT
+        assert(!actual.equal?(expected), msg)
+      end
+
+      def build_message(head, template=nil, *arguments)
+        template &&= template.chomp
+        template.gsub(/\?/) { mu_pp(arguments.shift) }
+      end
+    end
+  end
+end
Index: lib/test/unit/testcase.rb
===================================================================
--- lib/test/unit/testcase.rb	(revision 0)
+++ lib/test/unit/testcase.rb	(revision 20632)
@@ -0,0 +1,12 @@
+require 'test/unit/assertions'
+
+module Test
+  module Unit
+    class TestCase < MiniTest::Unit::TestCase
+      include Assertions
+      def self.test_order
+        :sorted
+      end
+    end
+  end
+end
Index: lib/test/unit.rb
===================================================================
--- lib/test/unit.rb	(revision 20631)
+++ lib/test/unit.rb	(revision 20632)
@@ -1,7 +1,8 @@
 # test/unit compatibility layer using minitest.
 
 require 'minitest/unit'
-require 'pp'
+require 'test/unit/assertions'
+require 'test/unit/testcase'
 
 module Test
   module Unit
@@ -58,117 +59,6 @@
 
       ARGV.replace minitest_argv
     end
-
-    module Assertions
-      include MiniTest::Assertions
-
-      def mu_pp(obj)
-        obj.pretty_inspect.chomp
-      end
-
-      def assert_raise(*args, &b)
-        assert_raises(*args, &b)
-      end
-
-      def assert_nothing_raised(*args)
-        if Module === args.last
-          msg = nil
-        else
-          msg = args.pop
-        end
-        begin
-          yield
-        rescue Exception => e
-          if ((args.empty? && !e.instance_of?(MiniTest::Assertion)) ||
-              args.any? {|a| a.instance_of?(Module) ? e.is_a?(a) : e.class == a })
-            msg = message(msg) { "Exception raised:\n<#{mu_pp(e)}>" }
-            raise MiniTest::Assertion, msg.call, e.backtrace
-          else
-            raise
-          end
-        end
-        nil
-      end
-
-      def assert_nothing_thrown(msg=nil)
-        begin
-          yield
-        rescue ArgumentError => error
-          raise error if /\Auncaught throw (.+)\z/m !~ error.message
-          msg = message(msg) { "<#{$1}> was thrown when nothing was expected" }
-          flunk(msg)
-        end
-        assert(true, "Expected nothing to be thrown")
-      end
-
-      def assert_equal(exp, act, msg = nil)
-        msg = message(msg) {
-          exp_str = mu_pp(exp)
-          act_str = mu_pp(act)
-          exp_comment = ''
-          act_comment = ''
-          if exp_str == act_str
-            if exp.is_a?(String) && act.is_a?(String)
-              exp_comment = " (#{exp.encoding})"
-              act_comment = " (#{act.encoding})"
-            elsif exp.is_a?(Time) && act.is_a?(Time)
-              exp_comment = " (nsec=#{exp.nsec})"
-              act_comment = " (nsec=#{act.nsec})"
-            end
-          elsif !Encoding.compatible?(exp_str, act_str)
-            if exp.is_a?(String) && act.is_a?(String)
-              exp_str = exp.dump
-              act_str = act.dump
-              exp_comment = " (#{exp.encoding})"
-              act_comment = " (#{act.encoding})"
-            else
-              exp_str = exp_str.dump
-              act_str = act_str.dump
-            end
-          end
-          "<#{exp_str}>#{exp_comment} expected but was\n<#{act_str}>#{act_comment}"
-        }
-        assert(exp == act, msg)
-      end
-
-      def assert_not_nil(exp, msg=nil)
-        msg = message(msg) { "<#{mu_pp(exp)}> expected to not be nil" }
-        assert(!exp.nil?, msg)
-      end
-
-      def assert_not_equal(exp, act, msg=nil)
-        msg = message(msg) { "<#{mu_pp(exp)}> expected to be != to\n<#{mu_pp(act)}>" }
-        assert(exp != act, msg)
-      end
-
-      def assert_no_match(regexp, string, msg=nil)
-        assert_instance_of(Regexp, regexp, "The first argument to assert_no_match should be a Regexp.")
-        msg = message(msg) { "<#{mu_pp(regexp)}> expected to not match\n<#{mu_pp(string)}>" }
-        assert(regexp !~ string, msg)
-      end
-
-      def assert_not_same(expected, actual, message="")
-        msg = message(msg) { build_message(message, <<EOT, expected, expected.__id__, actual, actual.__id__) }
-<?>
-with id <?> expected to not be equal\\? to
-<?>
-with id <?>.
-EOT
-        assert(!actual.equal?(expected), msg)
-      end
-
-      def build_message(head, template=nil, *arguments)
-        template &&= template.chomp
-        template.gsub(/\?/) { mu_pp(arguments.shift) }
-      end
-    end
-
-    class TestCase < MiniTest::Unit::TestCase
-      include Assertions
-      def self.test_order
-        :sorted
-      end
-    end
   end
 end
 

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

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