From edb18dcf956dd3399b2fb4b3d95cec4ca231578d Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Thu, 27 May 2021 15:17:27 -0600 Subject: [PATCH] Fix for default logger being cleaned up before Spectator runs Resolves https://github.com/icy-arctic-fox/spectator/issues/27 --- src/spectator.cr | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/spectator.cr b/src/spectator.cr index 73a56d5..bdc324e 100644 --- a/src/spectator.cr +++ b/src/spectator.cr @@ -98,8 +98,21 @@ module Spectator config.random end + # Trick for detecting if a constant is defined. + # Includes the block of code if the *constant* is defined. + private macro on_defined(constant) + {% if constant.resolve? %} + {{yield}} + {% end %} + end + # Builds the tests and runs the framework. private def run + # Silence default logger, only if it's used somewhere in the program. + on_defined(::Log) do + ::Log.setup_from_env(default_level: :none) + end + # Build the test suite and run it. suite = ::Spectator::SpecBuilder.build(config.example_filter) Runner.new(suite, config).run