From 7813f924123a1d4acac755cba1b83ac8f9c56bd5 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Mon, 7 Jul 2014 15:03:31 +0000 Subject: [PATCH] Add better noop/neutral reporting --- config/flay.yml | 2 +- lib/mutant.rb | 1 + lib/mutant/delegator.rb | 2 +- lib/mutant/reporter/cli/report/mutation.rb | 25 ++++++++++------- lib/mutant/reporter/cli/report/test.rb | 28 +++++++++++++++++++ lib/mutant/result.rb | 10 +++++++ spec/unit/mutant/reporter/cli_spec.rb | 31 +++++++++++++++++++--- 7 files changed, 84 insertions(+), 15 deletions(-) create mode 100644 lib/mutant/reporter/cli/report/test.rb diff --git a/config/flay.yml b/config/flay.yml index 2301bdc6..f5ac9c24 100644 --- a/config/flay.yml +++ b/config/flay.yml @@ -1,3 +1,3 @@ --- threshold: 18 -total_score: 1053 +total_score: 1040 diff --git a/lib/mutant.rb b/lib/mutant.rb index df5ee94c..8bd7611d 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -195,6 +195,7 @@ require 'mutant/reporter/cli/report' require 'mutant/reporter/cli/report/env' require 'mutant/reporter/cli/report/subject' require 'mutant/reporter/cli/report/mutation' +require 'mutant/reporter/cli/report/test' require 'mutant/reporter/cli/progress' require 'mutant/reporter/cli/progress/env' require 'mutant/reporter/cli/progress/config' diff --git a/lib/mutant/delegator.rb b/lib/mutant/delegator.rb index e733eac9..40bd6e94 100644 --- a/lib/mutant/delegator.rb +++ b/lib/mutant/delegator.rb @@ -25,7 +25,7 @@ module Mutant # @api private # def define_delegator(name) - fail if instance_methods.include?(name) + fail "method #{name} already defined" if instance_methods.include?(name) define_method(name) do object.public_send(name) end diff --git a/lib/mutant/reporter/cli/report/mutation.rb b/lib/mutant/reporter/cli/report/mutation.rb index c80d7cb7..90ce7c67 100644 --- a/lib/mutant/reporter/cli/report/mutation.rb +++ b/lib/mutant/reporter/cli/report/mutation.rb @@ -8,7 +8,7 @@ module Mutant handle Mutant::Result::Mutation - delegate :mutation + delegate :mutation, :failed_test_results DIFF_ERROR_MESSAGE = 'BUG: Mutation NOT resulted in exactly one diff. Please report a reproduction!'.freeze @@ -26,13 +26,15 @@ module Mutant "%s\n" \ "Unparsed Source:\n" \ "%s\n" \ - "-----------------------\n".freeze + "Test Reports: %d\n" NOOP_MESSAGE = - "--- Noop failure ---\n" \ + "---- Noop failure -----\n" \ "No code was inserted. And the test did NOT PASS.\n" \ "This is typically a problem of your specs not passing unmutated.\n" \ - "--------------------\n".freeze + "Test Reports: %d\n" + + FOOTER = '-----------------------'.freeze # Run report printer # @@ -42,7 +44,8 @@ module Mutant # def run puts(mutation.identification) - puts(details) + print_details + puts(FOOTER) self end @@ -50,11 +53,11 @@ module Mutant # Return details # - # @return [String] + # @return [undefined] # # @api private # - def details + def print_details send(MAP.fetch(mutation.class)) end @@ -68,7 +71,7 @@ module Mutant original, current = mutation.original_source, mutation.source diff = Mutant::Diff.build(original, current) diff = color? ? diff.colorized_diff : diff.diff - diff || DIFF_ERROR_MESSAGE + info(diff || DIFF_ERROR_MESSAGE) end # Noop details @@ -78,7 +81,8 @@ module Mutant # @api private # def noop_details - NOOP_MESSAGE + info(NOOP_MESSAGE, failed_test_results.length) + visit_collection(failed_test_results) end # Neutral details @@ -88,7 +92,8 @@ module Mutant # @api private # def neutral_details - format(NEUTRAL_MESSAGE, mutation.subject.node.inspect, mutation.source) + info(NEUTRAL_MESSAGE, mutation.subject.node.inspect, mutation.source, failed_test_results.length) + visit_collection(failed_test_results) end end # Mutation diff --git a/lib/mutant/reporter/cli/report/test.rb b/lib/mutant/reporter/cli/report/test.rb new file mode 100644 index 00000000..08acde8e --- /dev/null +++ b/lib/mutant/reporter/cli/report/test.rb @@ -0,0 +1,28 @@ +module Mutant + class Reporter + class CLI + class Report + # Test result reporter + class Test < self + + handle(Mutant::Result::Test) + + delegate :test, :runtime + + # Run test result reporter + # + # @return [self] + # + # @api private + # + def run + status('- %s / runtime: %s', test.identification, object.runtime) + puts('Test Output:') + puts(object.output) + end + + end + end # Report + end # CLI + end # Reporter +end # Mutant diff --git a/lib/mutant/result.rb b/lib/mutant/result.rb index 2bdee1fa..82b1bf46 100644 --- a/lib/mutant/result.rb +++ b/lib/mutant/result.rb @@ -284,6 +284,16 @@ module Mutant test_results.any?(&:success?) end + # Return failed test results + # + # @return [Array] + # + # @api private + # + def failed_test_results + test_results.select(&:fail?) + end + sum :killtime, :test_results end # Mutation diff --git a/spec/unit/mutant/reporter/cli_spec.rb b/spec/unit/mutant/reporter/cli_spec.rb index 1ee512b3..6964bfef 100644 --- a/spec/unit/mutant/reporter/cli_spec.rb +++ b/spec/unit/mutant/reporter/cli_spec.rb @@ -70,6 +70,19 @@ describe Mutant::Reporter::CLI do ) end + let(:test_results) do + [ + double( + 'Test Result', + class: Mutant::Result::Test, + test: _subject.tests.first, + runtime: 1.0, + output: 'test-output', + success?: mutation_result_success + ) + ] + end + let(:subject_results) do [ Mutant::Result::Subject.new( @@ -81,7 +94,9 @@ describe Mutant::Reporter::CLI do class: Mutant::Result::Mutation, mutation: mutation, killtime: 0.5, - success?: mutation_result_success + success?: mutation_result_success, + test_results: test_results, + failed_test_results: mutation_result_success ? [] : test_results ) ] ) @@ -192,6 +207,7 @@ describe Mutant::Reporter::CLI do @@ -1,2 +1,2 @@ -true +false + ----------------------- Subjects: 1 Mutations: 1 Kills: 0 @@ -215,6 +231,7 @@ describe Mutant::Reporter::CLI do - test_id mutation_id BUG: Mutation NOT resulted in exactly one diff. Please report a reproduction! + ----------------------- Subjects: 1 Mutations: 1 Kills: 0 @@ -246,6 +263,10 @@ describe Mutant::Reporter::CLI do (true) Unparsed Source: true + Test Reports: 1 + - test_id / runtime: 1.0 + Test Output: + test-output ----------------------- Subjects: 1 Mutations: 1 @@ -269,10 +290,14 @@ describe Mutant::Reporter::CLI do subject_id - test_id mutation_id - --- Noop failure --- + ---- Noop failure ----- No code was inserted. And the test did NOT PASS. This is typically a problem of your specs not passing unmutated. - -------------------- + Test Reports: 1 + - test_id / runtime: 1.0 + Test Output: + test-output + ----------------------- Subjects: 1 Mutations: 1 Kills: 0