1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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 #<BasicObject:0x00007f7757e7eb60>

      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.

f0669fb6cb/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.
This commit is contained in:
Yusuke Endoh 2022-01-04 17:34:28 +09:00
parent 47bf64a26d
commit 426ddbfff5

View file

@ -1409,7 +1409,7 @@ class TestMethod < Test::Unit::TestCase
# use_symbol = Object.instance_methods[0].is_a?(Symbol) # use_symbol = Object.instance_methods[0].is_a?(Symbol)
nummodule = nummethod = 0 nummodule = nummethod = 0
mods = [] 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 = mods.sort_by {|m| m.name }
mods.each {|mod| mods.each {|mod|
nummodule += 1 nummodule += 1