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:
parent
6b52b88d46
commit
71730b4243
4 changed files with 42 additions and 29 deletions
|
@ -351,22 +351,19 @@ module Test
|
||||||
raise "test_stderr ignored, use block only or without block" if test_stderr != []
|
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)
|
yield(stdout.lines.map {|l| l.chomp }, stderr.lines.map {|l| l.chomp }, status)
|
||||||
else
|
else
|
||||||
errs = []
|
all_assertions(message) do |a|
|
||||||
[[test_stdout, stdout], [test_stderr, stderr]].each do |exp, act|
|
[["stdout", test_stdout, stdout], ["stderr", test_stderr, stderr]].each do |key, exp, act|
|
||||||
begin
|
a.for(key) do
|
||||||
if exp.is_a?(Regexp)
|
if exp.is_a?(Regexp)
|
||||||
assert_match(exp, act, message)
|
assert_match(exp, act)
|
||||||
elsif exp.all? {|e| String === e}
|
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
|
else
|
||||||
assert_pattern_list(exp, act, message)
|
assert_pattern_list(exp, act)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
rescue MiniTest::Assertion => e
|
|
||||||
errs << e.message
|
|
||||||
message = nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
raise MiniTest::Assertion, errs.join("\n---\n") unless errs.empty?
|
|
||||||
status
|
status
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -442,6 +442,28 @@ EOT
|
||||||
assert(failed.empty?, message(m) {failed.pretty_inspect})
|
assert(failed.empty?, message(m) {failed.pretty_inspect})
|
||||||
end
|
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:
|
def build_message(head, template=nil, *arguments) #:nodoc:
|
||||||
template &&= template.chomp
|
template &&= template.chomp
|
||||||
template.gsub(/\G((?:[^\\]|\\.)*?)(\\)?\?/) { $1 + ($2 ? "?" : mu_pp(arguments.shift)) }
|
template.gsub(/\G((?:[^\\]|\\.)*?)(\\)?\?/) { $1 + ($2 ? "?" : mu_pp(arguments.shift)) }
|
||||||
|
|
|
@ -10,15 +10,13 @@ class TestEnv < Test::Unit::TestCase
|
||||||
]
|
]
|
||||||
|
|
||||||
def assert_invalid_env(msg = nil)
|
def assert_invalid_env(msg = nil)
|
||||||
failed = {}
|
all_assertions(msg) do |a|
|
||||||
INVALID_ENVVARS.select do |v|
|
INVALID_ENVVARS.each do |v|
|
||||||
begin
|
a.for(v) do
|
||||||
assert_raise(ArgumentError) {yield v}
|
assert_raise(ArgumentError) {yield v}
|
||||||
rescue MiniTest::Assertion => e
|
end
|
||||||
failed[v] = e
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
assert(failed.empty?, message(msg) {mu_pp(failed)})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
|
|
|
@ -356,16 +356,12 @@ class TestRubyYieldGen < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_all_sentences(syntax, *args)
|
def assert_all_sentences(syntax, *args)
|
||||||
fails = []
|
|
||||||
syntax = Sentence.expand_syntax(syntax)
|
syntax = Sentence.expand_syntax(syntax)
|
||||||
Sentence.each(syntax, *args) {|t|
|
all_assertions do |a|
|
||||||
begin
|
Sentence.each(syntax, *args) {|t|
|
||||||
yield t
|
a.for(t) {yield t}
|
||||||
rescue MiniTest::Assertion => e
|
}
|
||||||
fails << e.message
|
end
|
||||||
end
|
|
||||||
}
|
|
||||||
assert(fails.empty?, proc {fails.join("\n--------\n")})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_yield
|
def test_yield
|
||||||
|
|
Loading…
Reference in a new issue