summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-02-12 21:10:53 +0900
committerGitHub <[email protected]>2021-02-12 21:10:53 +0900
commitd3fbac4d53de338bc5560b985fb7e51112d3cab3 (patch)
tree499188e9ff794d40bd9824abb1554610decfa058
parent5f71e0e7548624f3ef5b3eb5b9be666da7cc752d (diff)
parent955464ca3cf408a14ae98b1e93afe31023219af9 (diff)
downloadmruby-d3fbac4d53de338bc5560b985fb7e51112d3cab3.tar.gz
mruby-d3fbac4d53de338bc5560b985fb7e51112d3cab3.zip
Merge pull request #5335 from shuujii/add-UncaughtThrowError-tagvalue-for-Ruby-compatibility
Add `UncaughtThrowError#{tag,value}` for Ruby compatibility
-rw-r--r--mrbgems/mruby-catch/mrblib/catch.rb8
-rw-r--r--mrbgems/mruby-catch/test/catch.rb23
2 files changed, 19 insertions, 12 deletions
diff --git a/mrbgems/mruby-catch/mrblib/catch.rb b/mrbgems/mruby-catch/mrblib/catch.rb
index 8e5f59023..9a60a67a3 100644
--- a/mrbgems/mruby-catch/mrblib/catch.rb
+++ b/mrbgems/mruby-catch/mrblib/catch.rb
@@ -1,8 +1,8 @@
class UncaughtThrowError < ArgumentError
- attr_reader :_tag, :_val
- def initialize(tag, val)
- @_tag = tag
- @_val = val
+ attr_reader :tag, :value
+ def initialize(tag, value)
+ @tag = tag
+ @value = value
super("uncaught throw #{tag.inspect}")
end
end
diff --git a/mrbgems/mruby-catch/test/catch.rb b/mrbgems/mruby-catch/test/catch.rb
index fe5bda096..38a4eb907 100644
--- a/mrbgems/mruby-catch/test/catch.rb
+++ b/mrbgems/mruby-catch/test/catch.rb
@@ -3,10 +3,14 @@ assert "return throw value" do
result = catch :foo do
loop do
loop do
- throw :foo, val
+ begin
+ throw :foo, val
+ rescue Exception
+ flunk("should not reach here 1")
+ end
break
end
- flunk("should not reach here")
+ flunk("should not reach here 2")
end
false
end
@@ -30,13 +34,16 @@ assert "pass the given tag to block" do
catch(tag){|t| assert_same(tag, t)}
end
-assert "tag identity" do
- assert_raise_with_message_pattern(Exception, "uncaught throw *") do
- catch [:tag] do
- throw [:tag]
- end
- flunk("should not reach here")
+assert "tag identity, uncaught throw" do
+ tag, val = [:tag], [:val]
+ catch [:tag] do
+ throw tag, val
end
+ flunk("should not reach here")
+rescue Exception => e
+ assert_match("uncaught throw *", e.message)
+ assert_same(tag, e.tag)
+ assert_same(val, e.value)
end
assert "without catch arguments" do