Add explicit resbody mutator

Closes: #117
This commit is contained in:
Markus Schirp 2013-12-01 22:42:52 +01:00
parent ec55f85804
commit 27d8387795
4 changed files with 107 additions and 12 deletions

View file

@ -92,6 +92,7 @@ require 'mutant/mutator/node/block'
require 'mutant/mutator/node/if'
require 'mutant/mutator/node/case'
require 'mutant/mutator/node/splat'
require 'mutant/mutator/node/resbody'
require 'mutant/config'
require 'mutant/loader'
require 'mutant/context'

View file

@ -12,7 +12,7 @@ module Mutant
handle(
:ensure,
:rescue, :redo, :defined?,
:regopt, :resbody, :retry, :arg_expr,
:regopt, :retry, :arg_expr,
:kwrestarg, :kwoptarg, :kwarg, :undef, :module, :empty,
:alias, :for, :xstr, :back_ref, :class,
:sclass, :match_with_lvasgn, :match_current_line

View file

@ -0,0 +1,45 @@
module Mutant
class Mutator
class Node
# Mutator for resbody nodes
class Resbody < self
handle(:resbody)
children :captures, :assignment, :block
private
# Emit mutations
#
# @return [undefined]
#
# @api private
#
def dispatch
emit_assignment(nil)
emit_block_mutations if block
mutate_captures
end
# Mutate captures
#
# @return [undefined]
#
# @api private
#
def mutate_captures
return unless captures
emit_captures(nil)
Util::Array.each(captures.children, self) do |matchers|
next if matchers.empty?
emit_captures(s(:array, *matchers))
# p capture
# emit_captures(s(:array, *capture))
end
end
end # Resbody
end # Node
end # Mutator
end # Mutant

View file

@ -3,22 +3,71 @@
require 'spec_helper'
describe Mutant::Mutator::Node::Generic, 'rescue' do
let(:source) { 'begin; rescue Exception => e; true end' }
let(:mutations) do
mutations = []
mutations << 'begin; rescue Exception => srandom; true; end'
mutations << 'begin; rescue Exception => e; false; end'
mutations << 'begin; rescue Exception => e; nil; end'
mutations << 'begin; rescue nil => e; true; end'
# mutations << 'begin; rescue => e; true; end' # FIXME
end
before do
Mutant::Random.stub(hex_string: 'random')
end
pending do
context 'multiple exception selectors and assignment' do
let(:source) { 'begin; rescue ExceptionA, ExceptionB => error; true; end' }
let(:mutations) do
mutations = []
mutations << 'nil'
# mutations << 'begin; rescue ExceptionA, ExceptionB => error; true; end'
mutations << 'begin; rescue ExceptionA, ExceptionB; true; end'
mutations << 'begin; rescue ExceptionA, ExceptionB => error; false; end'
mutations << 'begin; rescue ExceptionA, ExceptionB => error; nil; end'
mutations << 'begin; rescue ExceptionA, nil => error; true; end'
mutations << 'begin; rescue ExceptionA => error; true; end'
mutations << 'begin; rescue ExceptionB => error; true; end'
mutations << 'begin; rescue nil, ExceptionB => error; true; end'
mutations << 'begin; rescue => error; true; end'
end
it_should_behave_like 'a mutator'
end
context 'single exception selector and assignment' do
let(:source) { 'begin; rescue Exception => error; true; end' }
let(:mutations) do
mutations = []
mutations << 'nil'
mutations << 'begin; rescue Exception; true; end'
mutations << 'begin; rescue Exception => error; false; end'
mutations << 'begin; rescue Exception => error; nil; end'
mutations << 'begin; rescue nil => error; true; end'
mutations << 'begin; rescue => error; true; end'
end
it_should_behave_like 'a mutator'
end
context 'no exection selector and assignment' do
let(:source) { 'begin; rescue => error; true end' }
let(:mutations) do
mutations = []
mutations << 'nil'
mutations << 'begin; rescue => error; false; end'
mutations << 'begin; rescue => error; nil; end'
mutations << 'begin; rescue; true; end'
end
it_should_behave_like 'a mutator'
end
context 'no exection selector and no assignment' do
let(:source) { 'begin; rescue; true end' }
let(:mutations) do
mutations = []
mutations << 'nil'
mutations << 'begin; rescue; false; end'
mutations << 'begin; rescue; nil; end'
end
it_should_behave_like 'a mutator'
end
end