From 426ddbfff5e3106db52456e2b91a23f2f1644872 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Tue, 4 Jan 2022 17:34:28 +0900 Subject: [PATCH] test/ruby/test_method.rb: Fix a random failure during `make COVERAGE=1` This fixes the following failure. ``` 1) Error: TestMethod#test_method_list: NoMethodError: undefined method `<=>' for # mods = mods.sort_by {|m| m.name } ^^^^^^^^ ``` https://github.com/ruby/actions/runs/4699487470?check_suite_focus=true TestNoMethodError#test_to_s creates an anonymous module whose `#name` method returns a BasicObject. https://github.com/ruby/ruby/blob/f0669fb6cbdbad499974252ef2d955a608d0adc1/test/ruby/test_nomethod_error.rb#L95-L99 TestMethod#test_method_list uses `ObjectSpace.each_object(Module)` to gather all Modules and attempts to sort them by `#name`. But the anonymous module returns a BasicObject, which leads to the test failure above. --- test/ruby/test_method.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index 0da69fd4e4..8f68df7b24 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -1409,7 +1409,7 @@ class TestMethod < Test::Unit::TestCase # use_symbol = Object.instance_methods[0].is_a?(Symbol) nummodule = nummethod = 0 mods = [] - ObjectSpace.each_object(Module) {|m| mods << m if m.name } + ObjectSpace.each_object(Module) {|m| mods << m if Symbol === m.name } mods = mods.sort_by {|m| m.name } mods.each {|mod| nummodule += 1