1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
# frozen_string_literal: true
# - show current backtrace when interrupting a stuck test with Ctrl+c
# - skip remaining tests
module Maxitest
Interrupted = Class.new(StandardError)
class << self
attr_accessor :interrupted
end
module InterruptHandler
# capture interrupt and treat it as a regular error so we get a backtrace
def capture_exceptions(&block)
super(&block)
rescue Interrupt => e
Maxitest.interrupted = true
failures << Minitest::UnexpectedError.new(e)
end
# skip remaining tests if we were interrupted
def run
if Maxitest.interrupted
# produce a real error so we do not crash in -v mode
failures <<
begin
raise Minitest::Skip, 'Maxitest::Interrupted'
rescue Minitest::Skip
$!
end
result = Minitest::Result.from(self)
result.time = 0
result
else
super()
end
end
end
end
Minitest::Test.prepend(Maxitest::InterruptHandler)
|