Module: Mutineer::MinitestIntegration::StopAtFirstFailure

Extended by:
OuterReporter::Client
Defined in:
lib/mutineer/minitest_integration/stop_at_first_failure.rb

Overview

Stops a Minitest run at the first failing test: one failure already kills the mutant. Child-process only, like MinitestIntegration.

It sets a flag instead of unwinding the stack, so that class-level wrappers (after_all, a block-form transaction) still finish. The remaining tests and classes then return before they start.

Minitest 5 and 6 need different hook points. An unknown shape installs no hook, and the run is a full run. The outer reporter comes from OuterReporter, shared with KillRecorder.

Defined Under Namespace

Modules: RecordFailure, SkipAfterStop5, SkipAfterStop6

Class Attribute Summary collapse

Attributes included from OuterReporter::Client

#armed_pid, #armed_reporter

Class Method Summary collapse

Methods included from OuterReporter::Client

armed_here?, outer_reporter?

Class Attribute Details

.stopped ⇒ Boolean?

True after the outer reporter records a failure or an error.

Returns:

  • (Boolean, nil)


93
94
95
# File 'lib/mutineer/minitest_integration/stop_at_first_failure.rb', line 93

def stopped
  @stopped
end

Class Method Details

.arm!(runnables) ⇒ Boolean

Installs the hooks and arms the stop for this process. Call it after the test files load, so that every test class gets its prepend.

Parameters:

  • runnables (Array<Class>) —

    the loaded test classes.

Returns:

  • (Boolean) —

    false when the Minitest shape is unknown.



100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/mutineer/minitest_integration/stop_at_first_failure.rb', line 100

def arm!(runnables)
  outer, skip = hooks_for_loaded_minitest
  return false unless outer

  OuterReporter.prepend_once(::Minitest::CompositeReporter, RecordFailure)
  OuterReporter.prepend_once(::Minitest.singleton_class, outer)
  runnables.each { |klass| OuterReporter.prepend_once(klass.singleton_class, skip) }
  OuterReporter.register(self)
  self.armed_pid = Process.pid
  self.armed_reporter = nil
  self.stopped = false
  true
end

.disarm! ⇒ void

This method returns an undefined value.

Clears the armed state.



117
118
119
120
121
# File 'lib/mutineer/minitest_integration/stop_at_first_failure.rb', line 117

def disarm!
  self.armed_pid = nil
  self.armed_reporter = nil
  self.stopped = false
end

.hooks_for_loaded_minitest ⇒ Array(Module, Module)? (private)

Picks the hook modules for the loaded Minitest.

Returns:

  • (Array(Module, Module), nil) —

    the outer reporter hook and the skip hook, or nil for an unknown shape.



136
137
138
139
140
141
# File 'lib/mutineer/minitest_integration/stop_at_first_failure.rb', line 136

def hooks_for_loaded_minitest
  outer = OuterReporter.hook_for_loaded_minitest
  if outer.equal?(OuterReporter::Hook6) then [outer, SkipAfterStop6]
  elsif outer.equal?(OuterReporter::Hook5) then [outer, SkipAfterStop5]
  end
end

.stopped_here? ⇒ Boolean

True when the armed run in this process has stopped.

Returns:

  • (Boolean)


126
127
128
# File 'lib/mutineer/minitest_integration/stop_at_first_failure.rb', line 126

def stopped_here?
  stopped == true && armed_here?
end