diff options
author | Benoit Daloze <[email protected]> | 2020-02-28 19:07:17 +0100 |
---|---|---|
committer | Benoit Daloze <[email protected]> | 2020-02-28 19:07:17 +0100 |
commit | a0f5ff4c3cd05f8717be2bf1d79f0817f288d398 (patch) | |
tree | 441f409cf816cf8a61dacdbaf204ae9f5cbe2f18 /spec/ruby/optional/capi/kernel_spec.rb | |
parent | 5d210501825e1682e68cbfc2be424fc339f382fa (diff) |
Update to ruby/spec@41bf282
Diffstat (limited to 'spec/ruby/optional/capi/kernel_spec.rb')
-rw-r--r-- | spec/ruby/optional/capi/kernel_spec.rb | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/spec/ruby/optional/capi/kernel_spec.rb b/spec/ruby/optional/capi/kernel_spec.rb index c6fddc3f64..5c272947ab 100644 --- a/spec/ruby/optional/capi/kernel_spec.rb +++ b/spec/ruby/optional/capi/kernel_spec.rb @@ -261,28 +261,28 @@ describe "C-API Kernel function" do describe "rb_protect" do it "will run a function with an argument" do proof = [] # Hold proof of work performed after the yield. - res = @s.rb_protect_yield(7, proof) { |x| x + 1 } - res.should == 8 + res = @s.rb_protect_yield(77, proof) { |x| x + 1 } + res.should == 78 proof[0].should == 23 end it "will allow cleanup code to run after break" do proof = [] # Hold proof of work performed after the yield. - @s.rb_protect_yield(7, proof) { |x| break } + @s.rb_protect_yield(77, proof) { |x| break } proof[0].should == 23 end it "will allow cleanup code to run after break with value" do proof = [] # Hold proof of work performed after the yield. - res = @s.rb_protect_yield(7, proof) { |x| break x + 1 } - res.should == 8 + res = @s.rb_protect_yield(77, proof) { |x| break x + 1 } + res.should == 78 proof[0].should == 23 end it "will allow cleanup code to run after a raise" do proof = [] # Hold proof of work performed after the yield. -> do - @s.rb_protect_yield(7, proof) { |x| raise NameError} + @s.rb_protect_yield(77, proof) { |x| raise NameError} end.should raise_error(NameError) proof[0].should == 23 end @@ -290,7 +290,7 @@ describe "C-API Kernel function" do it "will return nil if an error was raised" do proof = [] # Hold proof of work performed after the yield. -> do - @s.rb_protect_yield(7, proof) { |x| raise NameError} + @s.rb_protect_yield(77, proof) { |x| raise NameError} end.should raise_error(NameError) proof[0].should == 23 proof[1].should == nil @@ -316,47 +316,47 @@ describe "C-API Kernel function" do describe "rb_rescue" do before :each do @proc = -> x { x } - @raise_proc_returns_sentinel = -> *_ { :raise_proc_executed } - @raise_proc_returns_arg = -> *a { a } + @rescue_proc_returns_sentinel = -> *_ { :rescue_proc_executed } + @rescue_proc_returns_arg = -> *a { a } @arg_error_proc = -> *_ { raise ArgumentError, '' } @std_error_proc = -> *_ { raise StandardError, '' } @exc_error_proc = -> *_ { raise Exception, '' } end it "executes passed function" do - @s.rb_rescue(@proc, :no_exc, @raise_proc_returns_arg, :exc).should == :no_exc + @s.rb_rescue(@proc, :no_exc, @rescue_proc_returns_arg, :exc).should == :no_exc end - it "executes passed 'raise function' if a StandardError exception is raised" do - @s.rb_rescue(@arg_error_proc, nil, @raise_proc_returns_sentinel, :exc).should == :raise_proc_executed - @s.rb_rescue(@std_error_proc, nil, @raise_proc_returns_sentinel, :exc).should == :raise_proc_executed + it "executes the passed 'rescue function' if a StandardError exception is raised" do + @s.rb_rescue(@arg_error_proc, nil, @rescue_proc_returns_sentinel, :exc).should == :rescue_proc_executed + @s.rb_rescue(@std_error_proc, nil, @rescue_proc_returns_sentinel, :exc).should == :rescue_proc_executed end - it "passes the user supplied argument to the 'raise function' if a StandardError exception is raised" do - arg1, _ = @s.rb_rescue(@arg_error_proc, nil, @raise_proc_returns_arg, :exc1) + it "passes the user supplied argument to the 'rescue function' if a StandardError exception is raised" do + arg1, _ = @s.rb_rescue(@arg_error_proc, nil, @rescue_proc_returns_arg, :exc1) arg1.should == :exc1 - arg2, _ = @s.rb_rescue(@std_error_proc, nil, @raise_proc_returns_arg, :exc2) + arg2, _ = @s.rb_rescue(@std_error_proc, nil, @rescue_proc_returns_arg, :exc2) arg2.should == :exc2 end - it "passes the raised exception to the 'raise function' if a StandardError exception is raised" do - _, exc1 = @s.rb_rescue(@arg_error_proc, nil, @raise_proc_returns_arg, :exc) + it "passes the raised exception to the 'rescue function' if a StandardError exception is raised" do + _, exc1 = @s.rb_rescue(@arg_error_proc, nil, @rescue_proc_returns_arg, :exc) exc1.class.should == ArgumentError - _, exc2 = @s.rb_rescue(@std_error_proc, nil, @raise_proc_returns_arg, :exc) + _, exc2 = @s.rb_rescue(@std_error_proc, nil, @rescue_proc_returns_arg, :exc) exc2.class.should == StandardError end it "raises an exception if passed function raises an exception other than StandardError" do - -> { @s.rb_rescue(@exc_error_proc, nil, @raise_proc_returns_arg, nil) }.should raise_error(Exception) + -> { @s.rb_rescue(@exc_error_proc, nil, @rescue_proc_returns_arg, nil) }.should raise_error(Exception) end - it "raises an exception if any exception is raised inside 'raise function'" do + it "raises an exception if any exception is raised inside the 'rescue function'" do -> { @s.rb_rescue(@std_error_proc, nil, @std_error_proc, nil) }.should raise_error(StandardError) end - it "makes $! available only during 'raise function' execution" do + it "makes $! available only during the 'rescue function' execution" do @s.rb_rescue(@std_error_proc, nil, -> *_ { $! }, nil).class.should == StandardError $!.should == nil end @@ -368,6 +368,10 @@ describe "C-API Kernel function" do proc_caller { break :value }.should == :value end + + it "returns nil if the 'rescue function' is null" do + @s.rb_rescue(@std_error_proc, nil, nil, nil).should == nil + end end describe "rb_rescue2" do |