Do not create empty blocks on mutations

This commit is contained in:
Markus Schirp 2012-08-13 20:40:00 +02:00
parent d140ef2435
commit 6f8d4e1cfa
3 changed files with 37 additions and 14 deletions

View file

@ -3,7 +3,7 @@ module Mutant
# Mutator on AST blocks
class Block < self
handle Rubinius::AST::Block
handle(Rubinius::AST::Block)
private
@ -16,7 +16,11 @@ module Mutant
def dispatch
array = node.array
emit_elements(array)
emit_element_presence(array)
if array.length > 1
emit_element_presence(array)
else
emit_self([new_nil])
end
end
end
end

View file

@ -3,7 +3,10 @@ shared_examples_for 'a mutator' do
let(:yields) { [] }
let(:object) { described_class }
let(:node) { source.to_ast }
unless instance_methods.map(&:to_s).include?('node')
let(:node) { source.to_ast }
end
it_should_behave_like 'a command method'

View file

@ -1,20 +1,36 @@
require 'spec_helper'
describe Mutant::Mutator, 'block' do
# Two send operations
let(:source) { "self.foo\nself.bar" }
let(:mutations) do
mutations = []
context 'with more than one statement' do
let(:source) { "self.foo\nself.bar" }
# Mutation of each statement in block
mutations << "foo\nself.bar"
mutations << "self.foo\nbar"
let(:mutations) do
mutations = []
## Remove statement in block
mutations << [:block, 'self.foo'.to_sexp]
mutations << [:block, 'self.bar'.to_sexp]
# Mutation of each statement in block
mutations << "foo\nself.bar"
mutations << "self.foo\nbar"
## Remove statement in block
mutations << [:block, 'self.foo'.to_sexp]
mutations << [:block, 'self.bar'.to_sexp]
end
it_should_behave_like 'a mutator'
end
it_should_behave_like 'a mutator'
context 'with one statement' do
let(:node) { Rubinius::AST::Block.new(1, ['self.foo'.to_ast]) }
let(:mutations) do
mutations = []
mutations << [:block, 'foo'.to_sexp]
# Empty blocks result in stack verification error
mutations << [:block, 'nil'.to_sexp]
end
it_should_behave_like 'a mutator'
end
end