Merge pull request #71 from mbj/const-mutator
Const access and assignment mutators
This commit is contained in:
commit
795be2c7e5
14 changed files with 179 additions and 123 deletions
|
@ -1,3 +1,3 @@
|
|||
---
|
||||
threshold: 16
|
||||
total_score: 722
|
||||
total_score: 730
|
||||
|
|
|
@ -54,17 +54,17 @@ require 'mutant/mutator/node/literal/array'
|
|||
require 'mutant/mutator/node/literal/hash'
|
||||
require 'mutant/mutator/node/literal/regex'
|
||||
require 'mutant/mutator/node/literal/nil'
|
||||
require 'mutant/mutator/node/assignment'
|
||||
require 'mutant/mutator/node/argument'
|
||||
require 'mutant/mutator/node/arguments'
|
||||
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/super'
|
||||
require 'mutant/mutator/node/send'
|
||||
require 'mutant/mutator/node/send/binary'
|
||||
require 'mutant/mutator/node/when'
|
||||
require 'mutant/mutator/node/assignment'
|
||||
require 'mutant/mutator/node/define'
|
||||
require 'mutant/mutator/node/mlhs'
|
||||
require 'mutant/mutator/node/masgn'
|
||||
|
|
|
@ -13,8 +13,8 @@ module Mutant
|
|||
:zsuper, :not, :or, :and, :defined,
|
||||
:next, :break, :match, :ensure,
|
||||
:dstr, :dsym, :yield, :rescue, :redo, :defined?,
|
||||
:const, :blockarg, :block_pass, :op_asgn, :and_asgn,
|
||||
:regopt, :restarg, :casgn, :resbody, :retry, :arg_expr,
|
||||
:blockarg, :block_pass, :op_asgn, :and_asgn,
|
||||
:regopt, :restarg, :resbody, :retry, :arg_expr,
|
||||
:kwrestarg, :kwoptarg, :kwarg, :undef, :module, :cbase, :empty,
|
||||
:alias, :for, :xstr, :back_ref, :nth_ref, :class,
|
||||
:sclass, :match_with_lvasgn, :match_current_line, :or_asgn, :kwbegin
|
||||
|
|
27
lib/mutant/mutator/node/named_value/access.rb
Normal file
27
lib/mutant/mutator/node/named_value/access.rb
Normal 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
|
42
lib/mutant/mutator/node/named_value/constant_assignment.rb
Normal file
42
lib/mutant/mutator/node/named_value/constant_assignment.rb
Normal 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
|
|
@ -1,11 +1,10 @@
|
|||
module Mutant
|
||||
class Mutator
|
||||
class Node
|
||||
# Mutator base class for assignments
|
||||
class Assignment < self
|
||||
module NamedValue
|
||||
|
||||
# Mutator for variable assignment
|
||||
class Variable < self
|
||||
# Mutation emitter to handle variable assignment nodes
|
||||
class VariableAssignment < Node
|
||||
|
||||
children :name, :value
|
||||
|
||||
|
@ -40,12 +39,12 @@ module Mutant
|
|||
def mutate_name
|
||||
prefix = MAP.fetch(node.type)
|
||||
Mutator::Util::Symbol.each(name, self) do |name|
|
||||
emit_name("#{prefix}#{name}")
|
||||
emit_name(prefix + name.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
end # Variable
|
||||
end # Assignment
|
||||
end # VariableAssignment
|
||||
end # NamedValue
|
||||
end # Node
|
||||
end # Mutator
|
||||
end # Mutant
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Mutant::Mutator::Node::Assignment, 'mutations' do
|
||||
describe Mutant::Mutator::Node::NamedValue::VariableAssignment, 'mutations' do
|
||||
|
||||
before do
|
||||
Mutant::Random.stub(:hex_string => :random)
|
Loading…
Add table
Reference in a new issue