diff options
author | Benoit Daloze <[email protected]> | 2022-03-28 17:47:04 +0200 |
---|---|---|
committer | Benoit Daloze <[email protected]> | 2022-03-28 17:47:04 +0200 |
commit | 8db4f25bf4327f169902afd9ea8f4b03b65656f0 (patch) | |
tree | ad61b99fb2d5ebfe9c07de8c2b5885e80d20b8e1 /spec/ruby/core/exception | |
parent | ae650f0372e10cea4d695769b1fcdc23a76fdf17 (diff) |
Update to ruby/spec@aaf998f
Diffstat (limited to 'spec/ruby/core/exception')
-rw-r--r-- | spec/ruby/core/exception/full_message_spec.rb | 40 | ||||
-rw-r--r-- | spec/ruby/core/exception/system_exit_spec.rb | 42 |
2 files changed, 71 insertions, 11 deletions
diff --git a/spec/ruby/core/exception/full_message_spec.rb b/spec/ruby/core/exception/full_message_spec.rb index 4cece9ebf9..9757a2f407 100644 --- a/spec/ruby/core/exception/full_message_spec.rb +++ b/spec/ruby/core/exception/full_message_spec.rb @@ -15,13 +15,19 @@ describe "Exception#full_message" do it "supports :highlight option and adds escape sequences to highlight some strings" do e = RuntimeError.new("Some runtime error") - full_message = e.full_message(highlight: true, order: :bottom) - full_message.should include "\e[1mTraceback\e[m (most recent call last)" - full_message.should include "\e[1mSome runtime error (\e[1;4mRuntimeError\e[m\e[1m)" + full_message = e.full_message(highlight: true, order: :top).lines + full_message[0].should.end_with? "\e[1mSome runtime error (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n" - full_message = e.full_message(highlight: false, order: :bottom) - full_message.should include "Traceback (most recent call last)" - full_message.should include "Some runtime error (RuntimeError)" + full_message = e.full_message(highlight: true, order: :bottom).lines + full_message[0].should == "\e[1mTraceback\e[m (most recent call last):\n" + full_message[-1].should.end_with? "\e[1mSome runtime error (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n" + + full_message = e.full_message(highlight: false, order: :top).lines + full_message[0].should.end_with? "Some runtime error (RuntimeError)\n" + + full_message = e.full_message(highlight: false, order: :bottom).lines + full_message[0].should == "Traceback (most recent call last):\n" + full_message[-1].should.end_with? "Some runtime error (RuntimeError)\n" end it "supports :order option and places the error message and the backtrace at the top or the bottom" do @@ -35,9 +41,9 @@ describe "Exception#full_message" do it "shows the caller if the exception has no backtrace" do e = RuntimeError.new("Some runtime error") e.backtrace.should == nil - full_message = e.full_message(highlight: false, order: :top) - full_message.should include("#{__FILE__}:#{__LINE__-1}:in `") - full_message.should include("': Some runtime error (RuntimeError)\n") + full_message = e.full_message(highlight: false, order: :top).lines + full_message[0].should.start_with?("#{__FILE__}:#{__LINE__-1}:in `") + full_message[0].should.end_with?("': Some runtime error (RuntimeError)\n") end it "shows the exception class at the end of the first line of the message when the message contains multiple lines" do @@ -45,12 +51,24 @@ describe "Exception#full_message" do line = __LINE__; raise "first line\nsecond line" rescue => e full_message = e.full_message(highlight: false, order: :top).lines - full_message[0].should include("#{__FILE__}:#{line}:in `") - full_message[0].should include(": first line (RuntimeError)\n") + full_message[0].should.start_with?("#{__FILE__}:#{line}:in `") + full_message[0].should.end_with?(": first line (RuntimeError)\n") full_message[1].should == "second line\n" end end + it "highlights the entire message when the message contains multiple lines" do + begin + line = __LINE__; raise "first line\nsecond line\nthird line" + rescue => e + full_message = e.full_message(highlight: true, order: :top).lines + full_message[0].should.start_with?("#{__FILE__}:#{line}:in `") + full_message[0].should.end_with?(": \e[1mfirst line (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n") + full_message[1].should == "\e[1msecond line\e[m\n" + full_message[2].should == "\e[1mthird line\e[m\n" + end + end + it "contains cause of exception" do begin begin diff --git a/spec/ruby/core/exception/system_exit_spec.rb b/spec/ruby/core/exception/system_exit_spec.rb index eef9faf271..d899844c4e 100644 --- a/spec/ruby/core/exception/system_exit_spec.rb +++ b/spec/ruby/core/exception/system_exit_spec.rb @@ -1,6 +1,48 @@ require_relative '../../spec_helper' describe "SystemExit" do + describe "#initialize" do + it "accepts a status and message" do + exc = SystemExit.new(42, "message") + exc.status.should == 42 + exc.message.should == "message" + + exc = SystemExit.new(true, "message") + exc.status.should == 0 + exc.message.should == "message" + + exc = SystemExit.new(false, "message") + exc.status.should == 1 + exc.message.should == "message" + end + + it "accepts a status only" do + exc = SystemExit.new(42) + exc.status.should == 42 + exc.message.should == "SystemExit" + + exc = SystemExit.new(true) + exc.status.should == 0 + exc.message.should == "SystemExit" + + exc = SystemExit.new(false) + exc.status.should == 1 + exc.message.should == "SystemExit" + end + + it "accepts a message only" do + exc = SystemExit.new("message") + exc.status.should == 0 + exc.message.should == "message" + end + + it "accepts no arguments" do + exc = SystemExit.new + exc.status.should == 0 + exc.message.should == "SystemExit" + end + end + it "sets the exit status and exits silently when raised" do code = 'raise SystemExit.new(7)' result = ruby_exe(code, args: "2>&1", exit_status: 7) |