Permalink
Browse files

- Write aggregated_results directly to the IO object to avoid mixed e…

…ncoding errors. (tenderlove)

[git-p4: depot-paths = "//src/minitest/dev/": change = 11209]
  • Loading branch information...
1 parent 7fe4654 commit c6ba2afd90473b76d289562edd24f7d7ca8484f9 @zenspider zenspider committed Jan 13, 2017
Showing with 58 additions and 12 deletions.
  1. +19 −11 lib/minitest.rb
  2. +1 −1 test/minitest/metametameta.rb
  3. +6 −0 test/minitest/test_minitest_reporter.rb
  4. +32 −0 test/minitest/test_minitest_test.rb
View
@@ -2,6 +2,7 @@
require "thread"
require "mutex_m"
require "minitest/parallel"
+require "stringio"
##
# :include: README.rdoc
@@ -593,7 +594,7 @@ def report # :nodoc:
io.puts unless options[:verbose] # finish the dots
io.puts
io.puts statistics
- io.puts aggregated_results
+ aggregated_results io
io.puts summary
end
@@ -602,21 +603,20 @@ def statistics # :nodoc:
[total_time, count / total_time, assertions / total_time]
end
- def aggregated_results # :nodoc:
+ def aggregated_results io # :nodoc:
filtered_results = results.dup
filtered_results.reject!(&:skipped?) unless options[:verbose]
- s = filtered_results.each_with_index.map { |result, i|
- "\n%3d) %s" % [i+1, result]
- }.join("\n") + "\n"
-
- s.force_encoding(io.external_encoding) if
- ENCS and io.external_encoding and s.encoding != io.external_encoding
-
- s
+ filtered_results.each_with_index { |result, i|
+ io.puts "\n%3d) %s" % [i+1, result]
+ }
+ io.puts
+ io
end
- alias to_s aggregated_results
+ def to_s
+ aggregated_results(StringIO.new(binary_string)).string
+ end
def summary # :nodoc:
extra = ""
@@ -627,6 +627,14 @@ def summary # :nodoc:
"%d runs, %d assertions, %d failures, %d errors, %d skips%s" %
[count, assertions, failures, errors, skips, extra]
end
+
+ private
+
+ if '<3'.respond_to? :b
+ def binary_string; ''.b; end
+ else
+ def binary_string; ''.force_encoding(Encoding::ASCII_8BIT); end
+ end
end
##
@@ -25,7 +25,7 @@ class MetaMetaMetaTestCase < Minitest::Test
def run_tu_with_fresh_reporter flags = %w[--seed 42]
options = Minitest.process_args flags
- @output = StringIO.new("")
+ @output = StringIO.new("".encode('UTF-8'))
self.reporter = Minitest::CompositeReporter.new
reporter << Minitest::SummaryReporter.new(@output, options)
@@ -74,6 +74,12 @@ def skip_test
@st
end
+ def test_to_s
+ r.record passing_test
+ r.record fail_test
+ assert_match "woot", r.first.to_s
+ end
+
def test_passed_eh_empty
assert r.passed?
end
@@ -78,6 +78,38 @@ def test_filter_backtrace_unit_starts
# assert_instance_of Minitest::Unit, Minitest::Unit.runner
# end
+ def test_infectious_binary_encoding
+ @tu = Class.new Minitest::Test do
+ def test_this_is_not_ascii_assertion
+ assert_equal "ЁЁЁ", "ёёё"
+ end
+
+ def test_this_is_non_ascii_failure_message
+ fail 'ЁЁЁ'.force_encoding('ASCII-8BIT')
+ end
+ end
+
+ expected = clean <<-EOM
+ EF
+
+ Finished in 0.00
+
+ 1) Error:
+ #<Class:0xXXX>#test_this_is_non_ascii_failure_message:
+ RuntimeError: ЁЁЁ
+ FILE:LINE:in `test_this_is_non_ascii_failure_message'
+
+ 2) Failure:
+ #<Class:0xXXX>#test_this_is_not_ascii_assertion [FILE:LINE]:
+ Expected: \"ЁЁЁ\"
+ Actual: \"ёёё\"
+
+ 2 runs, 1 assertions, 1 failures, 1 errors, 0 skips
+ EOM
+
+ assert_report expected
+ end
+
def test_passed_eh_teardown_good
test_class = Class.new FakeNamedTest do
def teardown; assert true; end

0 comments on commit c6ba2af

Please sign in to comment.