mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Intercept most exit calls and raise instead
This commit is contained in:
parent
3c9c7f88be
commit
754bfd6939
4 changed files with 43 additions and 15 deletions
|
@ -51,6 +51,7 @@ require "./runner_events"
|
|||
require "./runner"
|
||||
require "./spec_builder"
|
||||
require "./spec"
|
||||
require "./system_exit"
|
||||
require "./tag_node_filter"
|
||||
require "./test_context"
|
||||
require "./value"
|
||||
|
|
25
src/spectator/system_exit.cr
Normal file
25
src/spectator/system_exit.cr
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Spectator
|
||||
# Indicates a call to exit the application was performed.
|
||||
class SystemExit < Exception
|
||||
# Status code passed to the exit call.
|
||||
getter status : Int32
|
||||
|
||||
# Creates the exception.
|
||||
def initialize(message : String? = nil, cause : Exception? = nil, @status : Int32 = 0)
|
||||
super(message, cause)
|
||||
end
|
||||
end
|
||||
|
||||
# Allow Spectator to exit normally when needed.
|
||||
private def self.exit(status = 0) : NoReturn
|
||||
::Crystal::System::Process.exit(status)
|
||||
end
|
||||
end
|
||||
|
||||
class Process
|
||||
# Replace the typically used exit method with a method that raises.
|
||||
# This allows tests to catch attempts to exit the application.
|
||||
def self.exit(status = 0) : NoReturn
|
||||
raise ::Spectator::SystemExit.new(status: status)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue