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

ruby-changes:58045

From: Koichi <ko1@a...>
Date: Mon, 30 Sep 2019 16:22:53 +0900 (JST)
Subject: [ruby-changes:58045] 88f38c187e (master): Emulate method_list (chkbuild) on test-all.

https://git.ruby-lang.org/ruby.git/commit/?id=88f38c187e

From 88f38c187e3171f8f351f3198247d20ea9f016ee Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Mon, 30 Sep 2019 15:36:19 +0900
Subject: Emulate method_list (chkbuild) on test-all.

chkbuild (CI process) shows methods list before
running tests and sometimes it can fails. This
commit a code part to emulate this method listing
feature.

diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb
index a141202..fe1df15 100644
--- a/test/ruby/test_method.rb
+++ b/test/ruby/test_method.rb
@@ -1169,4 +1169,45 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_method.rb#L1169
     plus = Integer.instance_method(:+)
     assert_equal(3, plus.bind_call(1, 2))
   end
+
+  def test_method_list
+    # chkbuild lists all methods.
+    # The following code emulate this listing.
+
+    use_symbol = Object.instance_methods[0].is_a?(Symbol)
+    nummodule = nummethod = 0
+    mods = []
+    ObjectSpace.each_object(Module) {|m| mods << m if m.name }
+    mods = mods.sort_by {|m| m.name }
+    mods.each {|mod|
+      nummodule += 1
+      mc = mod.kind_of?(Class) ? "class" : "module"
+      puts_line = "#{mc} #{mod.name} #{(mod.ancestors - [mod]).inspect}"
+      mod.singleton_methods(false).sort.each {|methname|
+        nummethod += 1
+        meth = mod.method(methname)
+        line = "#{mod.name}.#{methname} #{meth.arity}"
+        line << " not-implemented" if !mod.respond_to?(methname)
+        # puts line
+      }
+      ms = mod.instance_methods(false)
+      if use_symbol
+        ms << :initialize if mod.private_instance_methods(false).include? :initialize
+      else
+        ms << "initialize" if mod.private_instance_methods(false).include? "initialize"
+      end
+
+      ms.sort.each {|methname|
+        nummethod += 1
+        meth = mod.instance_method(methname)
+        line = "#{mod.name}\##{methname} #{meth.arity}"
+        line << " not-implemented" if /\(not-implemented\)/ =~ meth.inspect
+        # puts line
+      }
+    }
+    # puts "#{nummodule} modules, #{nummethod} methods"
+
+    assert nummodule > 0
+    assert nummethod > 0
+  end
 end
-- 
cgit v0.10.2


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

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