summaryrefslogtreecommitdiff
path: root/bootstraptest/test_exception.rb
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-06-27 16:26:31 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-06-27 16:26:31 +0000
commitcaa535286d7442ddcbc1caf9fb2778efd435c56d (patch)
treef6181413baecc29e0360ae03f6b362d860d5578e /bootstraptest/test_exception.rb
parentfd78c2193e7032389a2a3ff9154654fa231ac8f0 (diff)
* bootstraptest/runner.rb: fix to show file name.
* bootstraptest/test_*.rb: add bootstarp tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12639 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bootstraptest/test_exception.rb')
-rw-r--r--bootstraptest/test_exception.rb370
1 files changed, 370 insertions, 0 deletions
diff --git a/bootstraptest/test_exception.rb b/bootstraptest/test_exception.rb
new file mode 100644
index 0000000..79d7388
--- /dev/null
+++ b/bootstraptest/test_exception.rb
@@ -0,0 +1,370 @@
+assert_equal %q{2}, %q{
+ begin
+ 1+1
+ ensure
+ 2+2
+ end
+}
+assert_equal %q{4}, %q{
+ begin
+ 1+1
+ begin
+ 2+2
+ ensure
+ 3+3
+ end
+ ensure
+ 4+4
+ end
+}
+assert_equal %q{4}, %q{
+ begin
+ 1+1
+ begin
+ 2+2
+ ensure
+ 3+3
+ end
+ ensure
+ 4+4
+ begin
+ 5+5
+ ensure
+ 6+6
+ end
+ end
+}
+assert_equal %q{NilClass}, %q{
+ a = nil
+ 1.times{|e|
+ begin
+ rescue => err
+ end
+ a = err.class
+ }
+ a
+}
+assert_equal %q{RuntimeError}, %q{
+ a = nil
+ 1.times{|e|
+ begin
+ raise
+ rescue => err
+ end
+ a = err.class
+ }
+ a
+}
+assert_equal %q{}, %q{
+ $!
+}
+assert_equal %q{FOO}, %q{
+ begin
+ raise "FOO"
+ rescue
+ $!
+ end
+}
+assert_equal %q{FOO}, %q{
+ def m
+ $!
+ end
+ begin
+ raise "FOO"
+ rescue
+ m()
+ end
+}
+assert_equal %q{[#<RuntimeError: BAR>, #<RuntimeError: FOO>]}, %q{
+ $ans = []
+ def m
+ $!
+ end
+ begin
+ raise "FOO"
+ rescue
+ begin
+ raise "BAR"
+ rescue
+ $ans << m()
+ end
+ $ans << m()
+ end
+ $ans
+}
+assert_equal %q{[#<RuntimeError: FOO>, #<RuntimeError: FOO>]}, %q{
+ $ans = []
+ def m
+ $!
+ end
+
+ begin
+ begin
+ raise "FOO"
+ ensure
+ $ans << m()
+ end
+ rescue
+ $ans << m()
+ end
+}
+assert_equal %q{[nil]}, %q{
+ $ans = []
+ def m
+ $!
+ end
+ def m2
+ 1.times{
+ begin
+ return
+ ensure
+ $ans << m
+ end
+ }
+ end
+ m2
+ $ans
+}
+assert_equal %q{ok}, %q{
+ begin
+ raise
+ rescue
+ :ok
+ end
+}
+assert_equal %q{ok}, %q{
+ begin
+ raise
+ rescue
+ :ok
+ ensure
+ :ng
+ end
+}
+assert_equal %q{RuntimeError}, %q{
+ begin
+ raise
+ rescue => e
+ e.class
+ end
+}
+assert_equal %q{ng}, %q{
+ begin
+ raise
+ rescue StandardError
+ :ng
+ rescue Exception
+ :ok
+ end
+}
+assert_equal %q{c}, %q{
+ begin
+ begin
+ raise "a"
+ rescue
+ raise "b"
+ ensure
+ raise "c"
+ end
+ rescue => e
+ e.message
+ end
+}
+assert_equal %q{33}, %q{
+ def m a, b
+ a + b
+ end
+ m(1, begin
+ raise
+ rescue
+ 2
+ end) +
+ m(10, begin
+ raise
+ rescue
+ 20
+ ensure
+ 30
+ end)
+}
+assert_equal %q{3}, %q{
+ def m a, b
+ a + b
+ end
+ m(begin
+ raise
+ rescue
+ 1
+ end,
+ begin
+ raise
+ rescue
+ 2
+ end)
+}
+assert_equal %q{ok3}, %q{
+ class E1 < Exception
+ end
+
+ def m
+ yield
+ end
+
+ begin
+ begin
+ begin
+ m{
+ raise
+ }
+ rescue E1
+ :ok2
+ ensure
+ end
+ rescue
+ :ok3
+ ensure
+ end
+ rescue E1
+ :ok
+ ensure
+ end
+}
+assert_equal %q{7}, %q{
+ $i = 0
+ def m
+ iter{
+ begin
+ $i += 1
+ begin
+ $i += 2
+ break
+ ensure
+
+ end
+ ensure
+ $i += 4
+ end
+ $i = 0
+ }
+ end
+
+ def iter
+ yield
+ end
+ m
+ $i
+}
+assert_equal %q{10}, %q{
+ $i = 0
+ def m
+ begin
+ $i += 1
+ begin
+ $i += 2
+ return
+ ensure
+ $i += 3
+ end
+ ensure
+ $i += 4
+ end
+ p :end
+ end
+ m
+ $i
+}
+assert_equal %q{1}, %q{
+ begin
+ 1
+ rescue
+ 2
+ end
+}
+assert_equal %q{4}, %q{
+ begin
+ 1
+ begin
+ 2
+ rescue
+ 3
+ end
+ 4
+ rescue
+ 5
+ end
+}
+assert_equal %q{3}, %q{
+ begin
+ 1
+ rescue
+ 2
+ else
+ 3
+ end
+}
+assert_equal %q{2}, %q{
+ begin
+ 1+1
+ rescue
+ 2+2
+ ensure
+ 3+3
+ end
+ }
+assert_equal %q{2}, %q{
+ begin
+ 1+1
+ rescue
+ 2+2
+ ensure
+ 3+3
+ end
+ }
+assert_equal %q{6}, %q{
+ begin
+ 1+1
+ rescue
+ 2+2
+ else
+ 3+3
+ ensure
+ 4+4
+ end
+ }
+assert_equal %q{12}, %q{
+ begin
+ 1+1
+ begin
+ 2+2
+ rescue
+ 3+3
+ else
+ 4+4
+ end
+ rescue
+ 5+5
+ else
+ 6+6
+ ensure
+ 7+7
+ end
+ }
+assert_equal %q{ok}, %q{ #
+ proc{
+ begin
+ raise
+ break
+ rescue
+ :ok
+ end
+ }.call
+}
+assert_equal %q{}, %q{
+ proc do
+ begin
+ raise StandardError
+ redo
+ rescue StandardError
+ end
+ end.call
+}