merge revision(s) dc146babf4, f23d502805, a0f7de814a: [Backport #20296]

[Bug #20296] Clear errinfo when `exception: false`

	[Bug #20296] Refine the test

	[Bug #20296] Fix the default assertion message
This commit is contained in:
nagachika 2024-07-15 09:50:14 +09:00
parent a54c717c7a
commit 90f4c5dc73
3 changed files with 24 additions and 25 deletions

View file

@ -2116,8 +2116,11 @@ nucomp_convert(VALUE klass, VALUE a1, VALUE a2, int raise)
return a1;
/* should raise exception for consistency */
if (!k_numeric_p(a1)) {
if (!raise)
return rb_protect(to_complex, a1, NULL);
if (!raise) {
a1 = rb_protect(to_complex, a1, NULL);
rb_set_errinfo(Qnil);
return a1;
}
return to_complex(a1);
}
}

View file

@ -915,31 +915,27 @@ class Complex_Test < Test::Unit::TestCase
}
end
def test_Complex_without_exception
assert_nothing_raised(ArgumentError){
assert_equal(nil, Complex('5x', exception: false))
}
assert_nothing_raised(ArgumentError){
assert_equal(nil, Complex(nil, exception: false))
}
assert_nothing_raised(ArgumentError){
assert_equal(nil, Complex(Object.new, exception: false))
}
assert_nothing_raised(ArgumentError){
assert_equal(nil, Complex(1, nil, exception: false))
}
assert_nothing_raised(ArgumentError){
assert_equal(nil, Complex(1, Object.new, exception: false))
}
def assert_complex_with_exception(error, *args, message: "")
assert_raise(error, message) do
Complex(*args, exception: true)
end
assert_nothing_raised(error, message) do
assert_nil(Complex(*args, exception: false))
assert_nil($!)
end
end
def test_Complex_with_exception
assert_complex_with_exception(ArgumentError, '5x')
assert_complex_with_exception(TypeError, nil)
assert_complex_with_exception(TypeError, Object.new)
assert_complex_with_exception(TypeError, 1, nil)
assert_complex_with_exception(TypeError, 1, Object.new)
o = Object.new
def o.to_c; raise; end
assert_nothing_raised(ArgumentError){
assert_equal(nil, Complex(o, exception: false))
}
assert_nothing_raised(ArgumentError){
assert_equal(nil, Complex(1, o, exception: false))
}
assert_complex_with_exception(RuntimeError, o)
assert_complex_with_exception(TypeError, 1, o)
end
def test_respond

View file

@ -11,7 +11,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 4
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
#define RUBY_PATCHLEVEL 189
#define RUBY_PATCHLEVEL 190
#include "ruby/version.h"
#include "ruby/internal/abi.h"