readall: fail on Ruby syntax warnings

Previously, syntax warnings were printed, but didn't cause `readall` to
exit with a non-zero exit code. Now they do, making it easier to catch
accidentally introduced syntax warnings in the test bot.
This commit is contained in:
Martin Afanasjew 2016-04-20 01:18:40 +02:00
parent cbc24a715c
commit a61829da46

View File

@ -22,7 +22,8 @@ module Homebrew
Thread.new do Thread.new do
begin begin
while rb = ruby_files.pop(true) while rb = ruby_files.pop(true)
failed = true unless system RUBY_PATH, "-c", "-w", rb # As a side effect, print syntax errors/warnings to `$stderr`.
failed = true if syntax_errors_or_warnings?(rb)
end end
rescue ThreadError # ignore empty queue error rescue ThreadError # ignore empty queue error
end end
@ -69,4 +70,17 @@ module Homebrew
end end
end end
end end
private
def syntax_errors_or_warnings?(rb)
# Retrieve messages about syntax errors/warnings printed to `$stderr`, but
# discard a `Syntax OK` printed to `$stdout` (in absence of syntax errors).
messages = Utils.popen_read("#{RUBY_PATH} -c -w #{rb} 2>&1 >/dev/null")
$stderr.print messages
# Only syntax errors result in a non-zero status code. To detect syntax
# warnings we also need to inspect the output to `$stderr`.
!$?.success? || !messages.chomp.empty?
end
end end