Merge pull request #70 from mbj/add-variable-mutator

Add variable mutator
This commit is contained in:
Markus Schirp 2013-07-22 12:41:14 -07:00
commit 55c68a7b25
7 changed files with 72 additions and 10 deletions

View file

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

View file

@ -58,7 +58,7 @@ 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/lvar' require 'mutant/mutator/node/variable'
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'

View file

@ -11,10 +11,10 @@ module Mutant
# your contribution is that close! # your contribution is that close!
handle( handle(
:zsuper, :not, :or, :and, :defined, :zsuper, :not, :or, :and, :defined,
:next, :break, :match, :gvar, :cvar, :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, :const, :blockarg, :block_pass, :op_asgn, :and_asgn,
:regopt, :ivar, :restarg, :casgn, :resbody, :retry, :arg_expr, :regopt, :restarg, :casgn, :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
@ -30,8 +30,7 @@ module Mutant
# #
def dispatch def dispatch
children.each_with_index do |child, index| children.each_with_index do |child, index|
next unless child.kind_of?(Parser::AST::Node) mutate_child(index) if child.kind_of?(Parser::AST::Node)
mutate_child(index)
end end
end end

View file

@ -2,10 +2,10 @@ module Mutant
class Mutator class Mutator
class Node class Node
# Mutation emitter to handle local variable nodes # Mutation emitter to handle variable nodes
class LocalVariable < self class Variable < self
handle(:lvar) handle(:gvar, :cvar, :ivar, :lvar)
private private
@ -19,7 +19,7 @@ module Mutant
emit_nil emit_nil
end end
end # LocalVariable end # Variable
end # Node end # Node
end # Mutator end # Mutator
end # Mutant end # Mutant

View file

@ -0,0 +1,21 @@
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

@ -0,0 +1,21 @@
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

@ -0,0 +1,21 @@
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