1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Add C interface spec.

This commit is contained in:
Samuel Williams 2021-09-20 14:19:52 +12:00
parent 88ba5fe547
commit 649c87bd86
Notes: git 2021-09-20 15:31:11 +09:00
2 changed files with 49 additions and 0 deletions

View file

@ -44,6 +44,13 @@ VALUE fiber_spec_rb_fiber_new(VALUE self) {
return rb_fiber_new(fiber_spec_rb_fiber_new_function, Qnil);
}
#ifdef RUBY_VERSION_IS_3_1
VALUE fiber_spec_rb_fiber_raise(int argc, VALUE *argv, VALUE self) {
VALUE fiber = argv[0];
return rb_fiber_raise(fiber, argc-1, argv+1);
}
#endif
void Init_fiber_spec(void) {
VALUE cls = rb_define_class("CApiFiberSpecs", rb_cObject);
rb_define_method(cls, "rb_fiber_current", fiber_spec_rb_fiber_current, 0);
@ -51,6 +58,10 @@ void Init_fiber_spec(void) {
rb_define_method(cls, "rb_fiber_resume", fiber_spec_rb_fiber_resume, 2);
rb_define_method(cls, "rb_fiber_yield", fiber_spec_rb_fiber_yield, 1);
rb_define_method(cls, "rb_fiber_new", fiber_spec_rb_fiber_new, 0);
#ifdef RUBY_VERSION_IS_3_1
rb_define_method(cls, "rb_fiber_raise", fiber_spec_rb_fiber_raise, -1);
#endif
}
#ifdef __cplusplus

View file

@ -48,4 +48,42 @@ describe "C-API Fiber function" do
fiber.resume(42).should == "42"
end
end
describe "rb_fiber_raise" do
ruby_version_is '3.1' do
it "raises an exception on the resumed fiber" do
fiber = Fiber.new do
begin
Fiber.yield
rescue => error
error
end
end
fiber.resume
result = @s.rb_fiber_raise(fiber, "Boom!")
result.should be_an_instance_of(RuntimeError)
result.message.should == "Boom!"
end
it "raises an exception on the transferred fiber" do
main = Fiber.current
fiber = Fiber.new do
begin
main.transfer
rescue => error
error
end
end
fiber.transfer
result = @s.rb_fiber_raise(fiber, "Boom!")
result.should be_an_instance_of(RuntimeError)
result.message.should == "Boom!"
end
end
end
end