Skip to content

Commit 871663c

Browse files
andrykonchineregon
authored andcommitted
Don't rely in specs on SyntaxError message - only on class name
Prism emits different error and warning messages
1 parent 0ae1fd1 commit 871663c

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

command_line/dash_r_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
out = ruby_exe(fixture(__FILE__, "bad_syntax.rb"), options: "-r #{@test_file}", args: "2>&1", exit_status: 1)
1717
$?.should_not.success?
1818
out.should include("REQUIRED")
19-
out.should include("syntax error")
19+
20+
# it's tempting not to rely on error message and rely only on exception class name,
21+
# but CRuby before 3.2 doesn't print class name for syntax error
22+
out.should include_any_of("syntax error", "SyntaxError")
2023
end
2124

2225
it "does not require the file if the main script file does not exist" do

command_line/syntax_error_spec.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
describe "The interpreter" do
44
it "prints an error when given a file with invalid syntax" do
55
out = ruby_exe(fixture(__FILE__, "bad_syntax.rb"), args: "2>&1", exit_status: 1)
6-
out.should include "syntax error"
6+
7+
# it's tempting not to rely on error message and rely only on exception class name,
8+
# but CRuby before 3.2 doesn't print class name for syntax error
9+
out.should include_any_of("syntax error", "SyntaxError")
710
end
811

912
it "prints an error when given code via -e with invalid syntax" do
1013
out = ruby_exe(nil, args: "-e 'a{' 2>&1", exit_status: 1)
11-
out.should include "syntax error"
14+
15+
# it's tempting not to rely on error message and rely only on exception class name,
16+
# but CRuby before 3.2 doesn't print class name for syntax error
17+
out.should include_any_of("syntax error", "SyntaxError")
1218
end
1319
end

shared/kernel/at_exit.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@
5454
result = ruby_exe('{', options: "-r#{script}", args: "2>&1", exit_status: 1)
5555
$?.should_not.success?
5656
result.should.include?("handler ran\n")
57-
result.should.include?("SyntaxError")
57+
58+
# it's tempting not to rely on error message and rely only on exception class name,
59+
# but CRuby before 3.2 doesn't print class name for syntax error
60+
result.should include_any_of("syntax error", "SyntaxError")
5861
end
5962

6063
it "calls the nested handler right after the outer one if a handler is nested into another handler" do

0 commit comments

Comments
 (0)