From 0629cf21baefd83765206036e4ceac45f7a55ca4 Mon Sep 17 00:00:00 2001 From: Kazuki Tsujimoto Date: Sun, 3 Jun 2012 17:48:02 +0900 Subject: A rescue clause with no parameter list rescues only StandardErrors --- test/t/exception.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'test/t/exception.rb') diff --git a/test/t/exception.rb b/test/t/exception.rb index 6b46314d0..d68ed8bd7 100644 --- a/test/t/exception.rb +++ b/test/t/exception.rb @@ -193,3 +193,39 @@ assert('Exception 10') do 7+7 end == 12 end + +assert('Exception 11') do + a = :ok + begin + begin + raise Exception + rescue + a = :ng + end + rescue Exception + end + a == :ok +end + +assert('Exception 12') do + a = :ok + begin + raise Exception rescue a = :ng + rescue Exception + end + a == :ok +end + +assert('Exception 13') do + a = :ng + begin + raise StandardError + rescue TypeError, ArgumentError + a = :ng + rescue + a = :ok + else + a = :ng + end + a == :ok +end -- cgit v1.2.3 From c78dc2930c6b8c927e6c1415ecbc13e727c3637c Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sun, 3 Jun 2012 23:31:17 +0800 Subject: Add superclass tests for Exceptions --- test/t/argumenterror.rb | 5 +++++ test/t/exception.rb | 4 ++++ test/t/indexerror.rb | 5 +++++ test/t/nameerror.rb | 4 ++++ test/t/nomethoderror.rb | 5 +++++ test/t/rangeerror.rb | 5 +++++ test/t/standarderror.rb | 5 +++++ test/t/typeerror.rb | 5 +++++ 8 files changed, 38 insertions(+) (limited to 'test/t/exception.rb') diff --git a/test/t/argumenterror.rb b/test/t/argumenterror.rb index ca998f8de..71cf38e26 100644 --- a/test/t/argumenterror.rb +++ b/test/t/argumenterror.rb @@ -13,3 +13,8 @@ assert('ArgumentError', '15.2.24') do ArgumentError.class == Class and e2.class == ArgumentError end + +assert('ArgumentError superclass', '15.2.24.2') do + ArgumentError.superclass == StandardError +end + diff --git a/test/t/exception.rb b/test/t/exception.rb index d68ed8bd7..22795161f 100644 --- a/test/t/exception.rb +++ b/test/t/exception.rb @@ -5,6 +5,10 @@ assert('Exception', '15.2.22') do Exception.class == Class end +assert('Exception superclass', '15.2.22.2') do + Exception.superclass == Object +end + assert('Exception.exception', '15.2.22.4.1') do e = Exception.exception('a') diff --git a/test/t/indexerror.rb b/test/t/indexerror.rb index d0cb81f32..d7c8ba148 100644 --- a/test/t/indexerror.rb +++ b/test/t/indexerror.rb @@ -4,3 +4,8 @@ assert('IndexError', '15.2.33') do IndexError.class == Class end + +assert('IndexError superclass', '15.2.33.2') do + IndexError.superclass == StandardError +end + diff --git a/test/t/nameerror.rb b/test/t/nameerror.rb index 67451ecf8..8e57ac18b 100644 --- a/test/t/nameerror.rb +++ b/test/t/nameerror.rb @@ -5,6 +5,10 @@ assert('NameError', '15.2.31') do NameError.class == Class end +assert('NameError superclass', '15.2.31.2') do + NameError.superclass == StandardError +end + # TODO 15.2.31.2.1 NameError#name assert('NameError#initialize', '15.2.31.2.2') do diff --git a/test/t/nomethoderror.rb b/test/t/nomethoderror.rb index 9eb122158..caab04a41 100644 --- a/test/t/nomethoderror.rb +++ b/test/t/nomethoderror.rb @@ -11,3 +11,8 @@ assert('NoMethodError', '15.2.32') do NoMethodError.class == Class and e2.class == NoMethodError end + +assert('NoMethodError superclass', '15.2.32.2') do + NoMethodError.superclass == NameError +end + diff --git a/test/t/rangeerror.rb b/test/t/rangeerror.rb index 7edb5d2d9..57afdc4bd 100644 --- a/test/t/rangeerror.rb +++ b/test/t/rangeerror.rb @@ -4,3 +4,8 @@ assert('RangeError', '15.2.26') do RangeError.class == Class end + +assert('RangeError superclass', '15.2.26.2') do + RangeError.superclass == StandardError +end + diff --git a/test/t/standarderror.rb b/test/t/standarderror.rb index 550c337c1..3868d7567 100644 --- a/test/t/standarderror.rb +++ b/test/t/standarderror.rb @@ -4,3 +4,8 @@ assert('StandardError', '15.2.23') do StandardError.class == Class end + +assert('StandardError superclass', '15.2.23.2') do + StandardError.superclass == Exception +end + diff --git a/test/t/typeerror.rb b/test/t/typeerror.rb index c4434aa24..d48db111a 100644 --- a/test/t/typeerror.rb +++ b/test/t/typeerror.rb @@ -4,3 +4,8 @@ assert('TypeError', '15.2.29') do TypeError.class == Class end + +assert('TypeError superclass', '15.2.29.2') do + TypeError.superclass == StandardError +end + -- cgit v1.2.3 From cfd5f5157d06f9c62a04660843c3c02014d8a3a5 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Fri, 15 Jun 2012 13:06:43 +0900 Subject: Move Subclasses of ScriptError to mrblib. --- mrblib/error.rb | 8 ++++++++ src/error.c | 3 --- test/t/exception.rb | 30 ++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) (limited to 'test/t/exception.rb') diff --git a/mrblib/error.rb b/mrblib/error.rb index 3fa7f21e3..1cb2b1150 100644 --- a/mrblib/error.rb +++ b/mrblib/error.rb @@ -17,5 +17,13 @@ end class ScriptError < Exception end +# ISO 15.2.38 +class SyntaxError < ScriptError +end + +# ISO 15.2.39 +class LoadError < ScriptError +end + class NotImplementedError < ScriptError end diff --git a/src/error.c b/src/error.c index 548527f07..590fad5a5 100644 --- a/src/error.c +++ b/src/error.c @@ -385,9 +385,6 @@ mrb_init_exception(mrb_state *mrb) eNameError = mrb_define_class(mrb, "NameError", mrb->eStandardError_class); /* 15.2.31 */ mrb_define_class(mrb, "NoMethodError", eNameError); /* 15.2.32 */ - // eScriptError = mrb_define_class(mrb, "ScriptError", mrb->eException_class); /* 15.2.37 */ - // mrb_define_class(mrb, "SyntaxError", eScriptError); /* 15.2.38 */ - // mrb_define_class(mrb, "LoadError", eScriptError); /* 15.2.39 */ // mrb_define_class(mrb, "SystemCallError", mrb->eStandardError_class); /* 15.2.36 */ mrb_define_class(mrb, "LocalJumpError", mrb->eStandardError_class); /* 15.2.25 */ diff --git a/test/t/exception.rb b/test/t/exception.rb index 22795161f..d7226a368 100644 --- a/test/t/exception.rb +++ b/test/t/exception.rb @@ -41,6 +41,36 @@ assert('Exception.exception', '15.2.22.4.1') do e.message == 'a' end +assert('ScriptError', '15.2.37') do + begin + raise ScriptError.new + rescue ScriptError + true + else + false + end +end + +assert('SyntaxError', '15.2.38') do + begin + raise SyntaxError.new + rescue SyntaxError + true + else + false + end +end + +assert('LoadError', '15.2.39') do + begin + raise LoadError.new + rescue LoadError + true + else + false + end +end + # Not ISO specified assert('Exception 1') do -- cgit v1.2.3 From 39f47c191557ca401b6aaceb04b395227431b62f Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 15 Jun 2012 13:55:27 +0900 Subject: remove LoadError --- mrblib/error.rb | 4 ---- test/t/exception.rb | 12 +----------- 2 files changed, 1 insertion(+), 15 deletions(-) (limited to 'test/t/exception.rb') diff --git a/mrblib/error.rb b/mrblib/error.rb index 1cb2b1150..5d49ec1e4 100644 --- a/mrblib/error.rb +++ b/mrblib/error.rb @@ -21,9 +21,5 @@ end class SyntaxError < ScriptError end -# ISO 15.2.39 -class LoadError < ScriptError -end - class NotImplementedError < ScriptError end diff --git a/test/t/exception.rb b/test/t/exception.rb index d7226a368..0aed0e2e6 100644 --- a/test/t/exception.rb +++ b/test/t/exception.rb @@ -24,7 +24,7 @@ end assert('Exception#message', '15.2.22.5.2') do e = Exception.exception('a') - + e.message == 'a' end @@ -61,16 +61,6 @@ assert('SyntaxError', '15.2.38') do end end -assert('LoadError', '15.2.39') do - begin - raise LoadError.new - rescue LoadError - true - else - false - end -end - # Not ISO specified assert('Exception 1') do -- cgit v1.2.3