Cleanup killers
This commit is contained in:
parent
2b6470f223
commit
277a29aba5
4 changed files with 36 additions and 91 deletions
|
@ -2,11 +2,41 @@ module Mutant
|
||||||
# Abstract base class for mutant killers
|
# Abstract base class for mutant killers
|
||||||
class Killer
|
class Killer
|
||||||
include Adamantium::Flat, AbstractType, Equalizer.new(:strategy, :mutation, :killed?)
|
include Adamantium::Flat, AbstractType, Equalizer.new(:strategy, :mutation, :killed?)
|
||||||
|
|
||||||
|
# Return strategy
|
||||||
|
#
|
||||||
|
# @return [Strategy]
|
||||||
|
#
|
||||||
|
# @api private
|
||||||
|
#
|
||||||
|
attr_reader :strategy
|
||||||
|
|
||||||
|
# Return mutation to kill
|
||||||
|
#
|
||||||
|
# @return [Mutation]
|
||||||
|
#
|
||||||
|
# @api private
|
||||||
|
#
|
||||||
|
attr_reader :mutation
|
||||||
|
|
||||||
|
# Initialize killer object
|
||||||
|
#
|
||||||
|
# @param [Strategy] strategy
|
||||||
|
# @param [Mutation] mutation
|
||||||
|
#
|
||||||
|
# @return [undefined]
|
||||||
|
#
|
||||||
|
# @api private
|
||||||
|
#
|
||||||
|
def initialize(strategy, mutation)
|
||||||
|
@strategy, @mutation = strategy, mutation
|
||||||
|
run_with_benchmark
|
||||||
|
end
|
||||||
|
|
||||||
# Test for kill failure
|
# Test for kill failure
|
||||||
#
|
#
|
||||||
# @return [true]
|
# @return [true]
|
||||||
# when mutant was killed
|
# when killer succeeded
|
||||||
#
|
#
|
||||||
# @return [false]
|
# @return [false]
|
||||||
# otherwise
|
# otherwise
|
||||||
|
@ -40,16 +70,6 @@ module Mutant
|
||||||
#
|
#
|
||||||
attr_reader :runtime
|
attr_reader :runtime
|
||||||
|
|
||||||
# Return configuration
|
|
||||||
#
|
|
||||||
# @return [Configuration]
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
#
|
|
||||||
def configuration
|
|
||||||
strategy.configuration
|
|
||||||
end
|
|
||||||
|
|
||||||
# Return mutated source
|
# Return mutated source
|
||||||
#
|
#
|
||||||
# @return [String]
|
# @return [String]
|
||||||
|
@ -60,69 +80,8 @@ module Mutant
|
||||||
mutation.source
|
mutation.source
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return name of killer
|
|
||||||
#
|
|
||||||
# @return [String]
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
#
|
|
||||||
def self.type
|
|
||||||
self::TYPE
|
|
||||||
end
|
|
||||||
|
|
||||||
# Return strategy
|
|
||||||
#
|
|
||||||
# @return [Strategy]
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
#
|
|
||||||
attr_reader :strategy
|
|
||||||
|
|
||||||
# Return identification
|
|
||||||
#
|
|
||||||
# @return [String]
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
#
|
|
||||||
def identification
|
|
||||||
"#{type}:#{mutation.identification}".freeze
|
|
||||||
end
|
|
||||||
memoize :identification
|
|
||||||
|
|
||||||
# Return mae of killer
|
|
||||||
#
|
|
||||||
# @return [String]
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
#
|
|
||||||
def type
|
|
||||||
self.class.type
|
|
||||||
end
|
|
||||||
|
|
||||||
# Return mutation to kill
|
|
||||||
#
|
|
||||||
# @return [Mutation]
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
#
|
|
||||||
attr_reader :mutation
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Initialize killer object
|
|
||||||
#
|
|
||||||
# @param [Mutation] mutation
|
|
||||||
#
|
|
||||||
# @return [undefined]
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
#
|
|
||||||
def initialize(strategy, mutation)
|
|
||||||
@strategy, @mutation = strategy, mutation
|
|
||||||
|
|
||||||
run_with_benchmark
|
|
||||||
end
|
|
||||||
|
|
||||||
# Run with taking the time
|
# Run with taking the time
|
||||||
#
|
#
|
||||||
# @return [undefined]
|
# @return [undefined]
|
||||||
|
@ -136,13 +95,13 @@ module Mutant
|
||||||
@runtime = end_time - start_time
|
@runtime = end_time - start_time
|
||||||
end
|
end
|
||||||
|
|
||||||
# Run test
|
# Run killer
|
||||||
#
|
#
|
||||||
# @return [true]
|
# @return [true]
|
||||||
# returns true when mutant was killed
|
# when mutant was killed
|
||||||
#
|
#
|
||||||
# @return [false]
|
# @return [false]
|
||||||
# returns false otherwise
|
# otherwise
|
||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
|
|
|
@ -17,16 +17,6 @@ module Mutant
|
||||||
super(strategy, mutation)
|
super(strategy, mutation)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return killer type
|
|
||||||
#
|
|
||||||
# @return [String]
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
#
|
|
||||||
def type
|
|
||||||
@killer.type
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Run killer
|
# Run killer
|
||||||
|
|
|
@ -3,14 +3,12 @@ module Mutant
|
||||||
# Runner for rspec tests
|
# Runner for rspec tests
|
||||||
class Rspec < self
|
class Rspec < self
|
||||||
|
|
||||||
TYPE = 'rspec'.freeze
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Run rspec test
|
# Run rspec test
|
||||||
#
|
#
|
||||||
# @return [true]
|
# @return [true]
|
||||||
# when test is NOT successful and the mutant was killed
|
# when test is NOT successful
|
||||||
#
|
#
|
||||||
# @return [false]
|
# @return [false]
|
||||||
# otherwise
|
# otherwise
|
||||||
|
@ -21,7 +19,6 @@ module Mutant
|
||||||
mutation.insert
|
mutation.insert
|
||||||
!!::RSpec::Core::Runner.run(command_line_arguments, strategy.error_stream, strategy.output_stream).nonzero?
|
!!::RSpec::Core::Runner.run(command_line_arguments, strategy.error_stream, strategy.output_stream).nonzero?
|
||||||
end
|
end
|
||||||
memoize :run
|
|
||||||
|
|
||||||
# Return command line arguments
|
# Return command line arguments
|
||||||
#
|
#
|
||||||
|
@ -34,6 +31,7 @@ module Mutant
|
||||||
--fail-fast
|
--fail-fast
|
||||||
) + strategy.spec_files(mutation.subject)
|
) + strategy.spec_files(mutation.subject)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,13 +19,11 @@ module Mutant
|
||||||
|
|
||||||
# Killer that is always successful
|
# Killer that is always successful
|
||||||
class Success < self
|
class Success < self
|
||||||
TYPE = 'success'.freeze
|
|
||||||
RESULT = true
|
RESULT = true
|
||||||
end
|
end
|
||||||
|
|
||||||
# Killer that always fails
|
# Killer that always fails
|
||||||
class Fail < self
|
class Fail < self
|
||||||
TYPE = 'fail'.freeze
|
|
||||||
RESULT = false
|
RESULT = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue