Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop exiting with error when syntax error detected during validation #1603

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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