Merge pull request #815 from mbj/fix/invalid-block-mutations
Fix invalid block pass mutation
This commit is contained in:
commit
cffcd910c4
2 changed files with 35 additions and 2 deletions
|
@ -3,7 +3,6 @@
|
|||
module Mutant
|
||||
class Mutator
|
||||
class Node
|
||||
# Emitter for mutations on 19 blocks
|
||||
class Block < self
|
||||
|
||||
handle(:block)
|
||||
|
@ -18,7 +17,7 @@ module Mutant
|
|||
def dispatch
|
||||
emit_singletons
|
||||
emit(send) unless n_lambda?(send)
|
||||
emit_send_mutations(&method(:n_send?))
|
||||
emit_send_mutations(&method(:valid_send_mutation?))
|
||||
emit_arguments_mutations
|
||||
|
||||
mutate_body
|
||||
|
@ -58,6 +57,17 @@ module Mutant
|
|||
emit(s(:send, send, body_meta.selector, *body_meta.arguments))
|
||||
end
|
||||
|
||||
# Test for valid send mutations
|
||||
#
|
||||
# @return [true, false, nil]
|
||||
def valid_send_mutation?(node)
|
||||
return unless n_send?(node)
|
||||
|
||||
last = AST::Meta::Send.new(node).arguments.last
|
||||
|
||||
!last&.type.equal?(:block_pass)
|
||||
end
|
||||
|
||||
end # Block
|
||||
end # Node
|
||||
end # Mutator
|
||||
|
|
|
@ -179,3 +179,26 @@ Mutant::Meta::Example.add :block do
|
|||
mutation 'foo { }'
|
||||
mutation 'foo'
|
||||
end
|
||||
|
||||
Mutant::Meta::Example.add :block do
|
||||
source 'foo(&:bar).baz {}'
|
||||
|
||||
singleton_mutations
|
||||
|
||||
mutation 'foo(&:bar).baz { raise }'
|
||||
mutation 'foo.baz { }'
|
||||
mutation 'foo(&:bar).baz'
|
||||
mutation 'self.baz {}'
|
||||
end
|
||||
|
||||
Mutant::Meta::Example.add :block do
|
||||
source 'foo(nil, &:bar).baz {}'
|
||||
|
||||
singleton_mutations
|
||||
mutation 'foo(nil, &:bar).baz { raise }'
|
||||
mutation 'foo(&:bar).baz { }'
|
||||
mutation 'foo(nil).baz { }'
|
||||
mutation 'foo.baz { }'
|
||||
mutation 'self.baz { }'
|
||||
mutation 'foo(nil, &:bar).baz'
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue