diff --git a/test/lib/envutil.rb b/test/lib/envutil.rb index 1e0cf61b95..723bfdda06 100644 --- a/test/lib/envutil.rb +++ b/test/lib/envutil.rb @@ -351,22 +351,19 @@ module Test raise "test_stderr ignored, use block only or without block" if test_stderr != [] yield(stdout.lines.map {|l| l.chomp }, stderr.lines.map {|l| l.chomp }, status) else - errs = [] - [[test_stdout, stdout], [test_stderr, stderr]].each do |exp, act| - begin - if exp.is_a?(Regexp) - assert_match(exp, act, message) - elsif exp.all? {|e| String === e} - assert_equal(exp, act.lines.map {|l| l.chomp }, message) - else - assert_pattern_list(exp, act, message) + all_assertions(message) do |a| + [["stdout", test_stdout, stdout], ["stderr", test_stderr, stderr]].each do |key, exp, act| + a.for(key) do + if exp.is_a?(Regexp) + assert_match(exp, act) + elsif exp.all? {|e| String === e} + assert_equal(exp, act.lines.map {|l| l.chomp }) + else + assert_pattern_list(exp, act) + end end - rescue MiniTest::Assertion => e - errs << e.message - message = nil end end - raise MiniTest::Assertion, errs.join("\n---\n") unless errs.empty? status end end diff --git a/test/lib/test/unit/assertions.rb b/test/lib/test/unit/assertions.rb index 727c54c9d5..6c36c4e8c5 100644 --- a/test/lib/test/unit/assertions.rb +++ b/test/lib/test/unit/assertions.rb @@ -442,6 +442,28 @@ EOT assert(failed.empty?, message(m) {failed.pretty_inspect}) end + class AllFailures + attr_reader :failures + + def initialize + @failures = {} + end + + def for(key) + yield + rescue Exception => e + @failures[key] = e + end + end + + def all_assertions(msg = nil) + all = AllFailures.new + yield all + ensure + failures = all.failures + assert(failures.empty?, message(msg) {mu_pp(failures)}) + end + def build_message(head, template=nil, *arguments) #:nodoc: template &&= template.chomp template.gsub(/\G((?:[^\\]|\\.)*?)(\\)?\?/) { $1 + ($2 ? "?" : mu_pp(arguments.shift)) } diff --git a/test/ruby/test_env.rb b/test/ruby/test_env.rb index 6effa5197c..070e10464e 100644 --- a/test/ruby/test_env.rb +++ b/test/ruby/test_env.rb @@ -10,15 +10,13 @@ class TestEnv < Test::Unit::TestCase ] def assert_invalid_env(msg = nil) - failed = {} - INVALID_ENVVARS.select do |v| - begin - assert_raise(ArgumentError) {yield v} - rescue MiniTest::Assertion => e - failed[v] = e + all_assertions(msg) do |a| + INVALID_ENVVARS.each do |v| + a.for(v) do + assert_raise(ArgumentError) {yield v} + end end end - assert(failed.empty?, message(msg) {mu_pp(failed)}) end def setup diff --git a/test/ruby/test_yield.rb b/test/ruby/test_yield.rb index e7d150a08f..5c98bb8850 100644 --- a/test/ruby/test_yield.rb +++ b/test/ruby/test_yield.rb @@ -356,16 +356,12 @@ class TestRubyYieldGen < Test::Unit::TestCase end def assert_all_sentences(syntax, *args) - fails = [] syntax = Sentence.expand_syntax(syntax) - Sentence.each(syntax, *args) {|t| - begin - yield t - rescue MiniTest::Assertion => e - fails << e.message - end - } - assert(fails.empty?, proc {fails.join("\n--------\n")}) + all_assertions do |a| + Sentence.each(syntax, *args) {|t| + a.for(t) {yield t} + } + end end def test_yield