summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2024-02-26 11:30:11 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2024-02-26 11:56:38 +0900
commitf23d5028059078a346efc977287b669d494a5a3f (patch)
treea7e8fc377dece58762a5f79fb45ddb2895ef0e8f /test/ruby
parentdc146babf47a84bbd1f176d766637d4a40327019 (diff)
[Bug #20296] Refine the test
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_complex.rb35
1 files changed, 18 insertions, 17 deletions
diff --git a/test/ruby/test_complex.rb b/test/ruby/test_complex.rb
index f2a0f5b5ee..3a9bad1416 100644
--- a/test/ruby/test_complex.rb
+++ b/test/ruby/test_complex.rb
@@ -980,17 +980,27 @@ class Complex_Test < Test::Unit::TestCase
}
end
- def test_Complex_without_exception
- assert_complex_without_exception('5x')
- assert_complex_without_exception(nil)
- assert_complex_without_exception(Object.new)
- assert_complex_without_exception(1, nil)
- assert_complex_without_exception(1, Object.new)
+ def assert_complex_with_exception(error, *args, message: nil)
+ 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_complex_without_exception(o)
- assert_complex_without_exception(1, o)
+ assert_complex_with_exception(RuntimeError, o)
+ assert_complex_with_exception(TypeError, 1, o)
end
def test_respond
@@ -1249,13 +1259,4 @@ class Complex_Test < Test::Unit::TestCase
Complex.polar(1, obj)
end
end
-
- private
-
- def assert_complex_without_exception(*args)
- assert_nothing_raised(ArgumentError) do
- assert_nil(Complex(*args, exception: false))
- assert_nil($!)
- end
- end
end