2013-07-28 16:03:06 -07:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2013-06-21 23:52:57 +02:00
|
|
|
module Mutant
|
|
|
|
class Reporter
|
|
|
|
class CLI
|
|
|
|
class Printer
|
|
|
|
# Mutation printer
|
|
|
|
class Mutation < self
|
|
|
|
|
2013-07-05 00:54:50 +02:00
|
|
|
handle(Runner::Mutation)
|
|
|
|
|
|
|
|
# Build printer
|
|
|
|
#
|
|
|
|
# @param [Runner::Mutation] runner
|
|
|
|
# @param [IO] output
|
|
|
|
#
|
|
|
|
# @return [Printer::Mutation]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def self.build(runner, output)
|
|
|
|
mutation = runner.mutation
|
2013-09-07 14:08:07 +02:00
|
|
|
lookup(mutation.class).new(runner, output)
|
2013-07-05 00:54:50 +02:00
|
|
|
end
|
|
|
|
|
2013-06-21 23:52:57 +02:00
|
|
|
# Run mutation printer
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def run
|
2013-07-16 17:37:39 +02:00
|
|
|
status('%s', mutation.identification)
|
2013-07-05 00:54:50 +02:00
|
|
|
puts(details)
|
2013-06-21 23:52:57 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Return mutation
|
|
|
|
#
|
|
|
|
# @return [Mutation]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def mutation
|
|
|
|
object.mutation
|
|
|
|
end
|
|
|
|
|
2013-07-05 00:54:50 +02:00
|
|
|
# Reporter for noop mutations
|
|
|
|
class Noop < self
|
|
|
|
|
2013-09-07 14:08:07 +02:00
|
|
|
handle(Mutant::Mutation::Neutral::Noop)
|
|
|
|
|
|
|
|
MESSAGE = [
|
|
|
|
'Parsed subject AST:',
|
|
|
|
'%s',
|
|
|
|
'Unparsed source:',
|
|
|
|
'%s',
|
|
|
|
].join("\n")
|
2013-07-05 00:54:50 +02:00
|
|
|
|
|
|
|
private
|
2013-06-21 23:52:57 +02:00
|
|
|
|
2013-07-05 00:54:50 +02:00
|
|
|
# Return details
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def details
|
2013-07-28 19:02:01 +02:00
|
|
|
sprintf(
|
|
|
|
MESSAGE,
|
|
|
|
mutation.subject.node.inspect,
|
|
|
|
mutation.original_source
|
|
|
|
)
|
2013-06-21 23:52:57 +02:00
|
|
|
end
|
|
|
|
|
2013-07-05 00:54:50 +02:00
|
|
|
end # Noop
|
|
|
|
|
|
|
|
# Reporter for neutral and evil mutations
|
|
|
|
class Diff < self
|
|
|
|
|
2013-09-07 14:08:07 +02:00
|
|
|
handle(Mutant::Mutation::Neutral)
|
|
|
|
handle(Mutant::Mutation::Evil)
|
|
|
|
|
2013-07-05 00:54:50 +02:00
|
|
|
# Return diff
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def details
|
|
|
|
original, current = mutation.original_source, mutation.source
|
|
|
|
differ = Differ.build(original, current)
|
|
|
|
color? ? differ.colorized_diff : differ.diff
|
|
|
|
end
|
|
|
|
|
|
|
|
end # Evil
|
2013-06-21 23:52:57 +02:00
|
|
|
|
|
|
|
end # Mutantion
|
|
|
|
end # Printer
|
|
|
|
end # CLI
|
|
|
|
end # Reporter
|
|
|
|
end # Mutant
|