Skip to content

[Kernel] Add tests for Exiting and Exception functions - #2684

Merged
soutaro merged 2 commits into
ruby:masterfrom
sampersand:sampersand/2025-10-17/exiting-and-exceptions
Feb 12, 2026
Merged

[Kernel] Add tests for Exiting and Exception functions#2684
soutaro merged 2 commits into
ruby:masterfrom
sampersand:sampersand/2025-10-17/exiting-and-exceptions

Conversation

@sampersand

@sampersand sampersand commented Oct 18, 2025

Copy link
Copy Markdown
Contributor

This PR adds tests for Kernel.{abort,exit,exit!,at_exit} and Kernel.{throw,catch,raise,fail}, as well as slightly tweaking the fail signature.

Additionally, it adds in the assert_send_type_error method (which is just a direct copy of assert_send_type, but accepts a type as the second argument)

@sampersand
sampersand force-pushed the sampersand/2025-10-17/exiting-and-exceptions branch 2 times, most recently from 2789ea5 to 49593f8 Compare October 18, 2025 02:09
@sampersand
sampersand marked this pull request as ready for review October 18, 2025 02:10

@ksss ksss left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking for a value like SystemExit rather than a type seems to be testing behavior, not the type.

@sampersand

Copy link
Copy Markdown
Contributor Author

Checking for a value like SystemExit rather than a type seems to be testing behavior, not the type.

The idea is to make sure that the exception that was thrown was one we expected from exit, not something like ArgumentError/TypeError caused by invalid arguments

Comment thread core/kernel.rbs
def self?.fail: () -> bot
| (string message, ?cause: Exception?) -> bot
| (_Exception exception, ?_ToS? message, ?String | Array[String] | Array[Thread::Backtrace::Location] | nil backtrace, ?cause: Exception?) -> bot
| (_Exception exception, ?string | _ToS message, ?String | Array[String] | Array[Thread::Backtrace::Location] | nil backtrace, ?cause: Exception?) -> bot

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why we need this fix on the argument type?
It looks like _ToS message would be fine technically.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#to_str is used if #to_s is not defined.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other way around—it tries to_str first:

class Foo
  def to_s = "to_s!"
  def to_str = "to_str!"
end

fail RuntimeError, Foo.new #=> -e:6:in '<main>': to_str! (RuntimeError)

@sampersand
sampersand force-pushed the sampersand/2025-10-17/exiting-and-exceptions branch from 49593f8 to 052b14f Compare February 4, 2026 05:42

@soutaro soutaro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@soutaro
soutaro merged commit e383373 into ruby:master Feb 12, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants