diff --git a/config/flay.yml b/config/flay.yml index b15d6991..94a794f3 100644 --- a/config/flay.yml +++ b/config/flay.yml @@ -1,3 +1,3 @@ --- threshold: 16 -total_score: 722 +total_score: 730 diff --git a/lib/mutant.rb b/lib/mutant.rb index 88dcfd08..6be0ccf8 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -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' diff --git a/lib/mutant/mutator/node/generic.rb b/lib/mutant/mutator/node/generic.rb index d022418b..0bab9dd1 100644 --- a/lib/mutant/mutator/node/generic.rb +++ b/lib/mutant/mutator/node/generic.rb @@ -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 diff --git a/lib/mutant/mutator/node/named_value/access.rb b/lib/mutant/mutator/node/named_value/access.rb new file mode 100644 index 00000000..6e7f505d --- /dev/null +++ b/lib/mutant/mutator/node/named_value/access.rb @@ -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 diff --git a/lib/mutant/mutator/node/named_value/constant_assignment.rb b/lib/mutant/mutator/node/named_value/constant_assignment.rb new file mode 100644 index 00000000..00a63ea7 --- /dev/null +++ b/lib/mutant/mutator/node/named_value/constant_assignment.rb @@ -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 diff --git a/lib/mutant/mutator/node/assignment.rb b/lib/mutant/mutator/node/named_value/variable_assignment.rb similarity index 78% rename from lib/mutant/mutator/node/assignment.rb rename to lib/mutant/mutator/node/named_value/variable_assignment.rb index 520a8f73..60f3dd46 100644 --- a/lib/mutant/mutator/node/assignment.rb +++ b/lib/mutant/mutator/node/named_value/variable_assignment.rb @@ -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 diff --git a/lib/mutant/mutator/node/variable.rb b/lib/mutant/mutator/node/variable.rb deleted file mode 100644 index 9b5d7fd7..00000000 --- a/lib/mutant/mutator/node/variable.rb +++ /dev/null @@ -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 diff --git a/spec/unit/mutant/mutator/node/cvar/mutation_spec.rb b/spec/unit/mutant/mutator/node/cvar/mutation_spec.rb deleted file mode 100644 index eeb8c385..00000000 --- a/spec/unit/mutant/mutator/node/cvar/mutation_spec.rb +++ /dev/null @@ -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 diff --git a/spec/unit/mutant/mutator/node/gvar/mutation_spec.rb b/spec/unit/mutant/mutator/node/gvar/mutation_spec.rb deleted file mode 100644 index 6e0375a5..00000000 --- a/spec/unit/mutant/mutator/node/gvar/mutation_spec.rb +++ /dev/null @@ -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 diff --git a/spec/unit/mutant/mutator/node/ivar/mutation_spec.rb b/spec/unit/mutant/mutator/node/ivar/mutation_spec.rb deleted file mode 100644 index ed3eb5f7..00000000 --- a/spec/unit/mutant/mutator/node/ivar/mutation_spec.rb +++ /dev/null @@ -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 diff --git a/spec/unit/mutant/mutator/node/lvar/mutation_spec.rb b/spec/unit/mutant/mutator/node/lvar/mutation_spec.rb deleted file mode 100644 index e63edc8b..00000000 --- a/spec/unit/mutant/mutator/node/lvar/mutation_spec.rb +++ /dev/null @@ -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 diff --git a/spec/unit/mutant/mutator/node/named_value/access/mutation_spec.rb b/spec/unit/mutant/mutator/node/named_value/access/mutation_spec.rb new file mode 100644 index 00000000..1ab64e1d --- /dev/null +++ b/spec/unit/mutant/mutator/node/named_value/access/mutation_spec.rb @@ -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 diff --git a/spec/unit/mutant/mutator/node/named_value/constant_assignment/mutation_spec.rb b/spec/unit/mutant/mutator/node/named_value/constant_assignment/mutation_spec.rb new file mode 100644 index 00000000..ea693398 --- /dev/null +++ b/spec/unit/mutant/mutator/node/named_value/constant_assignment/mutation_spec.rb @@ -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 diff --git a/spec/unit/mutant/mutator/node/assignment/mutation_spec.rb b/spec/unit/mutant/mutator/node/named_value/variable_assignment/mutation_spec.rb similarity index 93% rename from spec/unit/mutant/mutator/node/assignment/mutation_spec.rb rename to spec/unit/mutant/mutator/node/named_value/variable_assignment/mutation_spec.rb index d20220f3..59449390 100644 --- a/spec/unit/mutant/mutator/node/assignment/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/named_value/variable_assignment/mutation_spec.rb @@ -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)