From 5c2afd239c527be5d4117dfaea14902450937ac3 Mon Sep 17 00:00:00 2001 From: Akira Kuroda Date: Sun, 30 Sep 2012 17:25:50 +0900 Subject: add test case for Array#unshift, <=>, and * --- test/t/array.rb | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'test/t') diff --git a/test/t/array.rb b/test/t/array.rb index cb99cea6a..560faf8e7 100644 --- a/test/t/array.rb +++ b/test/t/array.rb @@ -14,7 +14,17 @@ assert('Array.[]', '15.2.12.4.1') do end assert('Array#*', '15.2.12.5.1') do - [1].*(3) == [1, 1, 1] + e2 = nil + begin + # this will cause an exception due to the wrong argument + [1].*(-1) + rescue => e1 + e2 = e1 + end + a = [1].*(3) + b = [1].*(0) + a == [1, 1, 1] and b == [] and + e2.class == ArgumentError end assert('Array#+', '15.2.12.5.2') do @@ -256,8 +266,10 @@ end assert('Array#unshift', '15.2.12.5.30') do a = [2,3] b = a.unshift(1) + c = [2,3] + d = c.unshift(0, 1) - a == [1,2,3] and b == [1,2,3] + a == [1,2,3] and b == [1,2,3] and c == [0,1,2,3] and d == [0,1,2,3] end assert('Array#to_s', '15.2.12.5.31') do @@ -279,8 +291,9 @@ end assert('Array#<=>', '15.2.12.5.36') do r1 = [ "a", "a", "c" ] <=> [ "a", "b", "c" ] #=> -1 r2 = [ 1, 2, 3, 4, 5, 6 ] <=> [ 1, 2 ] #=> +1 + r3 = [ "a", "b", "c" ] <=> [ "a", "b", "c" ] #=> 0 - r1 == -1 and r2 == +1 + r1 == -1 and r2 == +1 and r3 == 0 end # Not ISO specified -- cgit v1.2.3 From 8949e3c7fb964e58d1666e9dba20c575e553b479 Mon Sep 17 00:00:00 2001 From: Beoran Date: Tue, 9 Oct 2012 21:45:41 +0200 Subject: Bugfix for crash if main was extended with a module. --- src/class.c | 2 ++ test/t/kernel.rb | 10 ++++++++++ 2 files changed, 12 insertions(+) (limited to 'test/t') diff --git a/src/class.c b/src/class.c index fad476929..a73f42566 100644 --- a/src/class.c +++ b/src/class.c @@ -786,6 +786,8 @@ mrb_singleton_class(mrb_state *mrb, mrb_value v) return mrb_obj_value(mrb->false_class); case MRB_TT_TRUE: return mrb_obj_value(mrb->true_class); + case MRB_TT_MAIN: + return mrb_obj_value(mrb->object_class); case MRB_TT_SYMBOL: case MRB_TT_FIXNUM: case MRB_TT_FLOAT: diff --git a/test/t/kernel.rb b/test/t/kernel.rb index fb0aee310..5caa3d7ac 100644 --- a/test/t/kernel.rb +++ b/test/t/kernel.rb @@ -204,6 +204,16 @@ assert('Kernel#extend', '15.3.1.3.13') do a.respond_to?(:test_method) == true && b.respond_to?(:test_method) == false end +assert('Kernel#extend works on toplevel', '15.3.1.3.13') do + module Test4ExtendModule + def test_method; end + end + # This would crash... + extend(Test4ExtendModule) + + respond_to?(:test_method) == true +end + assert('Kernel#global_variables', '15.3.1.3.14') do global_variables.class == Array end -- cgit v1.2.3 From 89a18e4f22de80b836f9d6c3167d71b7078a31bb Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sat, 20 Oct 2012 03:59:13 +0900 Subject: unexpect break/next/redo/retry should raise LocalJumpError --- src/codegen.c | 2 +- src/vm.c | 8 +++++++- test/t/localjumperror.rb | 7 ++++++- test/t/runtimeerror.rb | 10 +--------- 4 files changed, 15 insertions(+), 12 deletions(-) (limited to 'test/t') diff --git a/src/codegen.c b/src/codegen.c index 19a5835fa..2482209cc 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -911,7 +911,7 @@ raise_error(codegen_scope *s, const char *msg) { int idx = new_lit(s, mrb_str_new_cstr(s->mrb, msg)); - genop(s, MKOP_ABx(OP_ERR, 0, idx)); + genop(s, MKOP_ABx(OP_ERR, 1, idx)); } static double diff --git a/src/vm.c b/src/vm.c index a779565be..a68d089cc 100644 --- a/src/vm.c +++ b/src/vm.c @@ -1817,8 +1817,14 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) CASE(OP_ERR) { /* Bx raise RuntimeError with message Lit(Bx) */ mrb_value msg = pool[GETARG_Bx(i)]; - mrb_value exc = mrb_exc_new3(mrb, E_RUNTIME_ERROR, msg); + mrb_value exc; + if (GETARG_A(i) == 0) { + exc = mrb_exc_new3(mrb, E_RUNTIME_ERROR, msg); + } + else { + exc = mrb_exc_new3(mrb, E_LOCALJUMP_ERROR, msg); + } mrb->exc = (struct RObject*)mrb_object(exc); goto L_RAISE; } diff --git a/test/t/localjumperror.rb b/test/t/localjumperror.rb index 9d1df9594..ebcec0670 100644 --- a/test/t/localjumperror.rb +++ b/test/t/localjumperror.rb @@ -2,7 +2,12 @@ # LocalJumpError ISO Test assert('LocalJumoError', '15.2.25') do - LocalJumpError.class == Class + begin + # this will cause an exception due to the wrong location + retry + rescue => e1 + end + LocalJumpError.class == Class and e1.class == LocalJumpError end # TODO 15.2.25.2.1 LocalJumpError#exit_value diff --git a/test/t/runtimeerror.rb b/test/t/runtimeerror.rb index 9157293cd..3e0636186 100644 --- a/test/t/runtimeerror.rb +++ b/test/t/runtimeerror.rb @@ -2,13 +2,5 @@ # RuntimeError ISO Test assert('RuntimeError', '15.2.28') do - e2 = nil - begin - # this will cause an exception due to the wrong location - retry - rescue => e1 - e2 = e1 - end - - RuntimeError.class == Class and e2.class == RuntimeError + RuntimeError.class == Class end -- cgit v1.2.3 From f166f63f452d21c55a860d26a57b2f815f5c96f2 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Sat, 20 Oct 2012 08:50:51 +0900 Subject: add test case for 750b7c2 --- test/t/exception.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'test/t') diff --git a/test/t/exception.rb b/test/t/exception.rb index 76c165e95..aa707c1b1 100644 --- a/test/t/exception.rb +++ b/test/t/exception.rb @@ -30,7 +30,7 @@ end assert('Exception#to_s', '15.2.22.5.3') do e = Exception.exception('a') - + e.to_s == 'a' end @@ -269,6 +269,24 @@ assert('Exception 14') do a == :ok end +assert('Exception 15') do + a = begin + :ok + rescue + :ng + end + a == :ok +end + +assert('Exception 16') do + begin + raise "foo" + false + rescue => e + e.message == "foo" + end +end + assert('Exception#inspect without message') do Exception.new.inspect end -- cgit v1.2.3