summaryrefslogtreecommitdiff
path: root/test/ruby/test_exception.rb
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-14 12:52:17 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-14 12:52:17 +0000
commitf09f597422b4130727638e41b1332edac1514642 (patch)
tree6a4ea2196159042da8c2751244d3e612d335217e /test/ruby/test_exception.rb
parente4f8e61dddb18f29fe71392a464f87b612d7eb5c (diff)
* test/ruby/test_object.rb: new tests to achieve over 90% test
coverage of object.c, eval.c and eval_method.c. * test/ruby/test_module.rb: ditto. * test/ruby/test_trace.rb: ditto. * test/ruby/test_integer.rb: ditto. * test/ruby/test_float.rb: ditto. * test/ruby/test_method.rb: ditto. * test/ruby/test_variable.rb: ditto. * test/ruby/test_eval.rb: ditto. * test/ruby/test_exception.rb: ditto. * test/ruby/test_class.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16418 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_exception.rb')
-rw-r--r--test/ruby/test_exception.rb62
1 files changed, 62 insertions, 0 deletions
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb
index 4c27c52f3c..6c2cedd242 100644
--- a/test/ruby/test_exception.rb
+++ b/test/ruby/test_exception.rb
@@ -1,6 +1,11 @@
require 'test/unit'
+require_relative 'envutil'
class TestException < Test::Unit::TestCase
+ def ruby(*r, &b)
+ EnvUtil.rubyexec(*r, &b)
+ end
+
def test_exception
begin
raise "this must be handled"
@@ -184,4 +189,61 @@ class TestException < Test::Unit::TestCase
assert(false)
end
end
+
+ def test_raise_with_wrong_number_of_arguments
+ assert_raise(TypeError) { raise nil }
+ assert_raise(TypeError) { raise 1, 1 }
+ assert_raise(ArgumentError) { raise 1, 1, 1, 1 }
+ end
+
+ def test_errat
+ ruby do |w, r, e|
+ w.puts "p $@"
+ w.close
+ assert_equal("nil", r.read.chomp)
+ assert_equal("", e.read.chomp)
+ end
+
+ ruby do |w, r, e|
+ w.puts "$@ = 1"
+ w.close
+ assert_equal("", r.read.chomp)
+ assert_match(/\$! not set \(ArgumentError\)$/, e.read.chomp)
+ end
+
+ ruby do |w, r, e|
+ w.puts "begin"
+ w.puts " raise"
+ w.puts "rescue"
+ w.puts " $@ = 1"
+ w.puts "end"
+ w.close
+ assert_equal("", r.read.chomp)
+ assert_match(/backtrace must be Array of String \(TypeError\)$/, e.read.chomp)
+ end
+
+ ruby do |w, r, e|
+ w.puts "begin"
+ w.puts " raise"
+ w.puts "rescue"
+ w.puts " $@ = 'foo'"
+ w.puts " raise"
+ w.puts "end"
+ w.close
+ assert_equal("", r.read.chomp)
+ assert_match(/^foo: unhandled exception$/, e.read.chomp)
+ end
+
+ ruby do |w, r, e|
+ w.puts "begin"
+ w.puts " raise"
+ w.puts "rescue"
+ w.puts " $@ = %w(foo bar baz)"
+ w.puts " raise"
+ w.puts "end"
+ w.close
+ assert_equal("", r.read.chomp)
+ assert_match(/^foo: unhandled exception\s+from bar\s+from baz$/, e.read.chomp)
+ end
+ end
end