summaryrefslogtreecommitdiff
path: root/test/ruby/test_exception.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-11-20 22:59:52 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-12-01 17:05:41 +0900
commit4e68b594314760611d0926c3de70a4cad26802cd (patch)
tree58254a7288d2402fbe5baa41426a8e8c4d027470 /test/ruby/test_exception.rb
parent5752d11f1f33d277356373da749db111e03c96b5 (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.rb23
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