From fb7bb942a3509a4dac97f75300950ad6ab18632a Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Wed, 1 Aug 2012 13:53:28 +0200 Subject: [PATCH] Add mutation of simple send without arguments * Lets the block spec work again as 1.8 and 1.9 mode do not behave differend as with literals. --- lib/mutant.rb | 1 - lib/mutant/mutator/call.rb | 32 ++++++++++++++++ lib/mutant/mutator/call/send.rb | 38 ------------------- .../mutation_enumeration_method_behavior.rb | 4 ++ .../mutator/block/class_methods/each_spec.rb | 20 ++++++++++ .../mutator/call/class_methods/each_spec.rb | 10 ++--- spec/unit/mutant/mutator/each_spec.rb | 19 ---------- .../mutator/self/class_methods/each_spec.rb | 6 +-- 8 files changed, 60 insertions(+), 70 deletions(-) delete mode 100644 lib/mutant/mutator/call/send.rb create mode 100644 spec/unit/mutant/mutator/block/class_methods/each_spec.rb diff --git a/lib/mutant.rb b/lib/mutant.rb index 4eda272f..59e95886 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -40,7 +40,6 @@ require 'mutant/mutator/literal/regex' require 'mutant/mutator/block' require 'mutant/mutator/self' require 'mutant/mutator/call' -require 'mutant/mutator/call/send' require 'mutant/mutator/call/send_with_arguments' require 'mutant/loader' require 'mutant/context' diff --git a/lib/mutant/mutator/call.rb b/lib/mutant/mutator/call.rb index 606fbc70..ac056bd3 100644 --- a/lib/mutant/mutator/call.rb +++ b/lib/mutant/mutator/call.rb @@ -39,6 +39,38 @@ module Mutant def self? receiver.kind_of?(Rubinius::AST::Self) end + + class Send < Call + + handle(Rubinius::AST::Send) + + private + + # Emit mutations + # + # @return [undefined] + # + # @api private + # + def dispatch + emit_explicit_receiver + end + + # Emit a private vcall mutation + # + # Transforms a call on self with implict receiver into one with + # explcit receiver. + # + # foo(1) => self.foo(1) + # + # @return [undefined] + # + # @api private + # + def emit_explicit_receiver + emit_self(receiver,name,false,false) + end + end end end end diff --git a/lib/mutant/mutator/call/send.rb b/lib/mutant/mutator/call/send.rb deleted file mode 100644 index 1e509ae5..00000000 --- a/lib/mutant/mutator/call/send.rb +++ /dev/null @@ -1,38 +0,0 @@ -module Mutant - class Mutator - class Call < Mutator - # Mutator for Rubinius::AST::Send - class Send < Call - - handle(Rubinius::AST::Send) - - private - - # Emit mutations - # - # @return [undefined] - # - # @api private - # - def dispatch - emit_explicit_receiver - end - - # Emit a private vcall mutation - # - # Transforms a call on self with implict receiver into one with - # explcit receiver. - # - # foo(1) => self.foo(1) - # - # @return [undefined] - # - # @api private - # - def emit_explicit_receiver - emit_self(receiver,name,false,true) - end - end - end - end -end diff --git a/spec/shared/mutation_enumeration_method_behavior.rb b/spec/shared/mutation_enumeration_method_behavior.rb index e8bf78d0..8c27060b 100644 --- a/spec/shared/mutation_enumeration_method_behavior.rb +++ b/spec/shared/mutation_enumeration_method_behavior.rb @@ -34,4 +34,8 @@ shared_examples_for 'a mutation enumerator method' do end end +shared_examples_for 'a noop mutation enumerator method' do + let(:mutations) { [] } + it_should_behave_like 'a mutation enumerator method' +end diff --git a/spec/unit/mutant/mutator/block/class_methods/each_spec.rb b/spec/unit/mutant/mutator/block/class_methods/each_spec.rb new file mode 100644 index 00000000..00c4fb7f --- /dev/null +++ b/spec/unit/mutant/mutator/block/class_methods/each_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe Mutant::Mutator::Block, '.each' do + # Two send operations + let(:source) { "foo\nbar" } + + let(:mutations) do + mutations = [] + + # Mutation of each statement in block + mutations << "foo\nself.bar" + mutations << "self.foo\nbar" + + ## Remove statement in block + mutations << [:block, 'foo'.to_sexp] + mutations << [:block, 'bar'.to_sexp] + end + + it_should_behave_like 'a mutation enumerator method' +end diff --git a/spec/unit/mutant/mutator/call/class_methods/each_spec.rb b/spec/unit/mutant/mutator/call/class_methods/each_spec.rb index f9b5a7dd..cb90e9fd 100644 --- a/spec/unit/mutant/mutator/call/class_methods/each_spec.rb +++ b/spec/unit/mutant/mutator/call/class_methods/each_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Mutant::Mutator::Call, '.each' do - pending 'send' do + context 'send without arguments' do context 'to self' do context 'implict' do @@ -9,6 +9,7 @@ describe Mutant::Mutator::Call, '.each' do let(:mutations) do mutations = [] + mutations << 'self.foo' # without explict receiver (not send privately) end it_should_behave_like 'a mutation enumerator method' @@ -17,12 +18,7 @@ describe Mutant::Mutator::Call, '.each' do context 'explict' do let(:source) { 'self.foo' } - let(:mutations) do - mutations = [] - mutations << 'foo' # without explict receiver (send privately) - end - - it_should_behave_like 'a mutation enumerator method' + it_should_behave_like 'a noop mutation enumerator method' end end end diff --git a/spec/unit/mutant/mutator/each_spec.rb b/spec/unit/mutant/mutator/each_spec.rb index d7502835..08c640cb 100644 --- a/spec/unit/mutant/mutator/each_spec.rb +++ b/spec/unit/mutant/mutator/each_spec.rb @@ -21,23 +21,4 @@ describe Mutant::Mutator, '.each' do it_should_behave_like 'a mutation enumerator method' end - - pending 'block literal' do - # Two send operations - let(:source) { "self.foo\nself.bar" } - - let(:mutations) do - mutations = [] - - # Mutation of each statement in block - mutations << "foo\nself.bar" - mutations << "self.foo\nbar" - - ## Remove statement in block - mutations << [:block, 'self.foo'.to_sexp] - mutations << [:block, 'self.bar'.to_sexp] - end - - it_should_behave_like 'a mutation enumerator method' - end end diff --git a/spec/unit/mutant/mutator/self/class_methods/each_spec.rb b/spec/unit/mutant/mutator/self/class_methods/each_spec.rb index 5f8db2e1..049eb841 100644 --- a/spec/unit/mutant/mutator/self/class_methods/each_spec.rb +++ b/spec/unit/mutant/mutator/self/class_methods/each_spec.rb @@ -3,9 +3,5 @@ require 'spec_helper' describe Mutant::Mutator::Self, '.each' do let(:source) { 'self' } - let(:mutations) do - mutations = [] - end - - it_should_behave_like 'a mutation enumerator method' + it_should_behave_like 'a noop mutation enumerator method' end