Commit 44381f0a authored by KOBAYASHI Shuji's avatar KOBAYASHI Shuji

Refine message to `skip` in nested `assert`

- I think "Info" is used only to `skip`, so change to "Skip".
- Changed the default value of `assert` and specify the argument explicitly
  at the caller of `assert` because it is unnatural "Assertion failed" is
  output even though the assertion doesn't fail.

== Example:

  def assert_foo(exp, act)
    assert do
      assert_equal exp[0], act[0]
      assert_equal exp[1], act[1]
    end
  end

  def assert_bar(exp, act)
    assert do
      skip
    end
  end

  def assert_baz(exp, act)
    assert do
      assert_equal exp, act
      assert_bar exp, act
    end
  end

  assert 'test#skip_in_nested_assert' do
    assert_baz 1, 1
  end

  === Before this patch:

    ?..
    Info: test#skip_in_nested_assert (core)
     - Assertion[1]
        Info: Assertion failed (core)
         - Assertion[1-2]
            Skip: Assertion failed (core)
      Total: 3
         OK: 2
         KO: 0
      Crash: 0
    Warning: 0
       Skip: 1

  === After this patch:

    ???
    Skip: test#skip_in_nested_assert (core)
     - Assertion[1]
        Skip: assert (core)
         - Assertion[1-2]
            Skip: assert (core)
      Total: 3
         OK: 0
         KO: 0
      Crash: 0
    Warning: 0
       Skip: 3
parent ff43b2b9
...@@ -3,7 +3,7 @@ require 'open3' ...@@ -3,7 +3,7 @@ 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 do assert "assert_mruby" do
assert_operator(exp_out, :===, out, "standard output") assert_operator(exp_out, :===, out, "standard output")
assert_operator(exp_err, :===, err, "standard error") assert_operator(exp_err, :===, err, "standard error")
assert_equal(exp_success, stat.success?, "exit success?") assert_equal(exp_success, stat.success?, "exit success?")
......
def assert_complex(real, exp) def assert_complex(real, exp)
assert do assert "assert_complex" do
assert_float real.real, exp.real assert_float real.real, exp.real
assert_float real.imaginary, exp.imaginary assert_float real.imaginary, exp.imaginary
end end
......
...@@ -5,7 +5,7 @@ MRubyIOTestUtil.io_test_setup ...@@ -5,7 +5,7 @@ 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)
assert do assert "assert_io_open" do
fd = IO.sysopen($mrbtest_io_rfname) fd = IO.sysopen($mrbtest_io_rfname)
assert_equal Fixnum, fd.class assert_equal Fixnum, fd.class
io1 = IO.__send__(meth, fd) io1 = IO.__send__(meth, fd)
......
...@@ -2,7 +2,7 @@ PACK_IS_LITTLE_ENDIAN = "\x01\00".unpack('S')[0] == 0x01 ...@@ -2,7 +2,7 @@ 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 do assert "assert_pack" do
assert_equal packed, unpacked.pack(tmpl), "#{unpacked.inspect}.pack(#{t})" assert_equal packed, unpacked.pack(tmpl), "#{unpacked.inspect}.pack(#{t})"
assert_equal unpacked, packed.unpack(tmpl), "#{packed.inspect}.unpack(#{t})" assert_equal unpacked, packed.unpack(tmpl), "#{packed.inspect}.unpack(#{t})"
end end
......
...@@ -23,14 +23,14 @@ class ComplexLikeNumeric < UserDefinedNumeric ...@@ -23,14 +23,14 @@ class ComplexLikeNumeric < UserDefinedNumeric
end end
def assert_rational(exp, real) def assert_rational(exp, real)
assert do assert "assert_rational" do
assert_float exp.numerator, real.numerator assert_float exp.numerator, real.numerator
assert_float exp.denominator, real.denominator assert_float exp.denominator, real.denominator
end end
end end
def assert_equal_rational(exp, o1, o2) def assert_equal_rational(exp, o1, o2)
assert do assert "assert_equal_rational" do
if exp if exp
assert_operator(o1, :==, o2) assert_operator(o1, :==, o2)
assert_not_operator(o1, :!=, o2) assert_not_operator(o1, :!=, o2)
......
...@@ -76,7 +76,7 @@ end ...@@ -76,7 +76,7 @@ end
# iso : The ISO reference code of the feature # iso : The ISO reference code of the feature
# which will be tested by this # which will be tested by this
# assertion # assertion
def assert(str = 'Assertion failed', iso = '') def assert(str = 'assert', iso = '')
t_print(str, (iso != '' ? " [#{iso}]" : ''), ' : ') if $mrbtest_verbose t_print(str, (iso != '' ? " [#{iso}]" : ''), ' : ') if $mrbtest_verbose
begin begin
$mrbtest_child_noassert ||= [0] $mrbtest_child_noassert ||= [0]
...@@ -99,10 +99,10 @@ def assert(str = 'Assertion failed', iso = '') ...@@ -99,10 +99,10 @@ def assert(str = 'Assertion failed', iso = '')
yield yield
if $mrbtest_assert.size > 0 if $mrbtest_assert.size > 0
if $mrbtest_assert.size == $mrbtest_child_noassert[-1] if $mrbtest_assert.size == $mrbtest_child_noassert[-1]
$asserts.push(assertion_string('Info: ', str, iso)) $asserts.push(assertion_string('Skip: ', str, iso))
$mrbtest_child_noassert[-2] += 1 $mrbtest_child_noassert[-2] += 1
$ok_test += 1 $skip_test += 1
t_print('.') t_print('?')
else else
$asserts.push(assertion_string('Fail: ', str, iso)) $asserts.push(assertion_string('Fail: ', str, iso))
$ko_test += 1 $ko_test += 1
......
...@@ -8,7 +8,7 @@ def assert_step(exp, receiver, args, inf: false) ...@@ -8,7 +8,7 @@ def assert_step(exp, receiver, args, inf: false)
break if inf && exp.size == act.size break if inf && exp.size == act.size
end end
expr = "#{receiver.inspect}.step(#{args.map(&:inspect).join(', ')})" expr = "#{receiver.inspect}.step(#{args.map(&:inspect).join(', ')})"
assert do assert "assert_step" do
assert_true(exp.eql?(act), "#{expr}: counters", assertion_diff(exp, act)) assert_true(exp.eql?(act), "#{expr}: counters", assertion_diff(exp, act))
assert_same(receiver, ret, "#{expr}: return value") unless inf assert_same(receiver, ret, "#{expr}: return value") unless inf
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