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

ruby-changes:37423

From: nobu <ko1@a...>
Date: Thu, 5 Feb 2015 11:10:49 +0900 (JST)
Subject: [ruby-changes:37423] nobu:r49504 (trunk): test_inadvertent_creation.rb: move tests

nobu	2015-02-05 11:10:44 +0900 (Thu, 05 Feb 2015)

  New Revision: 49504

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

  Log:
    test_inadvertent_creation.rb: move tests
    
    * test/-ext-/symbol/test_inadvertent_creation.rb: move symbol leak
      tests, for implementation details, from test/ruby/test_symbol.rb.

  Modified files:
    trunk/test/-ext-/symbol/test_inadvertent_creation.rb
    trunk/test/ruby/test_symbol.rb
Index: test/ruby/test_symbol.rb
===================================================================
--- test/ruby/test_symbol.rb	(revision 49503)
+++ test/ruby/test_symbol.rb	(revision 49504)
@@ -238,69 +238,4 @@ class TestSymbol < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_symbol.rb#L238
       200_000.times { |i| i.to_s.to_sym }
     end;
   end
-
-  def assert_no_immortal_symbol_created
-    delta = -Symbol.all_symbols.size
-    yield
-    GC.start
-    delta += Symbol.all_symbols.size
-    assert_equal 0, delta, "#{delta} immortal symbols were created"
-  end
-
-  def test_symbol_send_leak_string
-    assert_no_immortal_symbol_created do
-      10.times { 42.send "send should not leak #{i} - str" rescue nil }
-    end
-  end
-
-  def test_symbol_send_leak_symbol
-    assert_no_immortal_symbol_created do
-      10.times { 42.send "send should not leak #{i} - sym".to_sym rescue nil }
-    end
-  end
-
-  def test_symbol_send_leak_string_custom_method_missing
-    x = Object.new
-    def x.method_missing(*); end
-    assert_no_immortal_symbol_created do
-      10.times { |i| x.send "send should not leak #{i} - str mm" }
-    end
-  end if false
-
-  def test_symbol_send_leak_symbol_custom_method_missing
-    x = Object.new
-    def x.method_missing(*); end
-    assert_no_immortal_symbol_created do
-      10.times { |i| x.send "send should not leak #{i} - sym mm".to_sym }
-    end
-  end if false
-
-  def test_symbol_send_leak_string_no_optimization
-    assert_no_immortal_symbol_created do
-      10.times { 42.method(:send).call "send should not leak #{i} - str slow" rescue nil }
-    end
-  end
-
-  def test_symbol_send_leak_symbol_no_optimization
-    assert_no_immortal_symbol_created do
-      10.times { 42.method(:send).call "send should not leak #{i} - sym slow".to_sym rescue nil }
-    end
-  end
-
-  def test_symbol_send_leak_string_custom_method_missing_no_optimization
-    x = Object.new
-    def x.method_missing(*); end
-    assert_no_immortal_symbol_created do
-      10.times { |i| x.method(:send).call "send should not leak #{i} - str mm slow" }
-    end
-  end
-
-  def test_symbol_send_leak_symbol_custom_method_missing_no_optimization
-    x = Object.new
-    def x.method_missing(*); end
-    assert_no_immortal_symbol_created do
-      10.times { |i| x.method(:send).call "send should not leak #{i} - sym mm slow".to_sym }
-    end
-  end
-
 end
Index: test/-ext-/symbol/test_inadvertent_creation.rb
===================================================================
--- test/-ext-/symbol/test_inadvertent_creation.rb	(revision 49503)
+++ test/-ext-/symbol/test_inadvertent_creation.rb	(revision 49504)
@@ -358,5 +358,67 @@ module Test_Symbol https://github.com/ruby/ruby/blob/trunk/test/-ext-/symbol/test_inadvertent_creation.rb#L358
       }
       assert_not_pinneddown(name)
     end
+
+    def assert_no_immortal_symbol_created(name)
+      name = noninterned_name(name)
+      yield(name)
+      assert_not_pinneddown(name)
+    end
+
+    def test_send_leak_string
+      assert_no_immortal_symbol_created("send should not leak - str") do |name|
+        assert_raise(NoMethodError) {42.send(name)}
+      end
+    end
+
+    def test_send_leak_symbol
+      assert_no_immortal_symbol_created("send should not leak - sym") do |name|
+        assert_raise(NoMethodError) {42.send(name.to_sym)}
+      end
+    end
+
+    def test_send_leak_string_custom_method_missing
+      x = Object.new
+      def x.method_missing(*); end
+      assert_no_immortal_symbol_created("send should not leak - str mm") do |name|
+        assert_nothing_raised(NoMethodError) {x.send(name)}
+      end
+    end if false
+
+    def test_send_leak_symbol_custom_method_missing
+      x = Object.new
+      def x.method_missing(*); end
+      assert_no_immortal_symbol_created("send should not leak - sym mm") do |name|
+        assert_nothing_raised(NoMethodError) {x.send(name.to_sym)}
+      end
+    end if false
+
+    def test_send_leak_string_no_optimization
+      assert_no_immortal_symbol_created("send should not leak - str slow") do |name|
+        assert_raise(NoMethodError) {42.method(:send).call(name)}
+      end
+    end
+
+    def test_send_leak_symbol_no_optimization
+      assert_no_immortal_symbol_created("send should not leak - sym slow") do |name|
+        assert_raise(NoMethodError) {42.method(:send).call(name.to_sym)}
+      end
+    end
+
+    def test_send_leak_string_custom_method_missing_no_optimization
+      x = Object.new
+      def x.method_missing(*); end
+      assert_no_immortal_symbol_created("send should not leak - str mm slow") do |name|
+        assert_nothing_raised(NoMethodError) {x.method(:send).call(name)}
+      end
+    end
+
+    def test_send_leak_symbol_custom_method_missing_no_optimization
+      x = Object.new
+      def x.method_missing(*); end
+      assert_no_immortal_symbol_created("send should not leak - sym mm slow") do |name|
+        assert_nothing_raised(NoMethodError) {x.method(:send).call(name.to_sym)}
+      end
+    end
   end
 end

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

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