From b88d3ccc878800c66d4807f0d6fae41ddbe466d4 Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Thu, 25 Jul 2013 08:43:41 -0700 Subject: [PATCH] Fix mutator to not mutate the rhs in a boolean connective * If the right hand side of the expression includes a method which raises or otherwise exits the control flow we cannot kill that mutation. However we can mutate the left hand side, and then mutate the whole node so it is negated; in the worst case both those mutations will be equivalent, but in the best case the rhs will return a boolean which will be negated. --- lib/mutant/mutator/node/connective/binary.rb | 2 +- .../mutant/mutator/node/connective/binary/mutation_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/mutant/mutator/node/connective/binary.rb b/lib/mutant/mutator/node/connective/binary.rb index 8b2cbdb1..44b17360 100644 --- a/lib/mutant/mutator/node/connective/binary.rb +++ b/lib/mutant/mutator/node/connective/binary.rb @@ -49,7 +49,7 @@ module Mutant # def mutate_operands emit(s(node.type, n_not(left), right)) - emit(s(node.type, left, n_not(right))) + emit(n_not(node)) end end # Binary diff --git a/spec/unit/mutant/mutator/node/connective/binary/mutation_spec.rb b/spec/unit/mutant/mutator/node/connective/binary/mutation_spec.rb index 2d39469e..a51012d1 100644 --- a/spec/unit/mutant/mutator/node/connective/binary/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/connective/binary/mutation_spec.rb @@ -13,7 +13,7 @@ describe Mutant::Mutator::Node::Connective::Binary, 'mutations' do mutations << 'true or false' mutations << 'not true and false' - mutations << 'true and not false' + mutations << 'not(true and false)' end it_should_behave_like 'a mutator' @@ -31,7 +31,7 @@ describe Mutant::Mutator::Node::Connective::Binary, 'mutations' do mutations << 'true and false' mutations << 'not true or false' - mutations << 'true or not false' + mutations << 'not(true or false)' end it_should_behave_like 'a mutator'