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

ruby-changes:36233

From: nobu <ko1@a...>
Date: Fri, 7 Nov 2014 21:08:40 +0900 (JST)
Subject: [ruby-changes:36233] nobu:r48314 (trunk): test_exception.rb: more tests

nobu	2014-11-07 21:08:24 +0900 (Fri, 07 Nov 2014)

  New Revision: 48314

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

  Log:
    test_exception.rb: more tests
    
    * test/ruby/test_exception.rb: more tests for catch and throw.
      catch but no throw, autogenerated tag, and uncaught throw.

  Modified files:
    trunk/test/lib/test/unit/assertions.rb
    trunk/test/ruby/test_exception.rb
Index: test/ruby/test_exception.rb
===================================================================
--- test/ruby/test_exception.rb	(revision 48313)
+++ test/ruby/test_exception.rb	(revision 48314)
@@ -129,18 +129,42 @@ class TestException < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L129
     assert(!bad)
   end
 
+  def test_catch_no_throw
+    assert_equal(:foo, catch {:foo})
+  end
+
   def test_catch_throw
-    assert(catch(:foo) {
-             loop do
-               loop do
-                 throw :foo, true
-                 break
-               end
-               break
-               assert(false)			# should no reach here
-             end
-             false
-           })
+    result = catch(:foo) {
+      loop do
+        loop do
+          throw :foo, true
+          break
+        end
+        assert(false, "should no reach here")
+      end
+      false
+    }
+    assert(result)
+  end
+
+  def test_catch_throw_noarg
+    assert_nothing_raised(ArgumentError) {
+      result = catch {|obj|
+        throw obj, :ok
+        assert(false, "should no reach here")
+      }
+      assert_equal(:ok, result)
+    }
+  end
+
+  def test_uncaught_throw
+    assert_raise_with_message(ArgumentError, /uncaught throw/) {
+      catch("foo") {|obj|
+        throw obj.dup, :ok
+        assert(false, "should no reach here")
+      }
+      assert(false, "should no reach here")
+    }
   end
 
   def test_catch_throw_in_require
@@ -148,7 +172,7 @@ class TestException < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L172
     Tempfile.create(["dep", ".rb"]) {|t|
       t.puts("throw :extdep, 42")
       t.close
-      assert_equal(42, catch(:extdep) {require t.path}, bug7185)
+      assert_equal(42, assert_throw(:extdep, bug7185) {require t.path}, bug7185)
     }
   end
 
Index: test/lib/test/unit/assertions.rb
===================================================================
--- test/lib/test/unit/assertions.rb	(revision 48313)
+++ test/lib/test/unit/assertions.rb	(revision 48314)
@@ -228,7 +228,7 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit/assertions.rb#L228
           end
           msg = message(msg) {
             "Expected #{mu_pp(tag)} to have been thrown"\
-            "#{", not #{thrown}" if thrown}"
+            "#{%Q[, not #{thrown}] if thrown}"
           }
           assert(false, msg)
         end

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

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