Skip to content

Commit

Permalink
Merge pull request #397 from mbj/fix/remove-invalid-mutation
Browse files Browse the repository at this point in the history
Remove invalild mutation on negating booleans
  • Loading branch information
dkubb committed Aug 9, 2015
2 parents 808bb29 + 1443978 commit 991f25b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
@@ -1,3 +1,7 @@
# v0.8.2 2015-08-xx

* Remove invalid mutation `foo or bar` to `!(foo or bar)` see #287

# v0.8.1 2015-07-24

* Add --since flag to constrain mutated subjects based on
Expand Down
36 changes: 28 additions & 8 deletions lib/mutant/mutator/node/binary.rb
Expand Up @@ -22,10 +22,9 @@ class Binary < self
# @api private
def dispatch
emit_singletons
emit(left)
emit(right)
mutate_operator
mutate_operands
emit_promotions
emit_operator_mutations
emit_left_negation
emit_left_mutations
emit_right_mutations
end
Expand All @@ -35,18 +34,39 @@ def dispatch
# @return [undefined]
#
# @api private
def mutate_operator
def emit_operator_mutations
emit(s(INVERSE.fetch(node.type), left, right))
end

# Emit condition mutations
# Emit promotions
#
# @return [undefined]
#
# @api private
#
def emit_promotions
emit(left)
emit(right)
end

# Emit left negation
#
# We do not emit right negation as the `and` and `or` nodes
# in ruby are also used for control flow.
#
# Irrespectable of their syntax, aka `||` parses internally to `or`.
#
# `do_a or do_b`. Negating left makes sense, negating right
# only when the result is actualy used.
#
# It *would* be possible to emit the right negation in case the use of the result is proved.
# Like parent is an assignment to an {l,i}var. Dunno if we ever get the time to do that.
#
# @return [undefined]
#
# @api private
def mutate_operands
def emit_left_negation
emit(s(node.type, n_not(left), right))
emit(n_not(node))
end

end # Binary
Expand Down
1 change: 0 additions & 1 deletion meta/and.rb
Expand Up @@ -10,5 +10,4 @@
mutation 'false and false'
mutation 'true and true'
mutation '!true and false'
mutation '!(true and false)'
end
1 change: 0 additions & 1 deletion meta/or.rb
Expand Up @@ -10,5 +10,4 @@
mutation 'true or true'
mutation 'true and false'
mutation '!true or false'
mutation '!(true or false)'
end

0 comments on commit 991f25b

Please sign in to comment.