From 71730b42434e3c2dce7e7f6488bd54fae52cae51 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 27 Sep 2015 06:35:10 +0000 Subject: test/unit/assertions.rb: all_assertions * test/lib/test/unit/assertions.rb (all_assertions): try all assertions and check if all passed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/lib/envutil.rb | 23 ++++++++++------------- test/lib/test/unit/assertions.rb | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 13 deletions(-) (limited to 'test/lib') 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)) } -- cgit v1.2.3