aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorJack Nagel2014-11-18 00:41:52 -0600
committerJack Nagel2014-11-18 00:41:52 -0600
commit7f230dfaf871cb3bf6cd7b3937d2cffe48ee7ae4 (patch)
treeea5f2890a12e0750d39bda6ac30038f53b073571 /Library
parent91ccd8435c6f19e9937b6aff5946e86f1eb63c05 (diff)
downloadbrew-7f230dfaf871cb3bf6cd7b3937d2cffe48ee7ae4.tar.bz2
Suppress encoding errors in test-bot log files
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cmd/test-bot.rb25
1 files changed, 20 insertions, 5 deletions
diff --git a/Library/Homebrew/cmd/test-bot.rb b/Library/Homebrew/cmd/test-bot.rb
index 78ef2b4b3..9c09b66e8 100644
--- a/Library/Homebrew/cmd/test-bot.rb
+++ b/Library/Homebrew/cmd/test-bot.rb
@@ -129,7 +129,7 @@ module Homebrew
puts_result
if File.exist?(log)
- @output = File.read(log)
+ @output = fix_encoding File.read(log)
if has_output? and (failed? or @puts_output_on_success)
puts @output
end
@@ -138,6 +138,22 @@ module Homebrew
exit 1 if ARGV.include?("--fail-fast") && @status == :failed
end
+
+ private
+
+ if String.method_defined?(:force_encoding)
+ def fix_encoding(str)
+ return str if str.valid_encoding?
+ # Assume we are starting from a "mostly" UTF-8 string
+ str.force_encoding(Encoding::UTF_8)
+ str.encode!(Encoding::UTF_16, :invalid => :replace, :undef => :replace)
+ str.encode!(Encoding::UTF_8)
+ end
+ else
+ def fix_encoding(str)
+ str
+ end
+ end
end
class Test
@@ -630,12 +646,11 @@ module Homebrew
testcase.attributes['time'] = step.time
failure = testcase.add_element 'failure' if step.failed?
if step.has_output?
- # Remove invalid XML CData characters from step output.
output = step.output
- if output.respond_to?(:force_encoding) && !output.valid_encoding?
- output.force_encoding(Encoding::UTF_8)
- end
+
+ # Remove invalid XML CData characters from step output.
output = output.delete("\000\a\b\e\f")
+
if output.bytesize > BYTES_IN_1_MEGABYTE
output = "truncated output to 1MB:\n" \
+ output.slice(-BYTES_IN_1_MEGABYTE, BYTES_IN_1_MEGABYTE)