From 9b12d9f3ba18761815e2bb383470c5355e2817bb Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Fri, 23 May 2014 18:55:54 +0000 Subject: [PATCH] Remove always dead mutations on rescue matchers --- lib/mutant/mutator/node/resbody.rb | 7 +++---- spec/support/mutation_verifier.rb | 2 +- spec/unit/mutant/mutator/node/rescue_spec.rb | 14 ++++---------- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/lib/mutant/mutator/node/resbody.rb b/lib/mutant/mutator/node/resbody.rb index e9110e6e..7ccc95ca 100644 --- a/lib/mutant/mutator/node/resbody.rb +++ b/lib/mutant/mutator/node/resbody.rb @@ -8,7 +8,7 @@ module Mutant handle(:resbody) - children :captures, :assignment, :block + children :captures, :assignment, :body private @@ -20,7 +20,7 @@ module Mutant # def dispatch emit_assignment(nil) - emit_block_mutations if block + emit_body_mutations if body mutate_captures end @@ -32,9 +32,8 @@ module Mutant # def mutate_captures return unless captures - emit_captures(nil) Util::Array.each(captures.children, self) do |matchers| - next if matchers.empty? + next if matchers.empty? || matchers.any? { |node| node.type == :nil } emit_captures(s(:array, *matchers)) end end diff --git a/spec/support/mutation_verifier.rb b/spec/support/mutation_verifier.rb index 9c9921c2..d031e69c 100644 --- a/spec/support/mutation_verifier.rb +++ b/spec/support/mutation_verifier.rb @@ -46,7 +46,7 @@ private # @api private # def mutation_report - message = ['Original:', original_node.inspect] + message = ['Original-AST:', original_node.inspect, 'Original-Source:', Unparser.unparse(original_node)] if missing.any? message << 'Missing mutations:' message << missing.map(&method(:format_mutation)).join("\n-----\n") diff --git a/spec/unit/mutant/mutator/node/rescue_spec.rb b/spec/unit/mutant/mutator/node/rescue_spec.rb index 81385d38..78d4fdf1 100644 --- a/spec/unit/mutant/mutator/node/rescue_spec.rb +++ b/spec/unit/mutant/mutator/node/rescue_spec.rb @@ -10,31 +10,25 @@ describe Mutant::Mutator::Node::Generic, 'rescue' do let(:mutations) do mutations = [] mutations << 'nil' - # mutations << 'begin; rescue ExceptionA, ExceptionB => error; true; end' mutations << 'begin; rescue ExceptionA, ExceptionB; true; end' mutations << 'begin; rescue ExceptionA, ExceptionB => error; false; end' mutations << 'begin; rescue ExceptionA, ExceptionB => error; nil; end' - mutations << 'begin; rescue ExceptionA, nil => error; true; end' mutations << 'begin; rescue ExceptionA => error; true; end' mutations << 'begin; rescue ExceptionB => error; true; end' - mutations << 'begin; rescue nil, ExceptionB => error; true; end' - mutations << 'begin; rescue => error; true; end' end it_should_behave_like 'a mutator' end context 'single exception selector and assignment' do - let(:source) { 'begin; rescue Exception => error; true; end' } + let(:source) { 'begin; rescue SomeException => error; true; end' } let(:mutations) do mutations = [] mutations << 'nil' - mutations << 'begin; rescue Exception; true; end' - mutations << 'begin; rescue Exception => error; false; end' - mutations << 'begin; rescue Exception => error; nil; end' - mutations << 'begin; rescue nil => error; true; end' - mutations << 'begin; rescue => error; true; end' + mutations << 'begin; rescue SomeException; true; end' + mutations << 'begin; rescue SomeException => error; false; end' + mutations << 'begin; rescue SomeException => error; nil; end' end it_should_behave_like 'a mutator'