diff options
author | Jeremy Evans <code@jeremyevans.net> | 2021-05-21 11:01:06 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2021-07-29 13:51:03 -0700 |
commit | 64ac984129a7a4645efe5ac57c168ef880b479b2 (patch) | |
tree | 3d5aa171e3e63e39b9b8d4ab4425d01894880f02 /spec/ruby/core/thread/backtrace/location | |
parent | 6998d758248d778fa95b008c78d05473e48b8428 (diff) |
Make RubyVM::AbstractSyntaxTree.of raise for method/proc created in eval
This changes Thread::Location::Backtrace#absolute_path to return
nil for methods/procs defined in eval. If the realpath of an iseq
is nil, that indicates it was defined in eval, in which case you
cannot use RubyVM::AbstractSyntaxTree.of.
Fixes [Bug #16983]
Co-authored-by: Koichi Sasada <ko1@atdot.net>
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4519
Diffstat (limited to 'spec/ruby/core/thread/backtrace/location')
-rw-r--r-- | spec/ruby/core/thread/backtrace/location/absolute_path_spec.rb | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/spec/ruby/core/thread/backtrace/location/absolute_path_spec.rb b/spec/ruby/core/thread/backtrace/location/absolute_path_spec.rb index b0ae28beee..4136f09348 100644 --- a/spec/ruby/core/thread/backtrace/location/absolute_path_spec.rb +++ b/spec/ruby/core/thread/backtrace/location/absolute_path_spec.rb @@ -18,10 +18,20 @@ describe 'Thread::Backtrace::Location#absolute_path' do end context "when used in eval with a given filename" do - it "returns filename" do - code = "caller_locations(0)[0].absolute_path" - eval(code, nil, "foo.rb").should == "foo.rb" - eval(code, nil, "foo/bar.rb").should == "foo/bar.rb" + code = "caller_locations(0)[0].absolute_path" + + ruby_version_is ""..."3.1" do + it "returns filename with absolute_path" do + eval(code, nil, "foo.rb").should == "foo.rb" + eval(code, nil, "foo/bar.rb").should == "foo/bar.rb" + end + end + + ruby_version_is "3.1" do + it "returns nil with absolute_path" do + eval(code, nil, "foo.rb").should == nil + eval(code, nil, "foo/bar.rb").should == nil + end end end |