1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
`Binding#source_location` returns the `__FILE__` when created, and
may not be an absolute or real path.  And in the `eval` context
with an explicit file name, `__dir__` also returns that name.
On the other hand, `__FILE__` in `require`d script file has been
expanded at searching the library.
This commit is contained in:
Nobuyoshi Nakada 2020-01-09 10:13:08 +09:00
parent d254d5563e
commit b369f5e8a2
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60

View file

@ -790,7 +790,9 @@ class TestMethod < Test::Unit::TestCase
assert_instance_of String, __dir__
assert_equal(File.dirname(File.realpath(__FILE__)), __dir__)
bug8436 = '[ruby-core:55123] [Bug #8436]'
assert_equal(__dir__, eval("__dir__", binding, *binding.source_location), bug8436)
file, line = *binding.source_location
file = File.realpath(file)
assert_equal(__dir__, eval("__dir__", binding, file, line), bug8436)
bug8662 = '[ruby-core:56099] [Bug #8662]'
assert_equal("arbitrary", eval("__dir__", binding, "arbitrary/file.rb"), bug8662)
assert_equal("arbitrary", Object.new.instance_eval("__dir__", "arbitrary/file.rb"), bug8662)