Merge pull request #71 from mbj/const-mutator

Const access and assignment mutators
This commit is contained in:
Markus Schirp 2013-07-23 00:31:19 -07:00
commit 795be2c7e5
14 changed files with 179 additions and 123 deletions

View file

@ -1,3 +1,3 @@
--- ---
threshold: 16 threshold: 16
total_score: 722 total_score: 730

View file

@ -54,17 +54,17 @@ require 'mutant/mutator/node/literal/array'
require 'mutant/mutator/node/literal/hash' require 'mutant/mutator/node/literal/hash'
require 'mutant/mutator/node/literal/regex' require 'mutant/mutator/node/literal/regex'
require 'mutant/mutator/node/literal/nil' require 'mutant/mutator/node/literal/nil'
require 'mutant/mutator/node/assignment'
require 'mutant/mutator/node/argument' require 'mutant/mutator/node/argument'
require 'mutant/mutator/node/arguments' require 'mutant/mutator/node/arguments'
require 'mutant/mutator/node/begin' require 'mutant/mutator/node/begin'
require 'mutant/mutator/node/variable' require 'mutant/mutator/node/named_value/access'
require 'mutant/mutator/node/named_value/constant_assignment'
require 'mutant/mutator/node/named_value/variable_assignment'
require 'mutant/mutator/node/while' require 'mutant/mutator/node/while'
require 'mutant/mutator/node/super' require 'mutant/mutator/node/super'
require 'mutant/mutator/node/send' require 'mutant/mutator/node/send'
require 'mutant/mutator/node/send/binary' require 'mutant/mutator/node/send/binary'
require 'mutant/mutator/node/when' require 'mutant/mutator/node/when'
require 'mutant/mutator/node/assignment'
require 'mutant/mutator/node/define' require 'mutant/mutator/node/define'
require 'mutant/mutator/node/mlhs' require 'mutant/mutator/node/mlhs'
require 'mutant/mutator/node/masgn' require 'mutant/mutator/node/masgn'

View file

@ -13,8 +13,8 @@ module Mutant
:zsuper, :not, :or, :and, :defined, :zsuper, :not, :or, :and, :defined,
:next, :break, :match, :ensure, :next, :break, :match, :ensure,
:dstr, :dsym, :yield, :rescue, :redo, :defined?, :dstr, :dsym, :yield, :rescue, :redo, :defined?,
:const, :blockarg, :block_pass, :op_asgn, :and_asgn, :blockarg, :block_pass, :op_asgn, :and_asgn,
:regopt, :restarg, :casgn, :resbody, :retry, :arg_expr, :regopt, :restarg, :resbody, :retry, :arg_expr,
:kwrestarg, :kwoptarg, :kwarg, :undef, :module, :cbase, :empty, :kwrestarg, :kwoptarg, :kwarg, :undef, :module, :cbase, :empty,
:alias, :for, :xstr, :back_ref, :nth_ref, :class, :alias, :for, :xstr, :back_ref, :nth_ref, :class,
:sclass, :match_with_lvasgn, :match_current_line, :or_asgn, :kwbegin :sclass, :match_with_lvasgn, :match_current_line, :or_asgn, :kwbegin

View file

@ -0,0 +1,27 @@
module Mutant
class Mutator
class Node
module NamedValue
# Mutation emitter to handle value access nodes
class Access < Node
handle(:gvar, :cvar, :ivar, :lvar, :const)
private
# Emit mutations
#
# @return [undefined]
#
# @api private
#
def dispatch
emit_nil
end
end # Access
end # NamedValue
end # Node
end # Mutator
end # Mutant

View file

@ -0,0 +1,42 @@
module Mutant
class Mutator
class Node
module NamedValue
# Mutation emitter to handle constant assignment nodes
class ConstantAssignment < Node
children :cbase, :name, :value
handle :casgn
private
# Perform dispatch
#
# @return [undefined]
#
# @api private
#
def dispatch
mutate_name
emit_value_mutations if value
end
# Emit name mutations
#
# @return [undefined]
#
# @api private
#
def mutate_name
Mutator::Util::Symbol.each(name, self) do |name|
emit_name(name.upcase)
end
end
end # ConstantAssignment
end # NamedValue
end # Node
end # Mutator
end # Mutant

View file

@ -1,11 +1,10 @@
module Mutant module Mutant
class Mutator class Mutator
class Node class Node
# Mutator base class for assignments module NamedValue
class Assignment < self
# Mutator for variable assignment # Mutation emitter to handle variable assignment nodes
class Variable < self class VariableAssignment < Node
children :name, :value children :name, :value
@ -40,12 +39,12 @@ module Mutant
def mutate_name def mutate_name
prefix = MAP.fetch(node.type) prefix = MAP.fetch(node.type)
Mutator::Util::Symbol.each(name, self) do |name| Mutator::Util::Symbol.each(name, self) do |name|
emit_name("#{prefix}#{name}") emit_name(prefix + name.to_s)
end end
end end
end # Variable end # VariableAssignment
end # Assignment end # NamedValue
end # Node end # Node
end # Mutator end # Mutator
end # Mutant end # Mutant

