From 87ca825845221411fa8e99db0360798e14e9d0e6 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 22 Feb 2019 16:54:36 -0700 Subject: [PATCH] Return 1 on failure --- src/spectator.cr | 6 ++++-- src/spectator/runner.cr | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/spectator.cr b/src/spectator.cr index 10d426e..5d50dea 100644 --- a/src/spectator.cr +++ b/src/spectator.cr @@ -69,7 +69,9 @@ module Spectator # Crystal doesn't display much information about what happened. # That issue is handled by putting a begin/rescue block to show a custom error message. at_exit do - run if autorun? + # Run only if `#autorun?` is true. + # Return 1 on failure. + exit(1) if autorun? && !run end @@config_builder = ConfigBuilder.new @@ -94,7 +96,7 @@ module Spectator # it's likely the fault of the test framework (Spectator). # So we display a helpful error that could be reported and return non-zero. display_error_stack(ex) - exit(1) + false end # Processes and builds up a configuration to use for running tests. diff --git a/src/spectator/runner.cr b/src/spectator/runner.cr index 49c2a34..968227d 100644 --- a/src/spectator/runner.cr +++ b/src/spectator/runner.cr @@ -9,7 +9,9 @@ module Spectator # Runs the test suite. # This will run the selected examples # and invoke the formatter to output results. - def run : Nil + # True will be returned if the test suite ran successfully, + # or false if there was at least one failure. + def run : Bool # Indicate the suite is starting. @config.formatter.start_suite(@suite) @@ -24,6 +26,8 @@ module Spectator # Generate a report and pass it along to the formatter. report = Report.new(results, elapsed) @config.formatter.end_suite(report) + + !report.failed? end # Runs a single example and returns the result.