Fix emit of invalid block body promotions

This commit is contained in:
Markus Schirp 2018-12-24 00:09:36 +00:00
parent 1b1bca68bd
commit 64862e8b86
2 changed files with 68 additions and 1 deletions

View file

@ -32,12 +32,21 @@ module Mutant
emit_body(N_RAISE)
return unless body
emit(body)
emit(body) unless body_has_control?
emit_body_mutations
mutate_body_receiver
end
# Test if body has control structures
#
# @return [Boolean]
def body_has_control?
AST.find_last_path(body) do |node|
n_break?(node) || n_next?(node)
end.any?
end
# Mutate method send in body scope of `send`
#
# @return [undefined]

View file

@ -121,3 +121,61 @@ Mutant::Meta::Example.add :block do
mutation 'foo { }'
mutation 'foo'
end
Mutant::Meta::Example.add :block do
source 'foo { next if true }'
singleton_mutations
mutation 'foo'
mutation 'foo { }'
mutation 'foo { self }'
mutation 'foo { nil }'
mutation 'foo { raise }'
mutation 'foo { self if true }'
mutation 'foo { nil if true }'
mutation 'foo { break if true }'
mutation 'foo { next if !true }'
mutation 'foo { next if false }'
mutation 'foo { next if nil }'
mutation 'foo { next }'
end
Mutant::Meta::Example.add :block do
source 'foo { next }'
singleton_mutations
mutation 'foo { nil }'
mutation 'foo { raise }'
mutation 'foo { self }'
mutation 'foo { break }'
mutation 'foo { }'
mutation 'foo'
end
Mutant::Meta::Example.add :block do
source 'foo { break if true }'
singleton_mutations
mutation 'foo'
mutation 'foo { }'
mutation 'foo { self }'
mutation 'foo { nil }'
mutation 'foo { raise }'
mutation 'foo { self if true }'
mutation 'foo { nil if true }'
mutation 'foo { break if !true }'
mutation 'foo { break if false }'
mutation 'foo { break if nil }'
mutation 'foo { break }'
end
Mutant::Meta::Example.add :block do
source 'foo { break }'
singleton_mutations
mutation 'foo { nil }'
mutation 'foo { raise }'
mutation 'foo { self }'
mutation 'foo { }'
mutation 'foo'
end