View file

@ -1,25 +0,0 @@
module Mutant
class Mutator
class Node
# Mutation emitter to handle variable nodes
class Variable < self
handle(:gvar, :cvar, :ivar, :lvar)
private
# Emit mutations
#
# @return [undefined]
#
# @api private
#
def dispatch
emit_nil
end
end # Variable
end # Node
end # Mutator
end # Mutant

View file

@ -1,21 +0,0 @@
require 'spec_helper'
describe Mutant::Mutator, 'cvar' do
before do
Mutant::Random.stub(:hex_string => 'random')
end
let(:source) { '@@a = nil; @@a' }
let(:mutations) do
mutants = []
mutants << '@@a = nil; nil'
mutants << '@@a = nil'
mutants << '@@a'
mutants << '@@a = ::Object.new; @@a'
mutants << '@@srandom = nil; @@a'
end
it_should_behave_like 'a mutator'
end

View file

@ -1,21 +0,0 @@
require 'spec_helper'
describe Mutant::Mutator, 'gvar' do
before do
Mutant::Random.stub(:hex_string => 'random')
end
let(:source) { '$a = nil; $a' }
let(:mutations) do
mutants = []
mutants << '$a = nil; nil'
mutants << '$a = nil'
mutants << '$a'
mutants << '$a = ::Object.new; $a'
mutants << '$srandom = nil; $a'
end
it_should_behave_like 'a mutator'
end

View file

@ -1,21 +0,0 @@
require 'spec_helper'
describe Mutant::Mutator, 'ivar' do
before do
Mutant::Random.stub(:hex_string => 'random')
end
let(:source) { '@a = nil; @a' }
let(:mutations) do
mutants = []
mutants << '@a = nil; nil'
mutants << '@a = nil'
mutants << '@a'
mutants << '@a = ::Object.new; @a'
mutants << '@srandom = nil; @a'
end
it_should_behave_like 'a mutator'
end

View file

@ -1,21 +0,0 @@
require 'spec_helper'
describe Mutant::Mutator, 'lvar' do
before do
Mutant::Random.stub(:hex_string => 'random')
end
let(:source) { 'a = nil; a' }
let(:mutations) do
mutants = []
mutants << 'a = nil; nil'
mutants << 'a = nil'
mutants << 'a'
mutants << 'a = ::Object.new; a'
mutants << 'srandom = nil; a'
end
it_should_behave_like 'a mutator'
end

View file

@ -0,0 +1,77 @@
require 'spec_helper'
describe Mutant::Mutator::Node::NamedValue::Access, 'mutations' do
before do
Mutant::Random.stub(:hex_string => :random)
end
context 'global variable' do
let(:source) { '$a = nil; $a' }
let(:mutations) do
mutants = []
mutants << '$a = nil; nil'
mutants << '$a = nil'
mutants << '$a'
mutants << '$a = ::Object.new; $a'
mutants << '$srandom = nil; $a'
end
it_should_behave_like 'a mutator'
end
context 'class variable' do
let(:source) { '@@a = nil; @@a' }
let(:mutations) do
mutants = []
mutants << '@@a = nil; nil'
mutants << '@@a = nil'
mutants << '@@a'
mutants << '@@a = ::Object.new; @@a'
mutants << '@@srandom = nil; @@a'
end
end
context 'instance variable' do
let(:source) { '@a = nil; @a' }
let(:mutations) do
mutants = []
mutants << '@a = nil; nil'
mutants << '@a = nil'
mutants << '@a'
mutants << '@a = ::Object.new; @a'
mutants << '@srandom = nil; @a'
end
it_should_behave_like 'a mutator'
end
context 'local variable' do
let(:source) { 'a = nil; a' }
let(:mutations) do
mutants = []
mutants << 'a = nil; nil'
mutants << 'a = nil'
mutants << 'a'
mutants << 'a = ::Object.new; a'
mutants << 'srandom = nil; a'
end
it_should_behave_like 'a mutator'
end
context 'constant' do
let(:source) { 'A' }
let(:mutations) do
mutants = []
mutants << 'nil'
end
it_should_behave_like 'a mutator'
end
end

View file

@ -0,0 +1,20 @@
require 'spec_helper'
describe Mutant::Mutator::Node::NamedValue::VariableAssignment, 'mutations' do
before do
Mutant::Random.stub(:hex_string => :random)
end
let(:source) { 'A = true' }
let(:mutations) do
mutations = []
mutations << 'SRANDOM = true'
mutations << 'A = false'
mutations << 'A = nil'
end
it_should_behave_like 'a mutator'
end

View file

@ -1,6 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe Mutant::Mutator::Node::Assignment, 'mutations' do describe Mutant::Mutator::Node::NamedValue::VariableAssignment, 'mutations' do
before do before do
Mutant::Random.stub(:hex_string => :random) Mutant::Random.stub(:hex_string => :random)