parent
ec55f85804
commit
27d8387795
4 changed files with 107 additions and 12 deletions
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
45
lib/mutant/mutator/node/resbody.rb
Normal file
45
lib/mutant/mutator/node/resbody.rb
Normal 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
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue