2012-08-16 04:10:54 +02:00
|
|
|
module Mutant
|
|
|
|
class Reporter
|
|
|
|
# Reporter that reports in human readable format
|
|
|
|
class CLI < self
|
2013-04-20 20:47:07 +02:00
|
|
|
include Concord.new(:io)
|
2012-08-29 13:36:29 +02:00
|
|
|
|
2013-04-20 20:47:07 +02:00
|
|
|
private
|
2012-08-16 04:10:54 +02:00
|
|
|
|
2013-04-20 20:47:07 +02:00
|
|
|
# Report subject
|
2012-12-11 00:17:19 +01:00
|
|
|
#
|
2013-04-20 20:47:07 +02:00
|
|
|
# @param [Subject] _subject
|
2012-12-11 00:17:19 +01:00
|
|
|
#
|
2013-04-20 20:47:07 +02:00
|
|
|
# @return [undefined]
|
2012-12-11 00:17:19 +01:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-04-20 20:47:07 +02:00
|
|
|
def subject(_subject)
|
2012-12-11 00:17:19 +01:00
|
|
|
end
|
|
|
|
|
2012-08-16 19:26:15 +02:00
|
|
|
# Report mutation
|
2012-08-16 04:10:54 +02:00
|
|
|
#
|
2013-04-20 20:47:07 +02:00
|
|
|
# @param [Mutation] _mutation
|
2012-08-16 04:10:54 +02:00
|
|
|
#
|
2013-04-20 20:47:07 +02:00
|
|
|
# @return [undefined]
|
2012-08-16 04:10:54 +02:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-04-20 20:47:07 +02:00
|
|
|
def mutation(_mutation)
|
2012-08-16 04:10:54 +02:00
|
|
|
end
|
|
|
|
|
2013-01-21 23:54:25 +01:00
|
|
|
# Report start
|
2012-11-21 22:28:08 +01:00
|
|
|
#
|
|
|
|
# @param [Mutant::Config] config
|
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-04-20 20:47:07 +02:00
|
|
|
def config(config)
|
2013-01-15 23:46:05 +01:00
|
|
|
message = []
|
|
|
|
message << 'Mutant configuration:'
|
2013-04-20 20:47:07 +02:00
|
|
|
message << "Matcher: #{config.matcher.inspect }"
|
|
|
|
message << "Filter: #{config.filter.inspect }"
|
2013-01-15 23:46:05 +01:00
|
|
|
message << "Strategy: #{config.strategy.inspect}"
|
|
|
|
puts message.join("\n")
|
2012-11-21 22:28:08 +01:00
|
|
|
end
|
|
|
|
|
2013-01-21 23:13:34 +01:00
|
|
|
# Report killer
|
|
|
|
#
|
|
|
|
# @param [Killer] killer
|
2012-11-22 02:51:16 +01:00
|
|
|
#
|
2013-01-21 23:13:34 +01:00
|
|
|
# @return [self]
|
2012-11-22 02:51:16 +01:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-04-20 20:47:07 +02:00
|
|
|
def killer(killer)
|
2013-01-21 23:13:34 +01:00
|
|
|
status = killer.killed? ? 'Killed' : 'Alive'
|
|
|
|
color = killer.success? ? Color::GREEN : Color::RED
|
|
|
|
|
2013-01-21 23:14:28 +01:00
|
|
|
puts(colorize(color, "%s: %s (%02.2fs)" % [status, killer.identification, killer.runtime]))
|
2013-01-21 23:13:34 +01:00
|
|
|
|
|
|
|
unless killer.success?
|
|
|
|
colorized_diff(killer.mutation)
|
|
|
|
end
|
|
|
|
|
|
|
|
self
|
|
|
|
end
|
2012-11-22 02:51:16 +01:00
|
|
|
|
2013-04-17 20:31:21 -07:00
|
|
|
private
|
2012-08-16 04:10:54 +02:00
|
|
|
|
2012-08-16 18:02:03 +02:00
|
|
|
# Test for colored output
|
|
|
|
#
|
|
|
|
# @return [true]
|
|
|
|
# returns true if output is colored
|
|
|
|
#
|
|
|
|
# @return [false]
|
|
|
|
# returns false otherwise
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def color?
|
|
|
|
tty?
|
|
|
|
end
|
|
|
|
|
|
|
|
# Colorize message
|
|
|
|
#
|
|
|
|
# @param [Color] color
|
|
|
|
# @param [String] message
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-08-16 19:26:15 +02:00
|
|
|
# @return [String]
|
|
|
|
# returns colorized string if color is enabled
|
|
|
|
# returns unmodified message otherwise
|
|
|
|
#
|
2012-08-16 18:02:03 +02:00
|
|
|
def colorize(color, message)
|
|
|
|
color = Color::NONE unless color?
|
|
|
|
color.format(message)
|
|
|
|
end
|
|
|
|
|
2012-11-21 22:28:08 +01:00
|
|
|
# Write string to io
|
|
|
|
#
|
|
|
|
# @param [String] string
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def puts(string="\n")
|
|
|
|
io.puts(string)
|
|
|
|
end
|
|
|
|
|
2012-11-24 23:28:23 +01:00
|
|
|
# Write colorized diff
|
|
|
|
#
|
2012-12-12 22:31:14 +01:00
|
|
|
# @param [Mutation] mutation
|
2012-11-24 23:28:23 +01:00
|
|
|
#
|
2012-12-11 00:17:19 +01:00
|
|
|
# @return [undefined]
|
2012-11-24 23:28:23 +01:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-12-11 00:17:19 +01:00
|
|
|
def colorized_diff(mutation)
|
2013-01-15 23:46:05 +01:00
|
|
|
if mutation.kind_of?(Mutation::Neutral)
|
2012-12-12 17:52:24 +01:00
|
|
|
puts mutation.original_source
|
2012-12-11 00:17:19 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
original, current = mutation.original_source, mutation.source
|
2012-11-24 23:28:23 +01:00
|
|
|
differ = Differ.new(original, current)
|
|
|
|
diff = color? ? differ.colorized_diff : differ.diff
|
2012-12-11 00:17:19 +01:00
|
|
|
|
2012-11-24 23:28:23 +01:00
|
|
|
if diff.empty?
|
2013-04-20 20:47:07 +02:00
|
|
|
raise 'Unable to create a diff, so ast mutant or to_source does something strange!!'
|
2012-11-24 23:28:23 +01:00
|
|
|
end
|
2012-12-11 00:17:19 +01:00
|
|
|
|
2012-11-24 23:28:23 +01:00
|
|
|
puts(diff)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2012-08-16 18:02:03 +02:00
|
|
|
# Test for output to tty
|
|
|
|
#
|
|
|
|
# @return [true]
|
|
|
|
# returns true if output is a tty
|
2013-04-17 20:31:21 -07:00
|
|
|
#
|
2012-08-16 18:02:03 +02:00
|
|
|
# @return [false]
|
|
|
|
# returns false otherwise
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def tty?
|
|
|
|
@io.respond_to?(:tty?) && @io.tty?
|
|
|
|
end
|
|
|
|
memoize :tty?
|
2013-01-15 23:46:05 +01:00
|
|
|
|
2012-08-16 04:10:54 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|