Bring back yard coverage to 100%
This commit is contained in:
parent
583668138e
commit
aaa96183b9
6 changed files with 149 additions and 23 deletions
|
@ -3,18 +3,49 @@ module Mutant
|
|||
class Color
|
||||
include Immutable
|
||||
|
||||
# Initialize color object
|
||||
#
|
||||
# @param [Fixnum] code
|
||||
#
|
||||
# @return [undefined]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def initialize(code)
|
||||
@code = code
|
||||
end
|
||||
|
||||
# Format text with color
|
||||
#
|
||||
# @param [String] text
|
||||
#
|
||||
# @return [String]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def format(text)
|
||||
"\e[#{@code}m#{text}\e[0m"
|
||||
end
|
||||
|
||||
NONE = Class.new(self) do
|
||||
# Initialize null color
|
||||
#
|
||||
# @return [undefined]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def initialize(*)
|
||||
end
|
||||
|
||||
# Format null color
|
||||
#
|
||||
# @param [String] text
|
||||
#
|
||||
# @return [String]
|
||||
# returns the argument string
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def format(text)
|
||||
text
|
||||
end
|
||||
|
|
|
@ -1,35 +1,31 @@
|
|||
module Mutant
|
||||
# Class to create diffs from source code
|
||||
class Differ
|
||||
include Immutable
|
||||
|
||||
def initialize(old, new)
|
||||
@new, @old = new.lines.map(&:chomp), old.lines.map(&:chomp)
|
||||
@diffs = Diff::LCS.diff(@old, @new)
|
||||
end
|
||||
|
||||
def format
|
||||
:unified
|
||||
end
|
||||
|
||||
def context_lines
|
||||
3
|
||||
end
|
||||
|
||||
def length_difference
|
||||
@new.size - @old.size
|
||||
end
|
||||
|
||||
# Return source diff
|
||||
#
|
||||
# @return [String]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def diff
|
||||
output = ''
|
||||
@diffs.each do |piece|
|
||||
hunk = Diff::LCS::Hunk.new(@old, @new, piece, context_lines, length_difference)
|
||||
output << hunk.diff(format)
|
||||
hunk = Diff::LCS::Hunk.new(@old, @new, piece, CONTEXT_LINES, @length_difference)
|
||||
output << hunk.diff(FORMAT)
|
||||
output << "\n"
|
||||
end
|
||||
output
|
||||
end
|
||||
memoize :diff
|
||||
|
||||
# Return colorized source diff
|
||||
#
|
||||
# @return [String]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def colorized_diff
|
||||
diff.lines.map do |line|
|
||||
self.class.colorize_line(line)
|
||||
|
@ -37,6 +33,35 @@ module Mutant
|
|||
end
|
||||
memoize :colorized_diff
|
||||
|
||||
private
|
||||
|
||||
FORMAT = :unified
|
||||
CONTEXT_LINES = 3
|
||||
|
||||
# Initialize differ object
|
||||
#
|
||||
# @param [String] old
|
||||
# @param [String] new
|
||||
#
|
||||
# @return [undefined]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def initialize(old, new)
|
||||
@new, @old = new.lines.map(&:chomp), old.lines.map(&:chomp)
|
||||
@length_difference = @new.size - @old.size
|
||||
@diffs = Diff::LCS.diff(@old, @new)
|
||||
end
|
||||
|
||||
# Return colorized diff line
|
||||
#
|
||||
# @param [String] line
|
||||
#
|
||||
# @return [String]
|
||||
# returns colorized line
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def self.colorize_line(line)
|
||||
case line[0].chr
|
||||
when '+'
|
||||
|
|
|
@ -4,7 +4,7 @@ module Mutant
|
|||
include Immutable, Abstract
|
||||
extend MethodObject
|
||||
|
||||
# Check if mutant was killed
|
||||
# Test for kill failure
|
||||
#
|
||||
# @return [true]
|
||||
# returns true when mutant was killed
|
||||
|
@ -30,6 +30,8 @@ module Mutant
|
|||
#
|
||||
# @return [String]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def original_source
|
||||
mutation.original_source
|
||||
end
|
||||
|
@ -38,16 +40,23 @@ module Mutant
|
|||
#
|
||||
# @return [String]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def mutation_source
|
||||
mutation.source
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Return mutation to kill
|
||||
#
|
||||
# @return [Mutation]
|
||||
#
|
||||
# @api private
|
||||
attr_reader :mutation
|
||||
private :mutation
|
||||
|
||||
# Initialize runner and run the test
|
||||
# Initialize killer object
|
||||
#
|
||||
# @param [Mutation] mutation
|
||||
#
|
||||
|
|
|
@ -14,9 +14,9 @@ module Mutant
|
|||
@io.puts("Subject: #{subject.identification}")
|
||||
end
|
||||
|
||||
# Report mutations
|
||||
# Report mutation
|
||||
#
|
||||
# @param [Mutation] mutations
|
||||
# @param [Mutation] mutation
|
||||
#
|
||||
# @return [self]
|
||||
#
|
||||
|
@ -81,6 +81,10 @@ module Mutant
|
|||
#
|
||||
# @api private
|
||||
#
|
||||
# @return [String]
|
||||
# returns colorized string if color is enabled
|
||||
# returns unmodified message otherwise
|
||||
#
|
||||
def colorize(color, message)
|
||||
color = Color::NONE unless color?
|
||||
color.format(message)
|
||||
|
|
|
@ -4,17 +4,47 @@ module Mutant
|
|||
include Immutable
|
||||
extend MethodObject
|
||||
|
||||
# Return killers with errors
|
||||
#
|
||||
# @return [Enumerable<Killer>]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
attr_reader :errors
|
||||
|
||||
# Test for failure
|
||||
#
|
||||
# @return [true]
|
||||
# returns true when there are left mutations
|
||||
#
|
||||
# @return [false]
|
||||
# returns false othewise
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def fail?
|
||||
!errors.empty?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Return reporter
|
||||
#
|
||||
# @return [Reporter]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
attr_reader :reporter
|
||||
private :reporter
|
||||
|
||||
# Initialize runner object
|
||||
#
|
||||
# @param [Hash] options
|
||||
#
|
||||
# @return [undefined]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def initialize(options)
|
||||
@killer = options.fetch(:killer) do
|
||||
raise ArgumentError, 'Missing :killer in options'
|
||||
|
@ -31,6 +61,12 @@ module Mutant
|
|||
run
|
||||
end
|
||||
|
||||
# Run mutation killers on subjects
|
||||
#
|
||||
# @return [undefined]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def run
|
||||
@subjects = subjects.each do |subject|
|
||||
reporter.subject(subject)
|
||||
|
@ -38,6 +74,14 @@ module Mutant
|
|||
end
|
||||
end
|
||||
|
||||
# Run mutation killers on subject
|
||||
#
|
||||
# @param [Subject] subject
|
||||
#
|
||||
# @return [undefined]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def run_subject(subject)
|
||||
subject.each do |mutation|
|
||||
reporter.mutation(mutation)
|
||||
|
@ -46,6 +90,14 @@ module Mutant
|
|||
subject.reset
|
||||
end
|
||||
|
||||
# Run killer on mutation
|
||||
#
|
||||
# @param [Mutation] mutation
|
||||
#
|
||||
# @return [undefined]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def kill(mutation)
|
||||
killer = @killer.run(mutation)
|
||||
reporter.killer(killer)
|
||||
|
|
|
@ -86,6 +86,11 @@ module Mutant
|
|||
memoize :original_root
|
||||
|
||||
# Reset subject into original state
|
||||
#
|
||||
# @return [self]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def reset
|
||||
Loader.run(original_root)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue