aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMartin Afanasjew2016-04-20 01:18:40 +0200
committerMartin Afanasjew2016-04-22 00:47:43 +0200
commita61829da467a80d7720d2a40b16141552e1af71e (patch)
treedb7c82829320d73a3663c7276935a7c2a973d4fb /Library
parentcbc24a715c512d53b40a06cce1c4e49e95a9f140 (diff)
downloadbrew-a61829da467a80d7720d2a40b16141552e1af71e.tar.bz2
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.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cmd/readall.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/Library/Homebrew/cmd/readall.rb b/Library/Homebrew/cmd/readall.rb
index 339819f0d..f95b7be74 100644
--- a/Library/Homebrew/cmd/readall.rb
+++ b/Library/Homebrew/cmd/readall.rb
@@ -22,7 +22,8 @@ module Homebrew
Thread.new do
begin
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
rescue ThreadError # ignore empty queue error
end
@@ -69,4 +70,17 @@ module Homebrew
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