diff --git a/lib/mutant/reporter.rb b/lib/mutant/reporter.rb index 505f697b..93c13691 100644 --- a/lib/mutant/reporter.rb +++ b/lib/mutant/reporter.rb @@ -1,136 +1,28 @@ module Mutant # Abstract reporter class Reporter - include Adamantium::Flat, AbstractType, Equalizer.new(:stats) + include Adamantium::Flat, AbstractType - # Initialize reporter - # - # @param [Config] config - # - # @api private - # - def initialize(config) - @stats = Stats.new - @config = config - end + ACTIONS = { + Subject => :subject, + }.freeze - # Test for success + # Report object # - # @return [true] - # if there are subjects and no errors - # - # @return [false] - # otherwise - # - # @api private - # - def success? - stats.success? - end - - # Report start - # - # @param [Config] config + # @param [Object] object # # @return [self] # # @api private # - def start(_config) + def report(object) + klass = object.class + method = self.class::ACTIONS.fetch(klass) do + raise "No reporter for: #{klass}" + end + send(method, object) self end - # Report stop - # - # @return [self] - # - # @api private - # - def stop - self - end - - # Report subject - # - # @param [Subject] subject - # - # @return [self] - # - # @api private - # - def subject(_subject) - stats.count_subject - self - end - - # Report mutation - # - # @param [Mutation] mutation - # - # @return [self] - # - # @api private - # - def mutation(_mutation) - self - end - - # Report killer - # - # @param [Killer] killer - # - # @return [self] - # - # @api private - # - def report_killer(killer) - stats.count_killer(killer) - self - end - - # Test for running in debug mode - # - # @return [true] - # if running in debug mode - # - # @return [false] - # otherwise - # - # @api private - # - def debug? - config.debug? - end - - # Return stats - # - # @return [Reporter::Stats] - # - # @api private - # - attr_reader :stats - - # Return config - # - # @return [Config] - # - # @api private - # - attr_reader :config - - # Test if errors are present - # - # @return [true] - # if errors are present - # - # @return [false] - # otherwise - # - # @api private - # - def errors? - stats.errors? - end - end end diff --git a/lib/mutant/reporter/cli.rb b/lib/mutant/reporter/cli.rb index a9720080..514c4d7a 100644 --- a/lib/mutant/reporter/cli.rb +++ b/lib/mutant/reporter/cli.rb @@ -2,69 +2,30 @@ module Mutant class Reporter # Reporter that reports in human readable format class CLI < self + include Concord.new(:io) - # Initialize reporter + private + + # Report subject # - # @param [Config] config + # @param [Subject] _subject # # @return [undefined] # # @api private # - def initialize(config) - super - @io = $stdout - end - - # Reporte subject - # - # @param [Subject] subject - # - # @return [self] - # - # @api private - # - def subject(subject) - super - puts("Subject: #{subject.identification}") - end - - # Return error stream - # - # @return [IO] - # - # @api private - # - def error_stream - debug? ? io : StringIO.new - end - - # Return output stream - # - # @return [IO] - # - # @api private - # - def output_stream - debug? ? io : StringIO.new + def subject(_subject) end # Report mutation # - # @param [Mutation] mutation + # @param [Mutation] _mutation # - # @return [self] + # @return [undefined] # # @api private # - def mutation(mutation) - super - - if debug? - colorized_diff(mutation) - end - - self + def mutation(_mutation) end # Report start @@ -75,24 +36,13 @@ module Mutant # # @api private # - def start(config) + def config(config) message = [] message << 'Mutant configuration:' - message << "Matcher: #{config.matcher.inspect}" - message << "Filter: #{config.filter.inspect}" + message << "Matcher: #{config.matcher.inspect }" + message << "Filter: #{config.filter.inspect }" message << "Strategy: #{config.strategy.inspect}" puts message.join("\n") - super - end - - # Report stop - # - # @return [self] - # - # @api private - # - def stop - super end # Report killer @@ -103,9 +53,7 @@ module Mutant # # @api private # - def report_killer(killer) - super - + def killer(killer) status = killer.killed? ? 'Killed' : 'Alive' color = killer.success? ? Color::GREEN : Color::RED @@ -120,14 +68,6 @@ module Mutant private - # Return IO stream - # - # @return [IO] - # - # @api private - # - attr_reader :io - # Test for colored output # # @return [true] @@ -189,7 +129,7 @@ module Mutant diff = color? ? differ.colorized_diff : differ.diff if diff.empty? - raise 'Unable to create a diff, so ast mutation or to_source has an error!' + raise 'Unable to create a diff, so ast mutant or to_source does something strange!!' end puts(diff) diff --git a/lib/mutant/reporter/null.rb b/lib/mutant/reporter/null.rb index ace5dbfa..1d50cb2a 100644 --- a/lib/mutant/reporter/null.rb +++ b/lib/mutant/reporter/null.rb @@ -4,42 +4,18 @@ module Mutant # Null reporter class Null < self - # Report subject + # Report object # - # @param [Subject] subject + # @param [Object] _object # # @return [self] # # @api private # - def subject(*) + def report(_object) self end - # Report mutation - # - # @param [Mutation] mutation - # - # @return [self] - # - # @api private - # - def mutation(*) - self - end - - # Report killer - # - # @param [Killer] killer - # - # @return [self] - # - # @api private - # - def killer(*) - self - end end - end end