mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
test_exception.rb: more tests
* test/ruby/test_exception.rb: more tests for catch and throw. catch but no throw, autogenerated tag, and uncaught throw. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48314 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
181f3719bb
commit
72ce1a4759
2 changed files with 37 additions and 13 deletions
|
@ -228,7 +228,7 @@ module Test
|
||||||
end
|
end
|
||||||
msg = message(msg) {
|
msg = message(msg) {
|
||||||
"Expected #{mu_pp(tag)} to have been thrown"\
|
"Expected #{mu_pp(tag)} to have been thrown"\
|
||||||
"#{", not #{thrown}" if thrown}"
|
"#{%Q[, not #{thrown}] if thrown}"
|
||||||
}
|
}
|
||||||
assert(false, msg)
|
assert(false, msg)
|
||||||
end
|
end
|
||||||
|
|
|
@ -129,18 +129,42 @@ class TestException < Test::Unit::TestCase
|
||||||
assert(!bad)
|
assert(!bad)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_catch_no_throw
|
||||||
|
assert_equal(:foo, catch {:foo})
|
||||||
|
end
|
||||||
|
|
||||||
def test_catch_throw
|
def test_catch_throw
|
||||||
assert(catch(:foo) {
|
result = catch(:foo) {
|
||||||
loop do
|
loop do
|
||||||
loop do
|
loop do
|
||||||
throw :foo, true
|
throw :foo, true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
break
|
assert(false, "should no reach here")
|
||||||
assert(false) # should no reach here
|
end
|
||||||
end
|
false
|
||||||
false
|
}
|
||||||
})
|
assert(result)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_catch_throw_noarg
|
||||||
|
assert_nothing_raised(ArgumentError) {
|
||||||
|
result = catch {|obj|
|
||||||
|
throw obj, :ok
|
||||||
|
assert(false, "should no reach here")
|
||||||
|
}
|
||||||
|
assert_equal(:ok, result)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_uncaught_throw
|
||||||
|
assert_raise_with_message(ArgumentError, /uncaught throw/) {
|
||||||
|
catch("foo") {|obj|
|
||||||
|
throw obj.dup, :ok
|
||||||
|
assert(false, "should no reach here")
|
||||||
|
}
|
||||||
|
assert(false, "should no reach here")
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_catch_throw_in_require
|
def test_catch_throw_in_require
|
||||||
|
@ -148,7 +172,7 @@ class TestException < Test::Unit::TestCase
|
||||||
Tempfile.create(["dep", ".rb"]) {|t|
|
Tempfile.create(["dep", ".rb"]) {|t|
|
||||||
t.puts("throw :extdep, 42")
|
t.puts("throw :extdep, 42")
|
||||||
t.close
|
t.close
|
||||||
assert_equal(42, catch(:extdep) {require t.path}, bug7185)
|
assert_equal(42, assert_throw(:extdep, bug7185) {require t.path}, bug7185)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue