From e2cdc9e08ebd8e3faf3e3d558e5aaa140ef9f879 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 4 Nov 2022 22:10:59 -0600 Subject: [PATCH] Re-enable logger after catching exit The logger is closed during at-exit hooks that get invoked by Kernel's exit method. --- CHANGELOG.md | 1 + src/spectator/system_exit.cr | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0835bcb..4b1bbed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Clear stubs defined with `expect().to receive()` syntax after test finishes to prevent leakage between tests. - Ensure stubs defined with `allow().to receive()` syntax are cleared after test finishes when used inside a test (another leakage). +- Fix crash caused when logging is enabled after running an example that attempts to exit. ### Removed - Removed support for stubbing undefined (untyped) methods in lazy doubles. Avoids possible segfault. diff --git a/src/spectator/system_exit.cr b/src/spectator/system_exit.cr index 95a2b22..d94711e 100644 --- a/src/spectator/system_exit.cr +++ b/src/spectator/system_exit.cr @@ -20,6 +20,9 @@ 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 + # Re-enable log that is disabled from at-exit handlers. + ::Log.setup_from_env(default_level: :none) + raise ::Spectator::SystemExit.new(status: status) end end