Fix invalid AST emit
* Mutant prevents double emits via guarding on source representation of partial AST nodes. Not all AST nodes are valid as roots, so this change creates a valid root around an leave. * Over the time multiple of these situartions must be solved, we'll end up in a more deduplicated solution. * Closes: #165
This commit is contained in:
parent
4b1566caa6
commit
e93960ca35
4 changed files with 41 additions and 3 deletions
|
@ -87,6 +87,7 @@ require 'mutant/mutator/node/if'
|
||||||
require 'mutant/mutator/node/case'
|
require 'mutant/mutator/node/case'
|
||||||
require 'mutant/mutator/node/splat'
|
require 'mutant/mutator/node/splat'
|
||||||
require 'mutant/mutator/node/resbody'
|
require 'mutant/mutator/node/resbody'
|
||||||
|
require 'mutant/mutator/node/rescue'
|
||||||
require 'mutant/config'
|
require 'mutant/config'
|
||||||
require 'mutant/loader'
|
require 'mutant/loader'
|
||||||
require 'mutant/context'
|
require 'mutant/context'
|
||||||
|
|
|
@ -10,9 +10,7 @@ module Mutant
|
||||||
# These nodes still need a dedicated mutator,
|
# These nodes still need a dedicated mutator,
|
||||||
# your contribution is that close!
|
# your contribution is that close!
|
||||||
handle(
|
handle(
|
||||||
:ensure,
|
:ensure, :redo, :defined?, :regopt, :retry, :arg_expr,
|
||||||
:rescue, :redo, :defined?,
|
|
||||||
:regopt, :retry, :arg_expr,
|
|
||||||
:kwrestarg, :kwoptarg, :kwarg, :undef, :module, :empty,
|
:kwrestarg, :kwoptarg, :kwarg, :undef, :module, :empty,
|
||||||
:alias, :for, :xstr, :back_ref, :class,
|
:alias, :for, :xstr, :back_ref, :class,
|
||||||
:sclass, :match_with_lvasgn, :match_current_line, :while_post,
|
:sclass, :match_with_lvasgn, :match_current_line, :while_post,
|
||||||
|
|
26
lib/mutant/mutator/node/rescue.rb
Normal file
26
lib/mutant/mutator/node/rescue.rb
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
module Mutant
|
||||||
|
class Mutator
|
||||||
|
class Node
|
||||||
|
# Mutator for rescue nodes
|
||||||
|
class Rescue < Generic
|
||||||
|
|
||||||
|
handle :rescue
|
||||||
|
|
||||||
|
# Return identity
|
||||||
|
#
|
||||||
|
# @param [Parser::AST::Node] node
|
||||||
|
#
|
||||||
|
# @return [String]
|
||||||
|
#
|
||||||
|
# @api private
|
||||||
|
#
|
||||||
|
def self.identity(node)
|
||||||
|
super(NodeHelpers.s(:kwbegin, node))
|
||||||
|
end
|
||||||
|
|
||||||
|
end # Rescue
|
||||||
|
end # Node
|
||||||
|
end # Mutator
|
||||||
|
end # Mutant
|
|
@ -14,6 +14,19 @@ describe Mutant::Mutator, 'def' do
|
||||||
it_should_behave_like 'a mutator'
|
it_should_behave_like 'a mutator'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'empty rescue body' do
|
||||||
|
let(:source) { "def foo\nfoo\nrescue\nend" }
|
||||||
|
|
||||||
|
let(:mutations) do
|
||||||
|
mutations = []
|
||||||
|
mutations << 'def foo; raise; end'
|
||||||
|
mutations << 'def foo; nil; rescue; end'
|
||||||
|
mutations << 'def foo; end'
|
||||||
|
end
|
||||||
|
|
||||||
|
it_should_behave_like 'a mutator'
|
||||||
|
end
|
||||||
|
|
||||||
context 'with no arguments' do
|
context 'with no arguments' do
|
||||||
let(:source) { 'def foo; true; false; end' }
|
let(:source) { 'def foo; true; false; end' }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue