Skip to content

Commit

Permalink
Merge pull request #1603 from ruby/non-error-exit-on-syntax-error
Browse files Browse the repository at this point in the history
Stop exiting with error when syntax error detected during validation
  • Loading branch information
soutaro authored Nov 9, 2023
2 parents cc9e876 + 1290a86 commit b9c033a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/rbs/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ def run_method(args, options)

def run_validate(args, options)
stdout = stdout()
exit_error = false

OptionParser.new do |opts|
opts.banner = <<EOU
Expand All @@ -460,6 +461,9 @@ def run_validate(args, options)
opts.on("--silent") do
stdout = StringIO.new
end
opts.on("--[no-]exit-error-on-syntax-error", "exit(1) if syntax error is detected") {|bool|
exit_error = bool
}
end.parse!(args)

loader = options.loader()
Expand Down Expand Up @@ -632,7 +636,7 @@ def run_validate(args, options)
syntax_errors.each do |message|
self.stdout.puts message
end
exit(1)
exit 1 if exit_error
end
end

Expand Down
10 changes: 7 additions & 3 deletions test/rbs/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,16 @@ class Foo
with_cli do |cli|
Dir.mktmpdir do |dir|
(Pathname(dir) + 'a.rbs').write(rbs)
assert_raises SystemExit do
cli.run(["-I", dir, "validate"])
end

cli.run(["-I", dir, "validate"])

last_lines = stdout.string.lines.last(3)
assert_match(/void|self|instance|class/, last_lines.join("\n"))

cli.run(["-I", dir, "validate", "--no-exit-error-on-syntax-error"])
assert_raises SystemExit do
cli.run(["-I", dir, "validate", "--exit-error-on-syntax-error"])
end
end
end
end
Expand Down

0 comments on commit b9c033a

Please sign in to comment.