Skip to content

Commit

Permalink
Refactor Spec.run to macro finished
Browse files Browse the repository at this point in the history
This should be largely equivalent to the current solution with `at_exit`
but more robust because it does not conflict with libraries' `at_exit`
handlers.
  • Loading branch information
straight-shoota committed Dec 20, 2023
1 parent 667fbf1 commit 7f2ee51
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
7 changes: 6 additions & 1 deletion src/spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,9 @@ Spec.add_split_filter ENV["SPEC_SPLIT"]?
Process.on_interrupt { Spec.abort! }
{% end %}

Spec.run
# The spec suite should run as last thing in the program. This enables other
# top-level code (for example library configuration) to run before the spec
# suite starts.
macro finished
Spec.run
end
29 changes: 12 additions & 17 deletions src/spec/dsl.cr
Original file line number Diff line number Diff line change
Expand Up @@ -205,24 +205,19 @@ module Spec
def self.run
@@start_time = Time.monotonic

at_exit do |status|
# Do not run specs if the process is exiting on an error
next unless status == 0

begin
if Spec.list_tags?
execute_list_tags
else
execute_examples
end
rescue ex
STDERR.print "Unhandled exception: "
ex.inspect_with_backtrace(STDERR)
STDERR.flush
@@aborted = true
ensure
finish_run unless Spec.list_tags?
begin
if Spec.list_tags?
execute_list_tags
else
execute_examples
end
rescue ex
STDERR.print "Unhandled exception: "
ex.inspect_with_backtrace(STDERR)
STDERR.flush
@@aborted = true
ensure
finish_run unless Spec.list_tags?
end
end

Expand Down

0 comments on commit 7f2ee51

Please sign in to comment.