Do not mutate underscore prefixed args or lvars

This commit is contained in:
Markus Schirp 2012-12-29 23:07:45 +01:00
parent a06030ef06
commit 07bb7b5bf6
4 changed files with 33 additions and 1 deletions

View file

@ -1,5 +1,6 @@
# v0.2.8 2012-12-29 # v0.2.8 2012-12-29
* [feature] Do not mutate argument or local variable names beginning with an underscore
* [feature] Mutate unary calls ```coerce(object)``` => ```object``` * [feature] Mutate unary calls ```coerce(object)``` => ```object```
* [feature] Mutate method call receivers ```foo.bar``` => ```foo``` * [feature] Mutate method call receivers ```foo.bar``` => ```foo```

5
TODO
View file

@ -12,6 +12,11 @@ Mutations:
* Mutate options on Regexp literals * Mutate options on Regexp literals
* Add mutations for dynamic regexp symbol and string literals * Add mutations for dynamic regexp symbol and string literals
* Mutate "def foo; bar; end" to "def foo; self; end"? * Mutate "def foo; bar; end" to "def foo; self; end"?
* Emit negative and positive mutations
Example of a negative mutation:
Mutations on local variables and arguments prefixed with an underscore would be emitted as
negative mutations that must be alive.
Loader: Loader:
* Make sure loader does not change visibility of injected mutants * Make sure loader does not change visibility of injected mutants

View file

@ -16,7 +16,21 @@ module Mutant
# @api private # @api private
# #
def dispatch def dispatch
emit_new { :"s#{Random.hex_string}" } emit_new { :"s#{Random.hex_string}" } unless ignore?
end
# Test if symbol is ignored
#
# @return [true]
# if symbol begins with an underscore
#
# @return [false]
# otherwise
#
# @pai private
#
def ignore?
input.to_s[0] == '_'
end end
end end

View file

@ -51,6 +51,18 @@ describe Mutant::Mutator, 'define' do
it_should_behave_like 'a mutator' it_should_behave_like 'a mutator'
end end
context 'with arguments beginning with an underscore' do
let(:source) { 'def foo(_unused); end' }
let(:mutations) do
mutations = []
mutations << 'def foo(_unused); Object.new; end'
mutations << 'def foo; end'
end
it_should_behave_like 'a mutator'
end
context 'default argument' do context 'default argument' do
let(:source) { 'def foo(a = "literal"); end' } let(:source) { 'def foo(a = "literal"); end' }