From a61829da467a80d7720d2a40b16141552e1af71e Mon Sep 17 00:00:00 2001 From: Martin Afanasjew Date: Wed, 20 Apr 2016 01:18:40 +0200 Subject: [PATCH] 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. --- Library/Homebrew/cmd/readall.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/readall.rb b/Library/Homebrew/cmd/readall.rb index 339819f0d0..f95b7be747 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