diff --git a/lib/mutant/reporter/cli/printer.rb b/lib/mutant/reporter/cli/printer.rb index 9d51fab0..dd7a41b1 100644 --- a/lib/mutant/reporter/cli/printer.rb +++ b/lib/mutant/reporter/cli/printer.rb @@ -63,10 +63,34 @@ module Mutant # @api private # def self.visit(object, output) - printer = REGISTRY.fetch(object.class) + printer = lookup(object.class) printer.run(object, output) end + # Lookup printer class + # + # @param [Class] klass + # + # @return [Class:Printer] + # if found + # + # @raise [RuntimeError] + # otherwise + # + # @api private + # + def self.lookup(klass) + current = klass + until current == Object + if REGISTRY.key?(current) + return REGISTRY.fetch(current) + end + current = current.superclass + end + raise "No printer for: #{klass}" + end + private_class_method :lookup + abstract_method :run private diff --git a/lib/mutant/reporter/cli/printer/killer.rb b/lib/mutant/reporter/cli/printer/killer.rb index ef07f60a..186e6084 100644 --- a/lib/mutant/reporter/cli/printer/killer.rb +++ b/lib/mutant/reporter/cli/printer/killer.rb @@ -8,7 +8,7 @@ module Mutant # Printer for killer results class Killer < self - handle(Mutant::Killer::Forked) + handle(Mutant::Killer) SUCCESS = '.'.freeze FAILURE = 'F'.freeze diff --git a/lib/mutant/reporter/cli/printer/mutation.rb b/lib/mutant/reporter/cli/printer/mutation.rb index 02237101..283ea44c 100644 --- a/lib/mutant/reporter/cli/printer/mutation.rb +++ b/lib/mutant/reporter/cli/printer/mutation.rb @@ -20,14 +20,7 @@ module Mutant # def self.build(runner, output) mutation = runner.mutation - case mutation - when Mutant::Mutation::Neutral::Noop - Noop - when Mutant::Mutation::Evil, Mutant::Mutation::Neutral - Diff - else - raise "Unknown mutation: #{mutation}" - end.new(runner, output) + lookup(mutation.class).new(runner, output) end # Run mutation printer @@ -56,12 +49,14 @@ module Mutant # Reporter for noop mutations class Noop < self - MESSAGE = [ - 'Parsed subject AST:', - '%s', - 'Unparsed source:', - '%s', - ].join("\n") + handle(Mutant::Mutation::Neutral::Noop) + + MESSAGE = [ + 'Parsed subject AST:', + '%s', + 'Unparsed source:', + '%s', + ].join("\n") private @@ -84,6 +79,9 @@ module Mutant # Reporter for neutral and evil mutations class Diff < self + handle(Mutant::Mutation::Neutral) + handle(Mutant::Mutation::Evil) + # Return diff # # @return [String] diff --git a/lib/mutant/reporter/cli/printer/subject.rb b/lib/mutant/reporter/cli/printer/subject.rb index 25554b79..873d7ebb 100644 --- a/lib/mutant/reporter/cli/printer/subject.rb +++ b/lib/mutant/reporter/cli/printer/subject.rb @@ -8,9 +8,7 @@ module Mutant # Subject results printer class Subject < self - handle(Mutant::Subject::Method::Instance) - handle(Mutant::Subject::Method::Instance::Memoized) - handle(Mutant::Subject::Method::Singleton) + handle(Mutant::Subject) # Run subject results printer #