diff options
author | TSUYUSATO Kitsune <make.just.on@gmail.com> | 2023-05-24 01:16:32 +0900 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-05-23 16:16:37 +0000 |
commit | 92d6c9a7b1c3f8462e91e9b7de04b0b2012d54b3 (patch) | |
tree | 0d4602bac1eb5cb4428f08c71472aece73a77b97 /test/irb/test_cmd.rb | |
parent | 24a6609ccb21af186d1cb73258abddb82e28a9f2 (diff) | |
download | ruby-92d6c9a7b1c3f8462e91e9b7de04b0b2012d54b3.tar.gz |
[ruby/irb] Allow `show_source` for private methods
(https://github.com/ruby/irb/pull/589)
* Allow `show_source` for private methods
Fix https://github.com/ruby/irb/pull/577
* Pend tests on TruffleRuby
It seems `eval(..., __LINE__ + 1)` does not work.
Other similar tests are also pended on TruffleRuby, so I think it
is acceptable.
* Use `private_method_defined?` instead of `defined?`
Diffstat (limited to 'test/irb/test_cmd.rb')
-rw-r--r-- | test/irb/test_cmd.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/irb/test_cmd.rb b/test/irb/test_cmd.rb index c5d9a0e544..448f42587a 100644 --- a/test/irb/test_cmd.rb +++ b/test/irb/test_cmd.rb @@ -488,6 +488,47 @@ module TestIRB assert_empty err assert_include(out, code) end + + def test_show_source_private_instance + pend if RUBY_ENGINE == 'truffleruby' + eval(code = <<-EOS, binding, __FILE__, __LINE__ + 1) + class PrivateInstanceTest + private def show_source_test_method + unless true + end + end unless private_method_defined?(:show_source_test_method) + end + EOS + + out, err = execute_lines( + "show_source '#{self.class.name}::PrivateInstanceTest#show_source_test_method'\n", + ) + + assert_empty err + assert_include(out, code.lines[1..-2].join) + end + + + def test_show_source_private + pend if RUBY_ENGINE == 'truffleruby' + eval(code = <<-EOS, binding, __FILE__, __LINE__ + 1) + class PrivateTest + private def show_source_test_method + unless true + end + end unless private_method_defined?(:show_source_test_method) + end + + Instance = PrivateTest.new unless defined?(Instance) + EOS + + out, err = execute_lines( + "show_source '#{self.class.name}::Instance.show_source_test_method'\n", + ) + + assert_empty err + assert_include(out, code.lines[1..-4].join) + end end class WorkspaceCommandTestCase < CommandTestCase |