Replace empty body/block mutations with raise

This commit is contained in:
Markus Schirp 2013-07-02 20:42:09 +02:00
parent 2c6b106848
commit 04c72c5d0f
5 changed files with 23 additions and 20 deletions

View file

@ -21,9 +21,8 @@ module Mutant
emit_arguments_mutations
if body
emit_body_mutations
else
emit_body(NEW_OBJECT)
end
emit_body(RAISE)
end
end # Block

View file

@ -14,11 +14,8 @@ module Mutant
#
def dispatch
emit_arguments_mutations
if body
emit_body_mutations
else
emit_body(NEW_OBJECT)
end
emit_body(RAISE)
emit_body_mutations if body
end
# Mutator for instance method defines

View file

@ -21,6 +21,8 @@ module Mutant
INFINITY = s(:send, s(:float, 1.0), :/, s(:args, s(:float, 0.0)))
NEW_OBJECT = s(:send, s(:const, s(:cbase), :Object), :new)
RAISE = s(:send, nil, :raise)
N_NIL = s(:nil)
N_EMPTY = s(:empty)

View file

@ -9,6 +9,7 @@ describe Mutant::Mutator, 'block' do
mutations << 'foo { a }'
mutations << 'foo { b }'
mutations << 'foo {}'
mutations << 'foo { raise }'
mutations << 'foo'
end
@ -26,7 +27,7 @@ describe Mutant::Mutator, 'block' do
let(:mutations) do
mutations = []
mutations << 'foo'
mutations << 'foo { |a, b| ::Object.new }'
mutations << 'foo { |a, b| raise }'
mutations << 'foo { |a, srandom| }'
mutations << 'foo { |srandom, b| }'
mutations << 'foo { |a| }'
@ -49,7 +50,7 @@ describe Mutant::Mutator, 'block' do
mutations = []
mutations << 'foo { || }'
mutations << 'foo { |a, b, c| }'
mutations << 'foo { |(a, b), c| ::Object.new }'
mutations << 'foo { |(a, b), c| raise }'
mutations << 'foo { |(a), c| }'
mutations << 'foo { |(b), c| }'
mutations << 'foo { |(a, b)| }'

View file

@ -7,7 +7,7 @@ describe Mutant::Mutator, 'def' do
let(:mutations) do
mutations = []
mutations << 'def foo; ::Object.new; end'
mutations << 'def foo; raise; end'
end
it_should_behave_like 'a mutator'
@ -31,6 +31,8 @@ describe Mutant::Mutator, 'def' do
# Remove all statements
mutations << 'def foo; end'
mutations << 'def foo; raise; end'
end
it_should_behave_like 'a mutator'
@ -58,7 +60,7 @@ describe Mutant::Mutator, 'def' do
mutations << 'def foo(a, srandom); end'
# Mutation of body
mutations << 'def foo(a, b); ::Object.new; end'
mutations << 'def foo(a, b); raise; end'
end
it_should_behave_like 'a mutator'
@ -69,7 +71,7 @@ describe Mutant::Mutator, 'def' do
let(:mutations) do
mutations = []
mutations << 'def foo(_unused); ::Object.new; end'
mutations << 'def foo(_unused); raise; end'
mutations << 'def foo; end'
end
@ -90,7 +92,7 @@ describe Mutant::Mutator, 'def' do
mutations << 'def foo(a = false); end'
mutations << 'def foo(a = nil); end'
mutations << 'def foo(srandom = true); end'
mutations << 'def foo(a = true); ::Object.new; end'
mutations << 'def foo(a = true); raise; end'
end
it_should_behave_like 'a mutator'
@ -114,6 +116,8 @@ describe Mutant::Mutator, 'def' do
# Remove all statements
mutations << 'def self.foo; end'
mutations << 'def self.foo; raise; end'
end
it_should_behave_like 'a mutator'
@ -125,24 +129,24 @@ describe Mutant::Mutator, 'def' do
Mutant::Random.stub(:hex_string => 'random')
end
let(:source) { 'def self.foo(a, b); nil; end' }
let(:source) { 'def self.foo(a, b); end' }
let(:mutations) do
mutations = []
# Deletion of each argument
mutations << 'def self.foo(a); nil; end'
mutations << 'def self.foo(b); nil; end'
mutations << 'def self.foo(a); end'
mutations << 'def self.foo(b); end'
# Deletion of all arguments
mutations << 'def self.foo; nil; end'
mutations << 'def self.foo; end'
# Rename each argument
mutations << 'def self.foo(srandom, b); nil; end'
mutations << 'def self.foo(a, srandom); nil; end'
mutations << 'def self.foo(srandom, b); end'
mutations << 'def self.foo(a, srandom); end'
# Mutation of body
mutations << 'def self.foo(a, b); ::Object.new; end'
mutations << 'def self.foo(a, b); raise; end'
end
it_should_behave_like 'a mutator'