From ec9da5da97adff6bfacc4b591411ece01945a31e Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Mon, 22 Jul 2013 09:08:01 -0700 Subject: [PATCH 2/4] Add Mutant::Mutator::Node::Variable * Rename lvar mutator to handle all variable usage --- lib/mutant.rb | 2 +- lib/mutant/mutator/node/generic.rb | 4 ++-- .../mutator/node/{lvar.rb => variable.rb} | 8 +++---- .../mutant/mutator/node/cvar/mutation_spec.rb | 21 +++++++++++++++++++ .../mutant/mutator/node/gvar/mutation_spec.rb | 21 +++++++++++++++++++ .../mutant/mutator/node/ivar/mutation_spec.rb | 21 +++++++++++++++++++ 6 files changed, 70 insertions(+), 7 deletions(-) rename lib/mutant/mutator/node/{lvar.rb => variable.rb} (65%) create mode 100644 spec/unit/mutant/mutator/node/cvar/mutation_spec.rb create mode 100644 spec/unit/mutant/mutator/node/gvar/mutation_spec.rb create mode 100644 spec/unit/mutant/mutator/node/ivar/mutation_spec.rb diff --git a/lib/mutant.rb b/lib/mutant.rb index e8f7dbd0..88dcfd08 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -58,7 +58,7 @@ require 'mutant/mutator/node/assignment' require 'mutant/mutator/node/argument' require 'mutant/mutator/node/arguments' require 'mutant/mutator/node/begin' -require 'mutant/mutator/node/lvar' +require 'mutant/mutator/node/variable' require 'mutant/mutator/node/while' require 'mutant/mutator/node/super' require 'mutant/mutator/node/send' diff --git a/lib/mutant/mutator/node/generic.rb b/lib/mutant/mutator/node/generic.rb index 7bb82aa7..6a17a7cc 100644 --- a/lib/mutant/mutator/node/generic.rb +++ b/lib/mutant/mutator/node/generic.rb @@ -11,10 +11,10 @@ module Mutant # your contribution is that close! handle( :zsuper, :not, :or, :and, :defined, - :next, :break, :match, :gvar, :cvar, :ensure, + :next, :break, :match, :ensure, :dstr, :dsym, :yield, :rescue, :redo, :defined?, :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, :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/lvar.rb b/lib/mutant/mutator/node/variable.rb similarity index 65% rename from lib/mutant/mutator/node/lvar.rb rename to lib/mutant/mutator/node/variable.rb index c67aa824..9b5d7fd7 100644 --- a/lib/mutant/mutator/node/lvar.rb +++ b/lib/mutant/mutator/node/variable.rb @@ -2,10 +2,10 @@ module Mutant class Mutator class Node - # Mutation emitter to handle local variable nodes - class LocalVariable < self + # Mutation emitter to handle variable nodes + class Variable < self - handle(:lvar) + handle(:gvar, :cvar, :ivar, :lvar) private @@ -19,7 +19,7 @@ module Mutant emit_nil end - end # LocalVariable + 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 new file mode 100644 index 00000000..eeb8c385 --- /dev/null +++ b/spec/unit/mutant/mutator/node/cvar/mutation_spec.rb @@ -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 diff --git a/spec/unit/mutant/mutator/node/gvar/mutation_spec.rb b/spec/unit/mutant/mutator/node/gvar/mutation_spec.rb new file mode 100644 index 00000000..6e0375a5 --- /dev/null +++ b/spec/unit/mutant/mutator/node/gvar/mutation_spec.rb @@ -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 diff --git a/spec/unit/mutant/mutator/node/ivar/mutation_spec.rb b/spec/unit/mutant/mutator/node/ivar/mutation_spec.rb new file mode 100644 index 00000000..ed3eb5f7 --- /dev/null +++ b/spec/unit/mutant/mutator/node/ivar/mutation_spec.rb @@ -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 From 0e1365a5658ad4f2c3bcaf3009890efe54264353 Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Mon, 22 Jul 2013 09:20:18 -0700 Subject: [PATCH 3/4] Refactor Mutant::Mutator::Node::Generic#dispatch guard clause --- lib/mutant/mutator/node/generic.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/mutant/mutator/node/generic.rb b/lib/mutant/mutator/node/generic.rb index 6a17a7cc..d022418b 100644 --- a/lib/mutant/mutator/node/generic.rb +++ b/lib/mutant/mutator/node/generic.rb @@ -30,8 +30,7 @@ module Mutant # def dispatch children.each_with_index do |child, index| - next unless child.kind_of?(Parser::AST::Node) - mutate_child(index) + mutate_child(index) if child.kind_of?(Parser::AST::Node) end end From 09fce5359c8fd7409d076b1a5a7220b58f5f7543 Mon Sep 17 00:00:00 2001 From: Dan Kubb Date: Mon, 22 Jul 2013 09:21:50 -0700 Subject: [PATCH 4/4] Update flay threshold --- config/flay.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/flay.yml b/config/flay.yml index 6e326a0c..b15d6991 100644 --- a/config/flay.yml +++ b/config/flay.yml @@ -1,3 +1,3 @@ --- threshold: 16 -total_score: 719 +total_score: 722