1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2015-09-27 06:35:10 +00:00
parent 6b52b88d46
commit 71730b4243
4 changed files with 42 additions and 29 deletions

View file

@ -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
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, message)
assert_match(exp, act)
elsif exp.all? {|e| String === e}
assert_equal(exp, act.lines.map {|l| l.chomp }, message)
assert_equal(exp, act.lines.map {|l| l.chomp })
else
assert_pattern_list(exp, act, message)
end
rescue MiniTest::Assertion => e
errs << e.message
message = nil
assert_pattern_list(exp, act)
end
end
end
end
raise MiniTest::Assertion, errs.join("\n---\n") unless errs.empty?
status
end
end

View file

@ -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)) }

View file

@ -10,15 +10,13 @@ class TestEnv < Test::Unit::TestCase
]
def assert_invalid_env(msg = nil)
failed = {}
INVALID_ENVVARS.select do |v|
begin
all_assertions(msg) do |a|
INVALID_ENVVARS.each do |v|
a.for(v) do
assert_raise(ArgumentError) {yield v}
rescue MiniTest::Assertion => e
failed[v] = e
end
end
assert(failed.empty?, message(msg) {mu_pp(failed)})
end
end
def setup

View file

@ -356,16 +356,12 @@ class TestRubyYieldGen < Test::Unit::TestCase
end
def assert_all_sentences(syntax, *args)
fails = []
syntax = Sentence.expand_syntax(syntax)
all_assertions do |a|
Sentence.each(syntax, *args) {|t|
begin
yield t
rescue MiniTest::Assertion => e
fails << e.message
end
a.for(t) {yield t}
}
assert(fails.empty?, proc {fails.join("\n--------\n")})
end
end
def test_yield