diff options
author | Benoit Daloze <eregontp@gmail.com> | 2021-03-27 13:02:41 +0100 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2021-03-27 13:02:41 +0100 |
commit | 95d9fe9538441eb57ee6752aa1c5088fc6608e34 (patch) | |
tree | 9a0bb070fd8042b83470f7a0bf9cd462c919c7c0 /spec/ruby/optional | |
parent | 44736a6b7a2b3475db2d05187f33e3c1a7b4b4e5 (diff) | |
download | ruby-95d9fe9538441eb57ee6752aa1c5088fc6608e34.tar.gz |
Update to ruby/spec@fd6eddd
Diffstat (limited to 'spec/ruby/optional')
-rw-r--r-- | spec/ruby/optional/capi/ext/kernel_spec.c | 9 | ||||
-rw-r--r-- | spec/ruby/optional/capi/ext/module_spec.c | 31 | ||||
-rw-r--r-- | spec/ruby/optional/capi/kernel_spec.rb | 8 | ||||
-rw-r--r-- | spec/ruby/optional/capi/module_spec.rb | 20 |
4 files changed, 67 insertions, 1 deletions
diff --git a/spec/ruby/optional/capi/ext/kernel_spec.c b/spec/ruby/optional/capi/ext/kernel_spec.c index a1960a2fe7..bbfeb198b7 100644 --- a/spec/ruby/optional/capi/ext/kernel_spec.c +++ b/spec/ruby/optional/capi/ext/kernel_spec.c @@ -191,6 +191,14 @@ static VALUE kernel_spec_rb_protect_yield(VALUE self, VALUE obj, VALUE ary) { return res; } +static VALUE kernel_spec_rb_protect_errinfo(VALUE self, VALUE obj, VALUE ary) { + int status = 0; + VALUE res = rb_protect(rb_yield, obj, &status); + rb_ary_store(ary, 0, INT2NUM(23)); + rb_ary_store(ary, 1, res); + return rb_errinfo(); +} + static VALUE kernel_spec_rb_protect_null_status(VALUE self, VALUE obj) { return rb_protect(rb_yield, obj, NULL); } @@ -345,6 +353,7 @@ void Init_kernel_spec(void) { rb_define_method(cls, "rb_rescue", kernel_spec_rb_rescue, 4); rb_define_method(cls, "rb_rescue2", kernel_spec_rb_rescue2, -1); rb_define_method(cls, "rb_protect_yield", kernel_spec_rb_protect_yield, 2); + rb_define_method(cls, "rb_protect_errinfo", kernel_spec_rb_protect_errinfo, 2); rb_define_method(cls, "rb_protect_null_status", kernel_spec_rb_protect_null_status, 1); rb_define_method(cls, "rb_eval_string_protect", kernel_spec_rb_eval_string_protect, 2); rb_define_method(cls, "rb_catch", kernel_spec_rb_catch, 2); diff --git a/spec/ruby/optional/capi/ext/module_spec.c b/spec/ruby/optional/capi/ext/module_spec.c index 3c8455a942..7475994fa1 100644 --- a/spec/ruby/optional/capi/ext/module_spec.c +++ b/spec/ruby/optional/capi/ext/module_spec.c @@ -9,6 +9,18 @@ static VALUE module_specs_test_method(VALUE self) { return ID2SYM(rb_intern("test_method")); } +static VALUE module_specs_test_method_2required(VALUE self, VALUE arg1, VALUE arg2) { + return ID2SYM(rb_intern("test_method_2required")); +} + +static VALUE module_specs_test_method_c_array(int argc, VALUE *argv, VALUE self) { + return ID2SYM(rb_intern("test_method_c_array")); +} + +static VALUE module_specs_test_method_ruby_array(VALUE self, VALUE args) { + return ID2SYM(rb_intern("test_method_ruby_array")); +} + static VALUE module_specs_const_defined(VALUE self, VALUE klass, VALUE id) { return rb_const_defined(klass, SYM2ID(id)) ? Qtrue : Qfalse; } @@ -76,6 +88,21 @@ static VALUE module_specs_rb_define_method(VALUE self, VALUE cls, VALUE str_name return Qnil; } +static VALUE module_specs_rb_define_method_2required(VALUE self, VALUE cls, VALUE str_name) { + rb_define_method(cls, RSTRING_PTR(str_name), module_specs_test_method_2required, 2); + return Qnil; +} + +static VALUE module_specs_rb_define_method_c_array(VALUE self, VALUE cls, VALUE str_name) { + rb_define_method(cls, RSTRING_PTR(str_name), module_specs_test_method_c_array, -1); + return Qnil; +} + +static VALUE module_specs_rb_define_method_ruby_array(VALUE self, VALUE cls, VALUE str_name) { + rb_define_method(cls, RSTRING_PTR(str_name), module_specs_test_method_ruby_array, -2); + return Qnil; +} + static VALUE module_specs_rb_define_module_function(VALUE self, VALUE cls, VALUE str_name) { rb_define_module_function(cls, RSTRING_PTR(str_name), module_specs_test_method, 0); return Qnil; @@ -132,6 +159,10 @@ void Init_module_spec(void) { module_specs_rb_define_global_function, 1); rb_define_method(cls, "rb_define_method", module_specs_rb_define_method, 2); + rb_define_method(cls, "rb_define_method_2required", module_specs_rb_define_method_2required, 2); + rb_define_method(cls, "rb_define_method_c_array", module_specs_rb_define_method_c_array, 2); + rb_define_method(cls, "rb_define_method_ruby_array", module_specs_rb_define_method_ruby_array, 2); + rb_define_method(cls, "rb_define_module_function", module_specs_rb_define_module_function, 2); diff --git a/spec/ruby/optional/capi/kernel_spec.rb b/spec/ruby/optional/capi/kernel_spec.rb index ab66f7fa9e..758d944da9 100644 --- a/spec/ruby/optional/capi/kernel_spec.rb +++ b/spec/ruby/optional/capi/kernel_spec.rb @@ -312,6 +312,14 @@ describe "C-API Kernel function" do @s.rb_protect_null_status(42) { |x| x + 1 }.should == 43 @s.rb_protect_null_status(42) { |x| raise }.should == nil end + + it "populates errinfo with the captured exception" do + proof = [] + @s.rb_protect_errinfo(77, proof) { |x| raise NameError }.class.should == NameError + proof[0].should == 23 + proof[1].should == nil + end + end describe "rb_eval_string_protect" do diff --git a/spec/ruby/optional/capi/module_spec.rb b/spec/ruby/optional/capi/module_spec.rb index 750d64367d..acf4d1fe48 100644 --- a/spec/ruby/optional/capi/module_spec.rb +++ b/spec/ruby/optional/capi/module_spec.rb @@ -246,12 +246,30 @@ describe "CApiModule" do cls.new.test_method.should == :test_method end - it "returns the correct arity of the method in class" do + it "returns the correct arity when argc of the method in class is 0" do cls = Class.new @m.rb_define_method(cls, "test_method") cls.new.method(:test_method).arity.should == 0 end + it "returns the correct arity when argc of the method in class is -1" do + cls = Class.new + @m.rb_define_method_c_array(cls, "test_method_c_array") + cls.new.method(:test_method_c_array).arity.should == -1 + end + + it "returns the correct arity when argc of the method in class is -2" do + cls = Class.new + @m.rb_define_method_ruby_array(cls, "test_method_ruby_array") + cls.new.method(:test_method_ruby_array).arity.should == -1 + end + + it "returns the correct arity when argc of the method in class is 2" do + cls = Class.new + @m.rb_define_method_2required(cls, "test_method_2required") + cls.new.method(:test_method_2required).arity.should == 2 + end + it "defines a method on a module" do mod = Module.new @m.rb_define_method(mod, "test_method") |