Commit a215292b authored by dearblue's avatar dearblue

Use nested `assert`

parent 1b9f949f
...@@ -3,9 +3,11 @@ require 'open3' ...@@ -3,9 +3,11 @@ require 'open3'
def assert_mruby(exp_out, exp_err, exp_success, args) def assert_mruby(exp_out, exp_err, exp_success, args)
out, err, stat = Open3.capture3(cmd("mruby"), *args) out, err, stat = Open3.capture3(cmd("mruby"), *args)
assert_operator(exp_out, :===, out, "standard output") assert do
assert_operator(exp_err, :===, err, "standard error") assert_operator(exp_out, :===, out, "standard output")
assert_equal(exp_success, stat.success?, "exit success?") assert_operator(exp_err, :===, err, "standard error")
assert_equal(exp_success, stat.success?, "exit success?")
end
end end
assert('regression for #1564') do assert('regression for #1564') do
......
def assert_complex(real, exp) def assert_complex(real, exp)
assert_float real.real, exp.real assert do
assert_float real.imaginary, exp.imaginary assert_float real.real, exp.real
assert_float real.imaginary, exp.imaginary
end
end end
assert 'Complex' do assert 'Complex' do
......
...@@ -5,24 +5,26 @@ MRubyIOTestUtil.io_test_setup ...@@ -5,24 +5,26 @@ MRubyIOTestUtil.io_test_setup
$cr, $crlf, $cmd = MRubyIOTestUtil.win? ? [1, "\r\n", "cmd /c "] : [0, "\n", ""] $cr, $crlf, $cmd = MRubyIOTestUtil.win? ? [1, "\r\n", "cmd /c "] : [0, "\n", ""]
def assert_io_open(meth) def assert_io_open(meth)
fd = IO.sysopen($mrbtest_io_rfname) assert do
assert_equal Fixnum, fd.class fd = IO.sysopen($mrbtest_io_rfname)
io1 = IO.__send__(meth, fd) assert_equal Fixnum, fd.class
begin io1 = IO.__send__(meth, fd)
assert_equal IO, io1.class begin
assert_equal $mrbtest_io_msg, io1.read assert_equal IO, io1.class
ensure assert_equal $mrbtest_io_msg, io1.read
io1.close ensure
end io1.close
end
io2 = IO.__send__(meth, IO.sysopen($mrbtest_io_rfname))do |io| io2 = IO.__send__(meth, IO.sysopen($mrbtest_io_rfname))do |io|
if meth == :open if meth == :open
assert_equal $mrbtest_io_msg, io.read assert_equal $mrbtest_io_msg, io.read
else else
flunk "IO.#{meth} does not take block" flunk "IO.#{meth} does not take block"
end
end end
io2.close unless meth == :open
end end
io2.close unless meth == :open
end end
assert('IO.class', '15.2.20') do assert('IO.class', '15.2.20') do
......
...@@ -2,8 +2,10 @@ PACK_IS_LITTLE_ENDIAN = "\x01\00".unpack('S')[0] == 0x01 ...@@ -2,8 +2,10 @@ PACK_IS_LITTLE_ENDIAN = "\x01\00".unpack('S')[0] == 0x01
def assert_pack tmpl, packed, unpacked def assert_pack tmpl, packed, unpacked
t = tmpl.inspect t = tmpl.inspect
assert_equal packed, unpacked.pack(tmpl), "#{unpacked.inspect}.pack(#{t})" assert do
assert_equal unpacked, packed.unpack(tmpl), "#{packed.inspect}.unpack(#{t})" assert_equal packed, unpacked.pack(tmpl), "#{unpacked.inspect}.pack(#{t})"
assert_equal unpacked, packed.unpack(tmpl), "#{packed.inspect}.unpack(#{t})"
end
end end
# pack & unpack 'm' (base64) # pack & unpack 'm' (base64)
......
...@@ -23,17 +23,21 @@ class ComplexLikeNumeric < UserDefinedNumeric ...@@ -23,17 +23,21 @@ class ComplexLikeNumeric < UserDefinedNumeric
end end
def assert_rational(exp, real) def assert_rational(exp, real)
assert_float exp.numerator, real.numerator assert do
assert_float exp.denominator, real.denominator assert_float exp.numerator, real.numerator
assert_float exp.denominator, real.denominator
end
end end
def assert_equal_rational(exp, o1, o2) def assert_equal_rational(exp, o1, o2)
if exp assert do
assert_operator(o1, :==, o2) if exp
assert_not_operator(o1, :!=, o2) assert_operator(o1, :==, o2)
else assert_not_operator(o1, :!=, o2)
assert_not_operator(o1, :==, o2) else
assert_operator(o1, :!=, o2) assert_not_operator(o1, :==, o2)
assert_operator(o1, :!=, o2)
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment