diff options
| author | Jean Boussier <byroot@ruby-lang.org> | 2023-07-13 11:49:28 +0200 |
|---|---|---|
| committer | Jean Boussier <jean.boussier@gmail.com> | 2023-07-24 14:51:20 +0200 |
| commit | 43a5c191358699fe8b19314763998cb8ca77ed90 (patch) | |
| tree | efebe1570ca2c77a66bfb81edeb3f86044e63174 /test/ruby/test_eval.rb | |
| parent | 14d16bdb1ad8e98d76ec2c43b2c1c412ff707d0b (diff) | |
Use the caller location as default filename for eval family of methods
[Feature #19755]
Before (in /tmp/test.rb):
```ruby
Object.class_eval("p __FILE__") # => "(eval)"
```
After:
```ruby
Object.class_eval("p __FILE__") # => "(eval at /tmp/test.rb:1)"
```
This makes it much easier to track down generated code in case
the author forgot to provide a filename argument.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/8070
Diffstat (limited to 'test/ruby/test_eval.rb')
| -rw-r--r-- | test/ruby/test_eval.rb | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/test/ruby/test_eval.rb b/test/ruby/test_eval.rb index af255c05c8..082d1dc03c 100644 --- a/test/ruby/test_eval.rb +++ b/test/ruby/test_eval.rb @@ -547,8 +547,8 @@ class TestEval < Test::Unit::TestCase end def test_eval_location_binding - assert_equal(['(eval)', 1], eval("[__FILE__, __LINE__]", nil)) - assert_equal(['(eval)', 1], eval("[__FILE__, __LINE__]", binding)) + assert_equal(["(eval at #{__FILE__}:#{__LINE__})", 1], eval("[__FILE__, __LINE__]", nil)) + assert_equal(["(eval at #{__FILE__}:#{__LINE__})", 1], eval("[__FILE__, __LINE__]", binding)) assert_equal(['foo', 1], eval("[__FILE__, __LINE__]", nil, 'foo')) assert_equal(['foo', 1], eval("[__FILE__, __LINE__]", binding, 'foo')) assert_equal(['foo', 2], eval("[__FILE__, __LINE__]", nil, 'foo', 2)) |
