diff options
author | Nobuyoshi Nakada <[email protected]> | 2022-11-20 22:59:52 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2022-12-01 17:05:41 +0900 |
commit | 4e68b594314760611d0926c3de70a4cad26802cd (patch) | |
tree | 58254a7288d2402fbe5baa41426a8e8c4d027470 /test/ruby/test_exception.rb | |
parent | 5752d11f1f33d277356373da749db111e03c96b5 (diff) |
[Feature #19138] Add `SyntaxError#path`
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6779
Diffstat (limited to 'test/ruby/test_exception.rb')
-rw-r--r-- | test/ruby/test_exception.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 36f778975b..9bed2c76cd 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -1487,4 +1487,27 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status| end end end + + def test_syntax_error_path + e = assert_raise(SyntaxError) { + eval("1+", nil, "test_syntax_error_path.rb") + } + assert_equal("test_syntax_error_path.rb", e.path) + + Dir.mktmpdir do |dir| + lib = File.join(dir, "syntax_error-path.rb") + File.write(lib, "#{<<~"begin;"}\n#{<<~'end;'}") + begin; + class SyntaxError + def detailed_message(**) + STDERR.puts "\n""path=#{path}\n" + super + end + end + end; + main = File.join(dir, "syntax_error.rb") + File.write(main, "1+\n") + assert_in_out_err(%W[-r#{lib} #{main}], "", [], [:*, "\n""path=#{main}\n", :*]) + end + end end |