Add return statement mutations

This commit is contained in:
Markus Schirp 2012-12-06 19:53:44 +01:00
parent 5a2f71abec
commit f5274a3e20
8 changed files with 88 additions and 26 deletions

25
Gemfile
View file

@ -6,27 +6,4 @@ gem 'to_source', :git => 'https://github.com/mbj/to_source.git'
gem 'melbourne', :git => 'https://github.com/mbj/melbourne.git'
gem 'inflector', :git => 'https://github.com/mbj/inflector.git'
group :development do
gem 'rake', '~> 0.9.2'
gem 'yard', '~> 0.8.1'
gem 'rspec', '~> 2'
end
group :guard do
gem 'guard', '~> 1.3.2'
gem 'guard-bundler', '~> 1.0.0'
gem 'guard-rspec', '~> 1.2.1'
# Remove this once https://github.com/nex3/rb-inotify/pull/20 is solved.
# This patch makes rb-inotify a nice player with listen so it does not poll.
gem 'rb-inotify', :git => 'https://github.com/mbj/rb-inotify'
end
group :metrics do
gem 'flay', '~> 1.4.2'
gem 'flog', '~> 2.5.1'
gem 'reek', '~> 1.2.8', :git => 'https://github.com/dkubb/reek.git'
gem 'roodi', '~> 2.1.0'
gem 'yardstick', '~> 0.5.0'
gem 'yard-spellcheck', '~> 0.1.5'
gem 'pelusa', '~> 0.2.1'
end
eval(File.read(File.join(File.dirname(__FILE__),'Gemfile.devtools')))

22
Gemfile.devtools Normal file
View file

@ -0,0 +1,22 @@
group :development do
gem 'rake', '~> 0.9.2'
gem 'rspec', '~> 2.12.0'
gem 'yard', '~> 0.8.3'
end
group :guard do
gem 'guard', '~> 1.5.4'
gem 'guard-bundler', '~> 1.0.0'
gem 'guard-rspec', '~> 2.1.1'
gem 'rb-inotify', :git => 'https://github.com/mbj/rb-inotify'
end
group :benchmarks do
gem 'rbench', '~> 0.2.3'
end
platform :jruby do
group :jruby do
gem 'jruby-openssl', '~> 0.7.4'
end
end

View file

@ -4,7 +4,7 @@ guard :bundler do
watch('Gemfile')
end
guard :rspec, :version => 2 do
guard :rspec, :all_on_start => false do
# run all specs if the spec_helper or supporting files files are modified
watch('spec/spec_helper.rb') { 'spec/unit' }
watch(%r{\Aspec/(?:lib|support|shared)/.+\.rb\z}) { 'spec/unit' }

View file

@ -69,6 +69,7 @@ require 'mutant/mutator/block'
require 'mutant/mutator/noop'
require 'mutant/mutator/call'
require 'mutant/mutator/define'
require 'mutant/mutator/return'
require 'mutant/mutator/if_statement'
require 'mutant/mutator/receiver_case'
require 'mutant/loader'

View file

@ -6,7 +6,6 @@ module Mutant
# Literal references to self do not need to be mutated.
handle(Rubinius::AST::Self)
# Some unimplemented mutations
handle(Rubinius::AST::Return)
handle(Rubinius::AST::ElementAssignment)
handle(Rubinius::AST::AttributeAssignment)
handle(Rubinius::AST::Not)

View file

@ -0,0 +1,29 @@
module Mutant
class Mutator
# Mutator for return statements
class Return < self
handle(Rubinius::AST::Return)
private
# Emit mutants
#
# @return [undefined]
#
# @api private
#
def dispatch
value = node.value
if value
emit(value)
else
emit_nil
end
end
end
end
end

View file

@ -0,0 +1,13 @@
require 'spec_helper'
describe Mutant::Mutator::Literal, 'nil' do
let(:source) { 'nil' }
let(:mutations) do
mutations = []
mutations << 'Object.new'
end
it_should_behave_like 'a mutator'
end

View file

@ -0,0 +1,21 @@
require 'spec_helper'
describe Mutant::Mutator, 'return' do
context 'return without value' do
let(:source) { 'return' }
let(:mutations) { ['nil'] }
it_should_behave_like 'a mutator'
end
context 'return with value' do
let(:source) { 'return foo' }
let(:mutations) { ['foo'] }
it_should_behave_like 'a mutator'
end
end