Change emit_nil to not emit on the left node of an assignment
* Add emit_nil to other nodes so that they can be replaced with nil, effectively removing them from the code.
This commit is contained in:
parent
58e6910573
commit
475512146f
28 changed files with 129 additions and 18 deletions
|
@ -181,7 +181,7 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def emit_nil
|
||||
emit(N_NIL)
|
||||
emit(N_NIL) unless agsn_left?
|
||||
end
|
||||
|
||||
# Return new self typed child
|
||||
|
@ -222,6 +222,17 @@ module Mutant
|
|||
parent && parent.node.type
|
||||
end
|
||||
|
||||
# Test if the node is the left of an or_asgn or op_asgn
|
||||
#
|
||||
# @return [Boolean]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def agsn_left?
|
||||
[:or_asgn, :op_asgn, :and_asgn].include?(parent_type) &&
|
||||
parent.left.equal?(node)
|
||||
end
|
||||
|
||||
end # Node
|
||||
end # Mutator
|
||||
end # Mutant
|
||||
|
|
|
@ -26,6 +26,7 @@ module Mutant
|
|||
end
|
||||
emit_body(nil)
|
||||
emit_body(RAISE)
|
||||
emit_nil
|
||||
end
|
||||
|
||||
end # Block
|
||||
|
|
|
@ -23,6 +23,7 @@ module Mutant
|
|||
emit_condition_mutations
|
||||
emit_when_mutations
|
||||
emit_else_mutations
|
||||
emit_nil
|
||||
end
|
||||
|
||||
# Emit when mutations
|
||||
|
|
|
@ -9,6 +9,19 @@ module Mutant
|
|||
|
||||
handle(:dstr)
|
||||
|
||||
private
|
||||
|
||||
# Emit mutations
|
||||
#
|
||||
# @return [undefined]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def dispatch
|
||||
super
|
||||
emit_nil
|
||||
end
|
||||
|
||||
end # Dstr
|
||||
end # Node
|
||||
end # Mutator
|
||||
|
|
|
@ -22,6 +22,7 @@ module Mutant
|
|||
mutate_condition
|
||||
mutate_if_branch
|
||||
mutate_else_branch
|
||||
emit_nil
|
||||
end
|
||||
|
||||
# Emit conditon mutations
|
||||
|
|
|
@ -20,7 +20,7 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def dispatch
|
||||
# noop, for now
|
||||
emit_nil
|
||||
end
|
||||
|
||||
end # MultipleAssignment
|
||||
|
|
|
@ -30,6 +30,7 @@ module Mutant
|
|||
def dispatch
|
||||
mutate_name
|
||||
emit_value_mutations if value # mlhs!
|
||||
emit_nil
|
||||
end
|
||||
|
||||
# Emit name mutations
|
||||
|
|
|
@ -22,9 +22,8 @@ module Mutant
|
|||
if value
|
||||
emit(value)
|
||||
emit_value_mutations
|
||||
else
|
||||
emit_nil
|
||||
end
|
||||
emit_nil
|
||||
end
|
||||
|
||||
end # Return
|
||||
|
|
|
@ -71,6 +71,7 @@ module Mutant
|
|||
else
|
||||
non_index_dispatch
|
||||
end
|
||||
emit_nil
|
||||
end
|
||||
|
||||
# Perform non index dispatch
|
||||
|
|
|
@ -27,6 +27,7 @@ module Mutant
|
|||
mutate_child(index)
|
||||
delete_child(index)
|
||||
end
|
||||
emit_nil
|
||||
end
|
||||
|
||||
end # Super
|
||||
|
|
|
@ -23,6 +23,7 @@ module Mutant
|
|||
emit_condition_mutations
|
||||
emit_body_mutations
|
||||
emit_body(nil)
|
||||
emit_nil
|
||||
end
|
||||
|
||||
end # While
|
||||
|
|
|
@ -12,7 +12,10 @@ describe Mutant::Mutator, 'block' do
|
|||
mutations << 'foo { b }'
|
||||
mutations << 'foo {}'
|
||||
mutations << 'foo { raise }'
|
||||
mutations << 'foo { a; nil }'
|
||||
mutations << 'foo { nil; b }'
|
||||
mutations << 'foo'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -35,6 +38,7 @@ describe Mutant::Mutator, 'block' do
|
|||
mutations << 'foo { |a| }'
|
||||
mutations << 'foo { |b| }'
|
||||
mutations << 'foo { || }'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -61,6 +65,7 @@ describe Mutant::Mutator, 'block' do
|
|||
mutations << 'foo { |(a, srandom), c| }'
|
||||
mutations << 'foo { |(a, b), srandom| }'
|
||||
mutations << 'foo'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
|
|
@ -8,6 +8,7 @@ describe Mutant::Mutator::Node::NamedValue::Access, 'block_pass' do
|
|||
let(:mutations) do
|
||||
mutants = []
|
||||
mutants << 'foo'
|
||||
mutants << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
|
|
@ -217,6 +217,8 @@ describe Mutant::Mutator::Node::Case do
|
|||
:else
|
||||
end
|
||||
RUBY
|
||||
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -314,6 +316,8 @@ describe Mutant::Mutator::Node::Case do
|
|||
:else
|
||||
end
|
||||
RUBY
|
||||
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
|
|
@ -4,7 +4,11 @@ require 'spec_helper'
|
|||
|
||||
describe Mutant::Mutator::Node::Generic, 'defined?' do
|
||||
let(:source) { 'defined?(foo)' }
|
||||
let(:mutations) { [] }
|
||||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << 'defined?(nil)'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
end
|
||||
|
|
|
@ -15,6 +15,8 @@ describe Mutant::Mutator::Node::Dstr, 'dstr' do
|
|||
mutations << '"#{nil}#{bar}baz"'
|
||||
mutations << '"foo#{bar}random"'
|
||||
mutations << '"foo#{bar}#{nil}"'
|
||||
mutations << '"foo#{nil}baz"'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
|
|
@ -15,6 +15,7 @@ describe Mutant::Mutator::Node::Generic, 'dsum' do
|
|||
mutations << ':"#{nil}#{bar}baz"'
|
||||
mutations << ':"foo#{bar}random"'
|
||||
mutations << ':"foo#{bar}#{nil}"'
|
||||
mutations << ':"foo#{nil}baz"'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
|
|
@ -36,6 +36,8 @@ describe Mutant::Mutator, 'if' do
|
|||
# mutations of else body
|
||||
mutants << 'if :condition; true; else true; end'
|
||||
mutants << 'if :condition; true; else nil; end'
|
||||
|
||||
mutants << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -51,6 +53,8 @@ describe Mutant::Mutator, 'if' do
|
|||
mutants << 'if condition; nil; end'
|
||||
mutants << 'if true; true; end'
|
||||
mutants << 'if false; true; end'
|
||||
mutants << 'if nil; true; end'
|
||||
mutants << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -69,6 +73,7 @@ describe Mutant::Mutator, 'if' do
|
|||
mutants << 'unless true; true; end'
|
||||
mutants << 'unless false; true; end'
|
||||
mutants << 'if :condition; true; end'
|
||||
mutants << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
|
|
@ -9,9 +9,9 @@ describe Mutant::Mutator::Node::Literal, 'regex' do
|
|||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << 'nil'
|
||||
mutations << '//' # match all
|
||||
mutations << '/a\A/' # match nothing
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -22,10 +22,12 @@ describe Mutant::Mutator::Node::Literal, 'regex' do
|
|||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << 'nil'
|
||||
mutations << '//' # match all
|
||||
mutations << '/#{foo}n/' # match all
|
||||
mutations << '/a\A/' # match nothing
|
||||
mutations << '/#{nil.bar}n/'
|
||||
mutations << '/#{nil}n/'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
|
|
@ -4,7 +4,11 @@ require 'spec_helper'
|
|||
|
||||
describe Mutant::Mutator, 'masgn' do
|
||||
let(:source) { 'a, b = c, d' }
|
||||
let(:mutations) { [] }
|
||||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
end
|
||||
|
|
|
@ -14,6 +14,7 @@ describe Mutant::Mutator::Node::Generic, 'match_current_line' do
|
|||
mutations << 'true if nil'
|
||||
mutations << 'true if !//'
|
||||
mutations << 'true if /a\A/'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
|
|
@ -17,6 +17,7 @@ describe Mutant::Mutator::Node::NamedValue::Access, 'mutations' do
|
|||
mutants << '$a'
|
||||
mutants << '$a = ::Object.new; $a'
|
||||
mutants << '$srandom = nil; $a'
|
||||
mutants << 'nil; $a'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -32,6 +33,7 @@ describe Mutant::Mutator::Node::NamedValue::Access, 'mutations' do
|
|||
mutants << '@@a'
|
||||
mutants << '@@a = ::Object.new; @@a'
|
||||
mutants << '@@srandom = nil; @@a'
|
||||
mutants << 'nil; @@a'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -45,6 +47,7 @@ describe Mutant::Mutator::Node::NamedValue::Access, 'mutations' do
|
|||
mutants << '@a'
|
||||
mutants << '@a = ::Object.new; @a'
|
||||
mutants << '@srandom = nil; @a'
|
||||
mutants << 'nil; @a'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -60,6 +63,7 @@ describe Mutant::Mutator::Node::NamedValue::Access, 'mutations' do
|
|||
mutants << 'a'
|
||||
mutants << 'a = ::Object.new; a'
|
||||
mutants << 'srandom = nil; a'
|
||||
mutants << 'nil; a'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
|
|
@ -15,6 +15,7 @@ describe Mutant::Mutator::Node::NamedValue::VariableAssignment, 'mutations' do
|
|||
mutations << '$srandom = true'
|
||||
mutations << '$a = false'
|
||||
mutations << '$a = nil'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -25,10 +26,10 @@ describe Mutant::Mutator::Node::NamedValue::VariableAssignment, 'mutations' do
|
|||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
|
||||
mutations << '@@srandom = true'
|
||||
mutations << '@@a = false'
|
||||
mutations << '@@a = nil'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -39,10 +40,10 @@ describe Mutant::Mutator::Node::NamedValue::VariableAssignment, 'mutations' do
|
|||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
|
||||
mutations << '@srandom = true'
|
||||
mutations << '@a = false'
|
||||
mutations << '@a = nil'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -53,10 +54,10 @@ describe Mutant::Mutator::Node::NamedValue::VariableAssignment, 'mutations' do
|
|||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
|
||||
mutations << 'srandom = true'
|
||||
mutations << 'a = false'
|
||||
mutations << 'a = nil'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
|
|
@ -10,6 +10,8 @@ describe Mutant::Mutator::Node::Generic, 'restarg' do
|
|||
mutants << 'foo'
|
||||
mutants << 'foo(nil)'
|
||||
mutants << 'foo(bar)'
|
||||
mutants << 'foo(*nil)'
|
||||
mutants << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
|
|
@ -7,18 +7,22 @@ describe Mutant::Mutator, 'return' do
|
|||
context 'return without value' do
|
||||
let(:source) { 'return' }
|
||||
|
||||
let(:mutations) { ['nil'] }
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
end
|
||||
|
||||
context 'return with value' do
|
||||
let(:source) { 'return nil' }
|
||||
let(:source) { 'return foo' }
|
||||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << 'foo'
|
||||
mutations << 'return nil'
|
||||
mutations << 'nil'
|
||||
mutations << 'return ::Object.new'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
|
|
@ -15,6 +15,10 @@ describe Mutant::Mutator, 'send' do
|
|||
mutations << 'foo.gsub(b)'
|
||||
mutations << 'foo.gsub'
|
||||
mutations << 'foo.sub(a, b)'
|
||||
mutations << 'foo.gsub(a, nil)'
|
||||
mutations << 'foo.gsub(nil, b)'
|
||||
mutations << 'nil.gsub(a, b)'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -29,6 +33,9 @@ describe Mutant::Mutator, 'send' do
|
|||
mutations << 'foo.public_send(bar)'
|
||||
mutations << 'bar'
|
||||
mutations << 'foo'
|
||||
mutations << 'foo.send(nil)'
|
||||
mutations << 'nil.send(bar)'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -40,6 +47,7 @@ describe Mutant::Mutator, 'send' do
|
|||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << 'foo ||= expression'
|
||||
mutations << 'self.foo ||= nil'
|
||||
mutations << 'nil.foo ||= expression'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
@ -53,6 +61,7 @@ describe Mutant::Mutator, 'send' do
|
|||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << 'foo'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -66,6 +75,8 @@ describe Mutant::Mutator, 'send' do
|
|||
mutations << 'foo'
|
||||
mutations << 'foo(nil)'
|
||||
mutations << 'foo(bar)'
|
||||
mutations << 'foo(*nil)'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -77,6 +88,7 @@ describe Mutant::Mutator, 'send' do
|
|||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << 'foo'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -88,6 +100,7 @@ describe Mutant::Mutator, 'send' do
|
|||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << 'foo'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -97,7 +110,12 @@ describe Mutant::Mutator, 'send' do
|
|||
context 'implicit' do
|
||||
let(:source) { 'foo' }
|
||||
|
||||
it_should_behave_like 'a noop mutator'
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
end
|
||||
|
||||
context 'explict receiver' do
|
||||
|
@ -108,6 +126,7 @@ describe Mutant::Mutator, 'send' do
|
|||
mutations << 'foo'
|
||||
mutations << 'self'
|
||||
mutations << 'nil.foo'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -133,6 +152,8 @@ describe Mutant::Mutator, 'send' do
|
|||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << 'foo'
|
||||
mutations << 'nil.bar'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -146,6 +167,8 @@ describe Mutant::Mutator, 'send' do
|
|||
mutations << 'self.class'
|
||||
mutations << 'self.foo'
|
||||
mutations << 'nil.class.foo'
|
||||
mutations << 'nil.foo'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -192,8 +215,9 @@ describe Mutant::Mutator, 'send' do
|
|||
mutations = []
|
||||
mutations << "foo.#{keyword}"
|
||||
mutations << 'foo'
|
||||
mutations << 'nil'
|
||||
mutations << "foo.#{keyword}(::Object.new)"
|
||||
mutations << "nil.#{keyword}(nil)"
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -210,6 +234,7 @@ describe Mutant::Mutator, 'send' do
|
|||
mutations << 'foo(nil)'
|
||||
mutations << 'foo(::Object.new, nil)'
|
||||
mutations << 'foo(nil, ::Object.new)'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -225,6 +250,11 @@ describe Mutant::Mutator, 'send' do
|
|||
mutations << '(left - right)'
|
||||
mutations << 'left / foo'
|
||||
mutations << 'right / foo'
|
||||
mutations << '(left - right) / nil'
|
||||
mutations << '(left - nil) / foo'
|
||||
mutations << '(nil - right) / foo'
|
||||
mutations << 'nil / foo'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -242,6 +272,7 @@ describe Mutant::Mutator, 'send' do
|
|||
mutations << "true #{operator} nil"
|
||||
mutations << 'true'
|
||||
mutations << 'false'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -253,6 +284,9 @@ describe Mutant::Mutator, 'send' do
|
|||
mutations = []
|
||||
mutations << 'left'
|
||||
mutations << 'right'
|
||||
mutations << "left #{operator} nil"
|
||||
mutations << "nil #{operator} right"
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
|
|
@ -21,6 +21,7 @@ describe Mutant::Mutator, 'super' do
|
|||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << 'super'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
@ -35,6 +36,9 @@ describe Mutant::Mutator, 'super' do
|
|||
mutations << 'super()'
|
||||
mutations << 'super(foo)'
|
||||
mutations << 'super(bar)'
|
||||
mutations << 'super(foo, nil)'
|
||||
mutations << 'super(nil, bar)'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
|
|
@ -14,6 +14,9 @@ describe Mutant::Mutator::Node::While do
|
|||
mutations << 'while true; end'
|
||||
mutations << 'while false; foo; bar; end'
|
||||
mutations << 'while nil; foo; bar; end'
|
||||
mutations << 'while true; foo; nil; end'
|
||||
mutations << 'while true; nil; bar; end'
|
||||
mutations << 'nil'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
|
|
Loading…
Add table
Reference in a new issue