From 08eb381c37e3d22daaecc7765e58181dd42f9721 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Tue, 1 Jan 2013 23:28:21 +0100 Subject: [PATCH] Add super mutations --- Changelog.md | 7 ++++ lib/mutant.rb | 1 + lib/mutant/mutator/node/super.rb | 39 ++++++++++++++++++ .../mutator/node/super/mutation_spec.rb | 40 +++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 lib/mutant/mutator/node/super.rb create mode 100644 spec/unit/mutant/mutator/node/super/mutation_spec.rb diff --git a/Changelog.md b/Changelog.md index 6e647014..e107e68a 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,10 @@ +# v0.2.9 2013-01-01 + +* [feature] Mutate instance and global variable assignments +* [feature] Mutate super calls + +[Compare v0.2.8..v0.2.9](https://github.com/mbj/mutant/compare/v0.2.8...v0.2.9) + # v0.2.8 2012-12-29 * [feature] Do not mutate argument or local variable names beginning with an underscore diff --git a/lib/mutant.rb b/lib/mutant.rb index 8e4b6eb6..aee9bde2 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -83,6 +83,7 @@ require 'mutant/mutator/node/literal/regex' require 'mutant/mutator/node/literal/nil' require 'mutant/mutator/node/block' require 'mutant/mutator/node/while' +require 'mutant/mutator/node/super' require 'mutant/mutator/node/send' require 'mutant/mutator/node/assignment' require 'mutant/mutator/node/define' diff --git a/lib/mutant/mutator/node/super.rb b/lib/mutant/mutator/node/super.rb new file mode 100644 index 00000000..529692bc --- /dev/null +++ b/lib/mutant/mutator/node/super.rb @@ -0,0 +1,39 @@ +module Mutant + class Mutator + class Node + + class ZSuper < self + + handle(Rubinius::AST::ZSuper) + + # Emit mutations + # + # @return [undefined] + # + # @api private + # + def dispatch + emit_node(Rubinius::AST::Super, new(Rubinius::AST::ActualArguments)) + end + + end + + class Super < self + handle(Rubinius::AST::Super) + + private + + # Emit mutations + # + # @return [undefined] + # + # @api private + # + def dispatch + emit_node(Rubinius::AST::ZSuper) + emit_attribute_mutations(:arguments) + end + end + end + end +end diff --git a/spec/unit/mutant/mutator/node/super/mutation_spec.rb b/spec/unit/mutant/mutator/node/super/mutation_spec.rb new file mode 100644 index 00000000..5dfe558f --- /dev/null +++ b/spec/unit/mutant/mutator/node/super/mutation_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe Mutant::Mutator, 'super' do + + context 'super no arguments' do + let(:source) { 'super' } + + let(:mutations) do + mutations = [] + mutations << 'super()' + end + + it_should_behave_like 'a mutator' + end + + context 'super with explicit empty arguments' do + let(:source) { 'super()' } + + let(:mutations) do + mutations = [] + mutations << 'super' + end + + it_should_behave_like 'a mutator' + end + + context 'super with arguments' do + let(:source) { 'super(foo, bar)' } + + let(:mutations) do + mutations = [] + mutations << 'super' + mutations << 'super()' + mutations << 'super(foo)' + mutations << 'super(bar)' + end + + it_should_behave_like 'a mutator' + end +end