Skip to content

Commit 8e50764

Browse files
committed
Handle new eval source location
See https://bugs.ruby-lang.org/issues/19755 In Ruby 3.3, using `eval` without providing a source location will now default to `"(eval at #{__FILE__}:#{__LINE__})"`.
1 parent 9cb278c commit 8e50764

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## HEAD (unreleased)
22

3+
- Handle Ruby 3.3 new eval source location format (https://github.com/ruby/syntax_suggest/pull/200).
4+
35
## 1.1.0
46

57
- Handle if/else with comment or empty line in branch (https://github.com/ruby/syntax_suggest/pull/193)

lib/syntax_suggest/pathname_from_message.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module SyntaxSuggest
1313
# # => "/tmp/scratch.rb"
1414
#
1515
class PathnameFromMessage
16-
EVAL_RE = /^\(eval\):\d+/
16+
EVAL_RE = /^\(eval.*\):\d+/
1717
STREAMING_RE = /^-:\d+/
1818
attr_reader :name
1919

spec/integration/ruby_command_line_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class Dog
167167
out = `#{ruby} -I#{lib_dir} -rsyntax_suggest #{script} 2>&1`
168168

169169
expect($?.success?).to be_falsey
170-
expect(out).to include("(eval):1")
170+
expect(out).to match(/\(eval.*\):1/)
171171

172172
expect(out).to_not include("SyntaxSuggest")
173173
expect(out).to_not include("Could not find filename")

spec/unit/pathname_from_message_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ module SyntaxSuggest
4343
expect(file).to be_falsey
4444
end
4545

46+
it "does not output error message on syntax error inside of an (eval at __FILE__:__LINE__)" do
47+
message = "(eval at #{__FILE__}:#{__LINE__}):1: invalid multibyte char (UTF-8) (SyntaxError)\n"
48+
io = StringIO.new
49+
file = PathnameFromMessage.new(message, io: io).call.name
50+
51+
expect(io.string).to eq("")
52+
expect(file).to be_falsey
53+
end
54+
4655
it "does not output error message on syntax error inside of streamed code" do
4756
# An example of streamed code is: $ echo "def foo" | ruby
4857
message = "-:1: syntax error, unexpected end-of-input\n"

0 commit comments

Comments
 (0)