Add expression => self mutation

Also reorganizes parts of meta to align filenames to node name better.

Closes #191
This commit is contained in:
Markus Schirp 2014-06-05 16:37:31 +00:00
parent 89e8eb5679
commit 017ccc1044
84 changed files with 517 additions and 440 deletions

View file

@ -159,6 +159,8 @@ require 'mutant/mutator/node/named_value/variable_assignment'
require 'mutant/mutator/node/loop_control'
require 'mutant/mutator/node/noop'
require 'mutant/mutator/node/or_asgn'
require 'mutant/mutator/node/and_asgn'
require 'mutant/mutator/node/defined'
require 'mutant/mutator/node/op_asgn'
require 'mutant/mutator/node/conditional_loop'
require 'mutant/mutator/node/yield'

View file

@ -74,6 +74,17 @@ module Mutant
self
end
# Add singleotn mutations
#
# @return [undefined]
#
# @api private
#
def singleton_mutations
mutation 'nil'
mutation 'self'
end
# Helper method to coerce input to node
#
# @param [String,Parser::AST::Node] input

View file

@ -23,8 +23,8 @@ module Mutant
children.at(index)
end
define_method("emit_#{name}_mutations") do
mutate_child(index)
define_method("emit_#{name}_mutations") do |&block|
mutate_child(index, &block)
end
define_method("emit_#{name}") do |node|
@ -118,10 +118,13 @@ module Mutant
#
# @api private
#
def mutate_child(index, mutator = Mutator)
def mutate_child(index, mutator = Mutator, &block)
block ||= lambda { |_node| true }
child = children.at(index)
mutator.each(child, self) do |mutation|
emit_child_update(index, mutation)
if block.call(mutation)
emit_child_update(index, mutation)
end
end
end
@ -166,7 +169,28 @@ module Mutant
emit(new_self(*children))
end
# Emit a new AST node with NilLiteral class
# Emit singleton literals
#
# @return [undefined]
#
# @api private
#
def emit_singletons
emit_nil
emit_self
end
# Emit a literal self
#
# @return [undefined]
#
# @api private
#
def emit_self
emit(N_SELF)
end
# Emit a literal nil
#
# @return [undefined]
#

View file

@ -0,0 +1,34 @@
# encoding: utf-8
module Mutant
class Mutator
class Node
# OpAsgn mutator
class AndAsgn < self
handle(:and_asgn)
children :left, :right
private
# Emit mutations
#
# @return [undefined]
#
# @api private
#
def dispatch
emit_singletons
emit_left_mutations do |mutation|
!mutation.type.equal?(:self)
end
emit_right_mutations
end
end # OrAsgn
end # Node
end # Mutator
end # Mutant

View file

@ -24,7 +24,7 @@ module Mutant
# @api private
#
def dispatch
emit_nil
emit_singletons
emit(left)
emit(right)
mutate_operator

View file

@ -19,6 +19,7 @@ module Mutant
# @api private
#
def dispatch
emit_singletons
emit(send)
emit_arguments_mutations
if body
@ -26,7 +27,6 @@ module Mutant
end
emit_body(nil)
emit_body(RAISE)
emit_nil
end
end # Block

View file

@ -20,10 +20,10 @@ module Mutant
# @api private
#
def dispatch
emit_singletons
emit_condition_mutations if condition
emit_when_mutations
emit_else_mutations
emit_nil
end
# Emit when mutations

View file

@ -20,11 +20,11 @@ module Mutant
# @api private
#
def dispatch
emit_singletons
emit_condition_mutations
emit_body_mutations if body
emit_body(nil)
emit_body(RAISE)
emit_nil
end
end # While

View file

@ -18,7 +18,7 @@ module Mutant
# @api private
#
def dispatch
emit_nil unless parent_type == :const
emit_singletons unless parent_type == :const
emit_type(nil, *children.drop(1))
children.each_with_index do |child, index|
mutate_child(index) if child.kind_of?(Parser::AST::Node)

View file

@ -0,0 +1,30 @@
# encoding: utf-8
module Mutant
class Mutator
class Node
# Namespace for define mutations
class Defined < self
handle(:defined?)
children :expression
private
# Emit mutations
#
# @return [undefined]
#
# @api private
#
def dispatch
emit_expression_mutations do |node|
!node.type.equal?(:self)
end
end
end # Defined
end # Node
end # Mutator
end # Mutant

View file

@ -19,7 +19,7 @@ module Mutant
#
def dispatch
super
emit_nil
emit_singletons
end
end # Dstr

View file

@ -19,7 +19,7 @@ module Mutant
#
def dispatch
super
emit_nil
emit_singletons
end
end # Dsym

View file

@ -10,7 +10,7 @@ module Mutant
# These nodes still need a dedicated mutator,
# your contribution is that close!
handle(
:ensure, :redo, :defined?, :regopt, :retry, :arg_expr,
:ensure, :redo, :regopt, :retry, :arg_expr,
:kwrestarg, :kwoptarg, :kwarg, :undef, :module, :empty,
:alias, :for, :xstr, :back_ref, :class,
:sclass, :match_with_lvasgn, :while_post,

View file

@ -19,10 +19,10 @@ module Mutant
# @api private
#
def dispatch
emit_singletons
mutate_condition
mutate_if_branch
mutate_else_branch
emit_nil
end
# Emit conditon mutations
@ -32,7 +32,9 @@ module Mutant
# @api private
#
def mutate_condition
emit_condition_mutations
emit_condition_mutations do |condition|
!condition.type.eql?(:self)
end
emit_type(n_not(condition), if_branch, else_branch) unless condition.type == :match_current_line
emit_type(N_TRUE, if_branch, else_branch)
emit_type(N_FALSE, if_branch, else_branch)

View file

@ -19,7 +19,7 @@ module Mutant
#
def dispatch
super
emit_nil
emit_singletons
end
end # Kwbegin

View file

@ -18,7 +18,7 @@ module Mutant
# @api private
#
def dispatch
emit_nil
emit_singletons
emit_type
mutate_body
if children.one?

View file

@ -18,7 +18,7 @@ module Mutant
# @api private
#
def dispatch
emit_nil
emit_singletons
emit_values(values)
end

View file

@ -18,7 +18,7 @@ module Mutant
# @api private
#
def dispatch
emit_nil
emit_singletons
emit_values(values)
emit_special_cases
end

View file

@ -18,7 +18,7 @@ module Mutant
# @api private
#
def dispatch
emit_nil
emit_singletons
emit_type
mutate_body
end

View file

@ -26,7 +26,7 @@ module Mutant
# @api private
#
def dispatch
emit_nil
emit_singletons
emit_inverse
emit_lower_bound_mutations
emit_upper_bound_mutations

View file

@ -31,7 +31,7 @@ module Mutant
# @api private
#
def dispatch
emit_nil unless parent_type == :match_current_line
emit_singletons unless parent_type == :match_current_line
children.each_with_index do |child, index|
mutate_child(index) unless child.type == :str
end

View file

@ -18,7 +18,7 @@ module Mutant
# @api private
#
def dispatch
emit_nil
emit_singletons
end
end # String

View file

@ -22,7 +22,7 @@ module Mutant
# @api private
#
def dispatch
emit_nil
emit_singletons
Mutator::Util::Symbol.each(value, self) do |value|
emit_type(value)
end

View file

@ -24,9 +24,9 @@ module Mutant
#
def dispatch
super
emit_singletons
children.each_index(&method(:delete_child))
emit(s(INVERSE.fetch(node.type), *children))
emit_nil
end
end # Next

View file

@ -20,7 +20,7 @@ module Mutant
# @api private
#
def dispatch
emit_nil
emit_singletons
end
end # MultipleAssignment

View file

@ -17,7 +17,7 @@ module Mutant
# @api private
#
def dispatch
emit_nil
emit_singletons
emit_regexp_mutations
end

View file

@ -19,7 +19,7 @@ module Mutant
# @api private
#
def dispatch
emit_nil
emit_singletons
end
end # Access

View file

@ -32,9 +32,9 @@ module Mutant
# @api private
#
def dispatch
emit_singletons
mutate_name
emit_value_mutations if value # mlhs!
emit_nil
end
# Emit name mutations

View file

@ -5,9 +5,11 @@ module Mutant
class Node
# OpAsgn mutator
class OpAsgn < Generic
class OpAsgn < self
handle(:op_asgn, :and_asgn)
handle(:op_asgn)
children :left, :operation, :right
private
@ -18,8 +20,11 @@ module Mutant
# @api private
#
def dispatch
super
emit_nil
emit_singletons
emit_left_mutations do |mutation|
!mutation.type.equal?(:self)
end
emit_right_mutations
end
end # OpAsgn

View file

@ -20,8 +20,12 @@ module Mutant
# @api private
#
def dispatch
emit_nil
emit_left_mutations unless left.type.equal?(:ivasgn)
emit_singletons
unless left.type.equal?(:ivasgn)
emit_left_mutations do |mutation|
!mutation.type.equal?(:self)
end
end
emit_right_mutations
end

View file

@ -19,11 +19,11 @@ module Mutant
# @api private
#
def dispatch
emit_singletons
if value
emit(value)
emit_value_mutations
end
emit_nil
end
end # Return

View file

@ -34,7 +34,7 @@ module Mutant
# @api private
#
def dispatch
emit_nil
emit_singletons
case selector
when INDEX_REFERENCE
run(Index::Reference)

View file

@ -19,7 +19,7 @@ module Mutant
# @api private
#
def dispatch
emit_nil
emit_singletons
emit_expression_mutations
emit(expression)
end

View file

@ -21,13 +21,13 @@ module Mutant
# @api private
#
def dispatch
emit_singletons
emit(Z_SUPER)
emit(EMPTY_SUPER)
children.each_index do |index|
mutate_child(index)
delete_child(index)
end
emit_nil
end
end # Super

View file

@ -19,8 +19,8 @@ module Mutant
#
def dispatch
super
emit_singletons
children.each_index(&method(:delete_child))
emit_nil
end
end # Yield

View file

@ -18,7 +18,7 @@ module Mutant
# @api private
#
def dispatch
emit_nil
emit_singletons
end
end # ZSuper

View file

@ -24,12 +24,13 @@ module Mutant
NEGATIVE_INFINITY =
s(:send, s(:float, -1.0), :/, s(:float, 0.0))
RAISE = s(:send, nil, :raise)
RAISE = s(:send, nil, :raise)
N_TRUE = s(:true)
N_FALSE = s(:false)
N_NIL = s(:nil)
N_EMPTY = s(:empty)
N_TRUE = s(:true)
N_FALSE = s(:false)
N_NIL = s(:nil)
N_EMPTY = s(:empty)
N_SELF = s(:self)
# Build a negated boolean node
#

View file

@ -3,7 +3,7 @@
Mutant::Meta::Example.add do
source 'true and false'
mutation 'nil'
singleton_mutations
mutation 'true'
mutation 'false'
mutation 'true or false'

View file

@ -3,10 +3,12 @@
Mutant::Meta::Example.add do
source 'a &&= 1'
singleton_mutations
mutation 'a__mutant__ &&= 1'
mutation 'a &&= nil'
mutation 'a &&= 0'
mutation 'a &&= -1'
mutation 'a &&= 2'
mutation 'nil'
mutation 'a &&= self'
end

View file

@ -3,7 +3,7 @@
Mutant::Meta::Example.add do
source '[true]'
mutation 'nil'
singleton_mutations
mutation 'true'
mutation '[false]'
mutation '[nil]'
@ -13,7 +13,7 @@ end
Mutant::Meta::Example.add do
source '[true, false]'
mutation 'nil'
singleton_mutations
# Mutation of each element in array
mutation '[nil, false]'

View file

@ -3,19 +3,22 @@
Mutant::Meta::Example.add do
source 'foo() { a; b }'
singleton_mutations
mutation 'foo { a }'
mutation 'foo { b }'
mutation 'foo {}'
mutation 'foo { raise }'
mutation 'foo { a; nil }'
mutation 'foo { a; self }'
mutation 'foo { nil; b }'
mutation 'foo { self; b }'
mutation 'foo'
mutation 'nil'
end
Mutant::Meta::Example.add do
source 'foo { |a, b| }'
singleton_mutations
mutation 'foo'
mutation 'foo { |a, b| raise }'
mutation 'foo { |a, b__mutant__| }'
@ -23,13 +26,12 @@ Mutant::Meta::Example.add do
mutation 'foo { |a| }'
mutation 'foo { |b| }'
mutation 'foo { || }'
mutation 'nil'
end
Mutant::Meta::Example.add do
source 'foo { |(a, b), c| }'
mutation 'nil'
singleton_mutations
mutation 'foo { || }'
mutation 'foo { |a, b, c| }'
mutation 'foo { |(a, b), c| raise }'
@ -46,10 +48,10 @@ end
Mutant::Meta::Example.add do
source 'foo { |(a)| }'
singleton_mutations
mutation 'foo { || }'
mutation 'foo { |a| }'
mutation 'foo { |(a)| raise }'
mutation 'foo { |(a__mutant__)| }'
mutation 'foo'
mutation 'nil'
end

View file

@ -3,6 +3,6 @@
Mutant::Meta::Example.add do
source 'foo(&bar)'
singleton_mutations
mutation 'foo'
mutation 'nil'
end

View file

@ -3,8 +3,8 @@
Mutant::Meta::Example.add do
source 'foo { |&bar| }'
singleton_mutations
mutation 'foo { |&bar| raise }'
mutation 'foo {}'
mutation 'foo'
mutation 'nil'
end

View file

@ -3,9 +3,9 @@
Mutant::Meta::Example.add do
source 'break true'
singleton_mutations
mutation 'break false'
mutation 'break nil'
mutation 'break'
mutation 'nil'
mutation 'next true'
end

View file

@ -8,7 +8,7 @@ Mutant::Meta::Example.add do
end
RUBY
mutation 'nil'
singleton_mutations
mutation <<-RUBY
case
@ -33,271 +33,192 @@ end
Mutant::Meta::Example.add do
source <<-RUBY
case :condition
when :foo
when :bar, :baz
:barbaz
case condition
when A
when B, C
C
else
:else
D
end
RUBY
# Presence of branches
mutation <<-RUBY
case :condition
when :bar, :baz
:barbaz
else
:else
end
RUBY
mutation <<-RUBY
case :condition
when :foo
else
:else
end
RUBY
mutation <<-RUBY
case :condition
when :foo
when :bar, :baz
:barbaz
end
RUBY
singleton_mutations
# Mutations of condition
mutation <<-RUBY
case nil
when :foo
when :bar, :baz
:barbaz
when A
when B, C
C
else
:else
end
RUBY
mutation <<-RUBY
case :condition__mutant__
when :foo
when :bar, :baz
:barbaz
else
:else
D
end
RUBY
# Mutations of branch bodies
mutation <<-RUBY
case :condition
when :foo
case self
when A
when B, C
C
else
D
end
RUBY
mutation <<-RUBY
case condition
when A
raise
when :bar, :baz
:barbaz
when B, C
C
else
:else
end
RUBY
mutation <<-RUBY
case :condition
when :foo
when :bar, :baz
:barbaz__mutant__
else
:else
end
RUBY
mutation <<-RUBY
case :condition
when :foo
when :bar, :baz
nil
else
:else
end
RUBY
mutation <<-RUBY
case :condition
when :foo
when :bar, :baz
:barbaz
else
:else__mutant__
end
RUBY
mutation <<-RUBY
case :condition
when :foo
when :bar, :baz
:barbaz
else
nil
D
end
RUBY
# Mutations of when conditions
mutation <<-RUBY
case :condition
when :foo__mutant__
when :bar, :baz
:barbaz
else
:else
end
RUBY
mutation <<-RUBY
case :condition
case condition
when nil
when :bar, :baz
:barbaz
when B, C
C
else
:else
end
RUBY
mutation <<-RUBY
case :condition
when :foo
when :bar__mutant__, :baz
:barbaz
else
:else
end
RUBY
mutation <<-RUBY
case :condition
when :foo
when nil, :baz
:barbaz
else
:else
end
RUBY
mutation <<-RUBY
case :condition
when :foo
when :bar, nil
:barbaz
else
:else
end
RUBY
mutation <<-RUBY
case :condition
when :foo
when :bar, :baz__mutant__
:barbaz
else
:else
end
RUBY
mutation <<-RUBY
case :condition
when :foo
when :baz
:barbaz
else
:else
end
RUBY
mutation <<-RUBY
case :condition
when :foo
when :bar
:barbaz
else
:else
D
end
RUBY
mutation 'nil'
mutation <<-RUBY
case condition
when self
when B, C
C
else
D
end
RUBY
mutation <<-RUBY
case condition
when B, C
C
else
D
end
RUBY
mutation <<-RUBY
case condition
when A
when B, C
nil
else
D
end
RUBY
mutation <<-RUBY
case condition
when A
when B, C
self
else
D
end
RUBY
mutation <<-RUBY
case condition
when A
when C
C
else
D
end
RUBY
mutation <<-RUBY
case condition
when A
when nil, C
C
else
D
end
RUBY
mutation <<-RUBY
case condition
when A
when self, C
C
else
D
end
RUBY
mutation <<-RUBY
case condition
when A
when B
C
else
D
end
RUBY
mutation <<-RUBY
case condition
when A
when B, nil
C
else
D
end
RUBY
mutation <<-RUBY
case condition
when A
when B, self
C
else
D
end
RUBY
mutation <<-RUBY
case condition
when A
else
D
end
RUBY
mutation <<-RUBY
case condition
when A
when B, C
C
else
nil
end
RUBY
mutation <<-RUBY
case condition
when A
when B, C
C
else
self
end
RUBY
mutation <<-RUBY
case condition
when A
when B, C
C
end
RUBY
end
Mutant::Meta::Example.add do
source <<-RUBY
case :condition
when :foo
:foo
else
:else
end
RUBY
# Presence of branches
mutation <<-RUBY
case :condition
when :foo
:foo
end
RUBY
# Mutations of condition
mutation <<-RUBY
case nil
when :foo
:foo
else
:else
end
RUBY
mutation <<-RUBY
case :condition__mutant__
when :foo
:foo
else
:else
end
RUBY
# Mutations of branch bodies
mutation <<-RUBY
case :condition
when :foo
nil
else
:else
end
RUBY
mutation <<-RUBY
case :condition
when :foo
:foo__mutant__
else
:else
end
RUBY
mutation <<-RUBY
case :condition
when :foo
:foo
else
:else__mutant__
end
RUBY
mutation <<-RUBY
case :condition
when :foo
:foo
else
nil
end
RUBY
# Mutations of when conditions
mutation <<-RUBY
case :condition
when :foo__mutant__
:foo
else
:else
end
RUBY
mutation <<-RUBY
case :condition
when nil
:foo
else
:else
end
RUBY
mutation 'nil'
end

View file

@ -3,6 +3,6 @@
Mutant::Meta::Example.add do
source '::A'
mutation 'nil'
singleton_mutations
mutation 'A'
end

View file

@ -3,7 +3,7 @@
Mutant::Meta::Example.add do
source 'A::B::C'
mutation 'nil'
singleton_mutations
mutation 'B::C'
mutation 'C'
end

View file

@ -3,5 +3,5 @@
Mutant::Meta::Example.add do
source '@@a'
mutation 'nil'
singleton_mutations
end

View file

@ -3,8 +3,8 @@
Mutant::Meta::Example.add do
source '@@a = true'
singleton_mutations
mutation '@@a__mutant__ = true'
mutation '@@a = false'
mutation '@@a = nil'
mutation 'nil'
end

View file

@ -7,10 +7,11 @@ Mutant::Meta::Example.add do
end
Mutant::Meta::Example.add do
source "def foo\nfoo\nrescue\nend"
source 'def foo; foo; rescue; end'
mutation 'def foo; raise; end'
mutation 'def foo; nil; rescue; end'
mutation 'def foo; self; rescue; end'
mutation 'def foo; end'
end

View file

@ -3,8 +3,11 @@
Mutant::Meta::Example.add do
source '"foo#{bar}baz"'
mutation 'nil'
singleton_mutations
mutation '"#{nil}#{bar}baz"'
mutation '"#{self}#{bar}baz"'
mutation '"foo#{bar}#{nil}"'
mutation '"foo#{bar}#{self}"'
mutation '"foo#{nil}baz"'
mutation '"foo#{self}baz"'
end

View file

@ -1,11 +1,13 @@
# encoding: utf-8
Mutant::Meta::Example.add do
source ':"foo#{bar}baz"'
singleton_mutations
mutation ':"#{nil}#{bar}baz"'
mutation ':"#{self}#{bar}baz"'
mutation ':"foo#{bar}#{nil}"'
mutation ':"foo#{bar}#{self}"'
mutation ':"foo#{nil}baz"'
mutation 'nil'
mutation ':"foo#{self}baz"'
end

View file

@ -3,7 +3,7 @@
Mutant::Meta::Example.add do
source 'begin; rescue; ensure; true; end'
singleton_mutations
mutation 'begin; rescue; ensure; false; end'
mutation 'begin; rescue; ensure; nil; end'
mutation 'nil'
end

8
meta/false.rb Normal file
View file

@ -0,0 +1,8 @@
# encoding: utf-8
Mutant::Meta::Example.add do
source 'false'
mutation 'nil'
mutation 'true'
end

View file

@ -3,8 +3,7 @@
Mutant::Meta::Example.add do
source '10.0'
# generic
mutation 'nil'
singleton_mutations
# edge cases
mutation '0.0'
@ -20,7 +19,7 @@ end
Mutant::Meta::Example.add do
source '0.0'
mutation 'nil'
singleton_mutations
mutation '1.0'
mutation '(0.0 / 0.0)'
mutation '(1.0 / 0.0)'
@ -30,7 +29,7 @@ end
Mutant::Meta::Example.add do
source '-0.0'
mutation 'nil'
singleton_mutations
mutation '1.0'
mutation '(0.0 / 0.0)'
mutation '(1.0 / 0.0)'

View file

@ -3,5 +3,5 @@
Mutant::Meta::Example.add do
source '$a'
mutation 'nil'
singleton_mutations
end

View file

@ -3,8 +3,8 @@
Mutant::Meta::Example.add do
source '$a = true'
singleton_mutations
mutation '$a__mutant__ = true'
mutation '$a = false'
mutation '$a = nil'
mutation 'nil'
end

View file

@ -3,8 +3,7 @@
Mutant::Meta::Example.add do
source '{true => true, false => false}'
# Literal replaced with nil
mutation 'nil'
singleton_mutations
# Mutation of each key and value in hash
mutation '{ false => true , false => false }'

View file

@ -1,57 +1,55 @@
# encoding: utf-8
Mutant::Meta::Example.add do
source 'if :condition; true; else false; end'
source 'if condition; true; else false; end'
singleton_mutations
# mutation of condition
mutation 'if :condition__mutant__; true; else false; end'
mutation 'if !:condition; true; else false; end'
mutation 'if nil; true; else false; end'
mutation 'if true; true; else false; end'
mutation 'if false; true; else false; end'
mutation 'if !condition; true; else false; end'
mutation 'if nil; true; else false; end'
mutation 'if true; true; else false; end'
mutation 'if false; true; else false; end'
# Deleted else branch
mutation 'if :condition; true end'
mutation 'if condition; true end'
# Deleted if branch resuting in unless rendering
mutation 'unless :condition; false; end'
mutation 'unless condition; false; end'
# Deleted if branch with promoting else branch to if branch
mutation 'if :condition; false end'
mutation 'if condition; false end'
# mutation of if body
mutation 'if :condition; false; else false; end'
mutation 'if :condition; nil; else false; end'
mutation 'if condition; false; else false; end'
mutation 'if condition; nil; else false; end'
# mutation of else body
mutation 'if :condition; true; else true; end'
mutation 'if :condition; true; else nil; end'
mutation 'nil'
mutation 'if condition; true; else true; end'
mutation 'if condition; true; else nil; end'
end
Mutant::Meta::Example.add do
source 'if condition; true; end'
singleton_mutations
mutation 'if !condition; true; end'
mutation 'if condition; false; end'
mutation 'if condition; nil; end'
mutation 'if true; true; end'
mutation 'if false; true; end'
mutation 'if nil; true; end'
mutation 'nil'
end
Mutant::Meta::Example.add do
source 'unless :condition; true; end'
source 'unless condition; true; end'
mutation 'unless !:condition; true; end'
mutation 'unless :condition__mutant__; true; end'
mutation 'unless nil; true; end'
mutation 'unless :condition; false; end'
mutation 'unless :condition; nil; end'
mutation 'unless true; true; end'
mutation 'unless false; true; end'
mutation 'if :condition; true; end'
mutation 'nil'
singleton_mutations
mutation 'unless !condition; true; end'
mutation 'unless nil; true; end'
mutation 'unless true; true; end'
mutation 'unless false; true; end'
mutation 'unless condition; false; end'
mutation 'unless condition; nil; end'
mutation 'if condition; true; end'
end

View file

@ -3,8 +3,7 @@
Mutant::Meta::Example.add do
source '10'
# generic
mutation 'nil'
singleton_mutations
# edge cases
mutation '0'

View file

@ -3,8 +3,8 @@
Mutant::Meta::Example.add do
source '@a = true'
singleton_mutations
mutation '@a__mutant__ = true'
mutation '@a = false'
mutation '@a = nil'
mutation 'nil'
end

View file

@ -3,7 +3,7 @@
Mutant::Meta::Example.add do
source 'begin; true; end'
singleton_mutations
mutation 'begin; false; end'
mutation 'begin; nil; end'
mutation 'nil'
end

View file

@ -4,11 +4,13 @@ Mutant::Meta::Example.add do
source 'a = nil; a'
mutation 'a = nil; nil'
mutation 'a = nil; self'
mutation 'a = nil'
# TODO: fix invalid AST
# These ASTs are not valid and should NOT be emitted
# Mutations of lvarasgn need to be special cased to avoid this.
mutation s(:begin, s(:lvasgn, :a__mutant__, s(:nil)), s(:lvar, :a))
mutation s(:begin, s(:nil), s(:lvar, :a))
mutation s(:begin, s(:self), s(:lvar, :a))
mutation s(:lvar, :a)
end

View file

@ -3,8 +3,8 @@
Mutant::Meta::Example.add do
source 'a = true'
singleton_mutations
mutation 'a__mutant__ = true'
mutation 'a = false'
mutation 'a = nil'
mutation 'nil'
end

View file

@ -3,5 +3,5 @@
Mutant::Meta::Example.add do
source 'a, b = c, d'
mutation 'nil'
singleton_mutations
end

View file

@ -3,6 +3,7 @@
Mutant::Meta::Example.add do
source 'true if /foo/'
singleton_mutations
mutation 'false if /foo/'
mutation 'true if //'
mutation 'nil if /foo/'
@ -10,5 +11,4 @@ Mutant::Meta::Example.add do
mutation 'true if false'
mutation 'true if nil'
mutation 'true if /a\A/'
mutation 'nil'
end

View file

@ -3,9 +3,9 @@
Mutant::Meta::Example.add do
source 'next true'
singleton_mutations
mutation 'next false'
mutation 'next nil'
mutation 'next'
mutation 'nil'
mutation 'break true'
end

View file

@ -3,12 +3,14 @@
Mutant::Meta::Example.add do
source '@a.b += 1'
singleton_mutations
mutation '@a.b += -1'
mutation '@a.b += 2'
mutation '@a.b += 0'
mutation '@a.b += nil'
mutation '@a.b += self'
mutation 'nil.b += 1'
mutation 'nil'
mutation 'self.b += 1'
# TODO: fix invalid AST
# This should not get emitted as invalid AST with valid unparsed source
mutation s(:op_asgn, s(:ivar, :@a), :+, s(:int, 1))

View file

@ -3,7 +3,7 @@
Mutant::Meta::Example.add do
source 'true or false'
mutation 'nil'
singleton_mutations
mutation 'true'
mutation 'false'
mutation 'true and false'

View file

@ -3,20 +3,22 @@
Mutant::Meta::Example.add do
source 'a ||= 1'
singleton_mutations
mutation 'a__mutant__ ||= 1'
mutation 'a ||= nil'
mutation 'a ||= self'
mutation 'a ||= 0'
mutation 'a ||= -1'
mutation 'a ||= 2'
mutation 'nil'
end
Mutant::Meta::Example.add do
source '@a ||= 1'
singleton_mutations
mutation '@a ||= nil'
mutation '@a ||= self'
mutation '@a ||= 0'
mutation '@a ||= -1'
mutation '@a ||= 2'
mutation 'nil'
end

View file

@ -3,7 +3,7 @@
Mutant::Meta::Example.add do
source '1..100'
mutation 'nil'
singleton_mutations
mutation '1...100'
mutation '(0.0 / 0.0)..100'
mutation '1..(1.0 / 0.0)'
@ -12,7 +12,9 @@ Mutant::Meta::Example.add do
mutation '0..100'
mutation '2..100'
mutation 'nil..100'
mutation 'self..100'
mutation '1..nil'
mutation '1..self'
mutation '1..0'
mutation '1..1'
mutation '1..99'
@ -23,7 +25,7 @@ end
Mutant::Meta::Example.add do
source '1...100'
mutation 'nil'
singleton_mutations
mutation '1..100'
mutation '(0.0 / 0.0)...100'
mutation '1...(1.0 / 0.0)'
@ -32,7 +34,9 @@ Mutant::Meta::Example.add do
mutation '0...100'
mutation '2...100'
mutation 'nil...100'
mutation 'self...100'
mutation '1...nil'
mutation '1...self'
mutation '1...0'
mutation '1...1'
mutation '1...99'

View file

@ -3,18 +3,20 @@
Mutant::Meta::Example.add do
source '/foo/'
singleton_mutations
mutation '//' # match all
mutation '/a\A/' # match nothing
mutation 'nil'
end
Mutant::Meta::Example.add do
source '/#{foo.bar}n/'
singleton_mutations
mutation '//' # match all
mutation '/#{foo}n/'
mutation '/a\A/' # match nothing
mutation '/#{nil.bar}n/'
mutation '/#{self.bar}n/'
mutation '/#{nil}n/'
mutation 'nil'
mutation '/#{self}n/'
end

View file

@ -3,8 +3,10 @@
Mutant::Meta::Example.add do
source 'begin; rescue ExceptionA, ExceptionB => error; true; end'
mutation 'nil'
singleton_mutations
mutation 'begin; rescue ExceptionA, ExceptionB; true; end'
mutation 'begin; rescue self, ExceptionB => error; true; end'
mutation 'begin; rescue ExceptionA, self => error; true; end'
mutation 'begin; rescue ExceptionA, ExceptionB => error; false; end'
mutation 'begin; rescue ExceptionA, ExceptionB => error; nil; end'
mutation 'begin; rescue ExceptionA => error; true; end'
@ -14,16 +16,17 @@ end
Mutant::Meta::Example.add do
source 'begin; rescue SomeException => error; true; end'
mutation 'nil'
singleton_mutations
mutation 'begin; rescue SomeException; true; end'
mutation 'begin; rescue SomeException => error; false; end'
mutation 'begin; rescue SomeException => error; nil; end'
mutation 'begin; rescue self => error; true; end'
end
Mutant::Meta::Example.add do
source 'begin; rescue => error; true end'
mutation 'nil'
singleton_mutations
mutation 'begin; rescue => error; false; end'
mutation 'begin; rescue => error; nil; end'
mutation 'begin; rescue; true; end'
@ -32,7 +35,7 @@ end
Mutant::Meta::Example.add do
source 'begin; rescue; true end'
mutation 'nil'
singleton_mutations
mutation 'begin; rescue; false; end'
mutation 'begin; rescue; nil; end'
end

View file

@ -3,9 +3,11 @@
Mutant::Meta::Example.add do
source 'foo(*bar)'
singleton_mutations
mutation 'foo'
mutation 'foo(nil)'
mutation 'foo(self)'
mutation 'foo(*self)'
mutation 'foo(bar)'
mutation 'foo(*nil)'
mutation 'nil'
end

View file

@ -3,13 +3,14 @@
Mutant::Meta::Example.add do
source 'return'
mutation 'nil'
singleton_mutations
end
Mutant::Meta::Example.add do
source 'return foo'
singleton_mutations
mutation 'foo'
mutation 'return nil'
mutation 'nil'
mutation 'return self'
end

View file

@ -3,14 +3,14 @@
Mutant::Meta::Example.add do
source 'reverse_each'
mutation 'nil'
singleton_mutations
mutation 'each'
end
Mutant::Meta::Example.add do
source 'reverse_map'
mutation 'nil'
singleton_mutations
mutation 'map'
mutation 'each'
end
@ -18,18 +18,20 @@ end
Mutant::Meta::Example.add do
source 'map'
mutation 'nil'
singleton_mutations
mutation 'each'
end
Mutant::Meta::Example.add do
source 'foo == bar'
singleton_mutations
mutation 'foo'
mutation 'bar'
mutation 'nil == bar'
mutation 'self == bar'
mutation 'foo == nil'
mutation 'nil'
mutation 'foo == self'
mutation 'foo.eql?(bar)'
mutation 'foo.equal?(bar)'
end
@ -37,43 +39,40 @@ end
Mutant::Meta::Example.add do
source 'foo.gsub(a, b)'
singleton_mutations
mutation 'foo'
mutation 'foo.gsub(a)'
mutation 'foo.gsub(b)'
mutation 'foo.gsub'
mutation 'foo.sub(a, b)'
mutation 'foo.gsub(a, nil)'
mutation 'foo.gsub(a, self)'
mutation 'foo.gsub(nil, b)'
mutation 'foo.gsub(self, b)'
mutation 'nil.gsub(a, b)'
mutation 'nil'
mutation 'self.gsub(a, b)'
end
Mutant::Meta::Example.add do
source 'foo.send(bar)'
singleton_mutations
mutation 'foo.send'
mutation 'foo.public_send(bar)'
mutation 'bar'
mutation 'foo'
mutation 'self.send(bar)'
mutation 'foo.send(nil)'
mutation 'foo.send(self)'
mutation 'nil.send(bar)'
mutation 'nil'
end
Mutant::Meta::Example.add do
source 'self.foo ||= expression'
source 'self.bar = baz'
mutation 'self.foo ||= nil'
mutation 'nil.foo ||= expression'
mutation 'nil'
end
Mutant::Meta::Example.add do
source 'self.bar=baz'
mutation 'nil'
mutation 'self.bar=nil'
mutation 'self'
singleton_mutations
mutation 'self.bar = nil'
mutation 'self.bar = self'
mutation 'self.bar'
mutation 'baz'
# This one could probably be removed
@ -81,105 +80,107 @@ Mutant::Meta::Example.add do
end
Mutant::Meta::Example.add do
source 'foo.bar=baz'
source 'foo.bar = baz'
singleton_mutations
mutation 'foo'
mutation 'nil'
mutation 'foo.bar=nil'
mutation 'foo.bar = nil'
mutation 'foo.bar = self'
mutation 'self.bar = baz'
mutation 'foo.bar'
mutation 'baz'
# This one could probably be removed
mutation 'nil.bar=baz'
mutation 'nil.bar = baz'
end
Mutant::Meta::Example.add do
source 'foo[bar]=baz'
singleton_mutations
mutation 'foo'
mutation 'nil'
end
Mutant::Meta::Example.add do
source 'foo(*bar)'
singleton_mutations
mutation 'foo'
mutation 'foo(nil)'
mutation 'foo(bar)'
mutation 'foo(self)'
mutation 'foo(*nil)'
mutation 'nil'
mutation 'foo(*self)'
end
Mutant::Meta::Example.add do
source 'foo(&bar)'
singleton_mutations
mutation 'foo'
mutation 'nil'
end
Mutant::Meta::Example.add do
source 'foo[*bar]'
singleton_mutations
mutation 'foo'
mutation 'nil'
end
Mutant::Meta::Example.add do
source 'foo'
mutation 'nil'
singleton_mutations
end
Mutant::Meta::Example.add do
source 'self.foo'
singleton_mutations
mutation 'foo'
mutation 'self'
mutation 'nil.foo'
mutation 'nil'
end
Unparser::Constants::KEYWORDS.each do |keyword|
Mutant::Meta::Example.add do
source "self.#{keyword}"
singleton_mutations
mutation "nil.#{keyword}"
mutation 'nil'
mutation 'self'
end
end
Mutant::Meta::Example.add do
source 'foo.bar'
singleton_mutations
mutation 'foo'
mutation 'nil.bar'
mutation 'nil'
mutation 'self.bar'
end
Mutant::Meta::Example.add do
source 'self.class.foo'
singleton_mutations
mutation 'self.class'
mutation 'self.foo'
mutation 'nil.class.foo'
mutation 'nil.foo'
mutation 'nil'
end
Mutant::Meta::Example.add do
source 'foo(nil)'
singleton_mutations
mutation 'foo'
mutation 'nil'
end
Mutant::Meta::Example.add do
source 'self.foo(nil)'
mutation 'self'
singleton_mutations
mutation 'self.foo'
mutation 'foo(nil)'
mutation 'nil'
mutation 'nil.foo(nil)'
end
@ -187,54 +188,50 @@ Unparser::Constants::KEYWORDS.each do |keyword|
Mutant::Meta::Example.add do
source "foo.#{keyword}(nil)"
singleton_mutations
mutation "self.#{keyword}(nil)"
mutation "foo.#{keyword}"
mutation 'foo'
mutation "nil.#{keyword}(nil)"
mutation 'nil'
end
end
Mutant::Meta::Example.add do
source 'foo(nil, nil)'
singleton_mutations
mutation 'foo()'
mutation 'foo(nil)'
mutation 'nil'
end
Mutant::Meta::Example.add do
source '(left - right) / foo'
singleton_mutations
mutation 'foo'
mutation '(left - right)'
mutation 'left / foo'
mutation 'right / foo'
mutation '(left - right) / nil'
mutation '(left - right) / self'
mutation '(left - nil) / foo'
mutation '(left - self) / foo'
mutation '(nil - right) / foo'
mutation '(self - right) / foo'
mutation 'nil / foo'
mutation 'nil'
mutation 'self / foo'
end
(Mutant::BINARY_METHOD_OPERATORS - [:==, :eql?]).each do |operator|
Mutant::Meta::Example.add do
source "true #{operator} false"
singleton_mutations
mutation 'true'
mutation 'false'
mutation "false #{operator} false"
mutation "nil #{operator} false"
mutation "true #{operator} true"
mutation "true #{operator} nil"
mutation 'true'
mutation 'false'
mutation 'nil'
end
Mutant::Meta::Example.add do
source "left #{operator} right"
mutation 'left'
mutation 'right'
mutation "left #{operator} nil"
mutation "nil #{operator} right"
mutation 'nil'
end
end

View file

@ -3,5 +3,5 @@
Mutant::Meta::Example.add do
source '"foo"'
mutation 'nil'
singleton_mutations
end

View file

@ -3,24 +3,27 @@
Mutant::Meta::Example.add do
source 'super'
mutation 'nil'
singleton_mutations
end
Mutant::Meta::Example.add do
source 'super()'
singleton_mutations
# this is zsuper a totally differend node thant super()
mutation 'super'
mutation 'nil'
end
Mutant::Meta::Example.add do
source 'super(foo, bar)'
singleton_mutations
mutation 'super'
mutation 'super()'
mutation 'super(foo)'
mutation 'super(bar)'
mutation 'super(foo, nil)'
mutation 'super(foo, self)'
mutation 'super(nil, bar)'
mutation 'nil'
mutation 'super(self, bar)'
end

View file

@ -3,6 +3,6 @@
Mutant::Meta::Example.add do
source ':foo'
mutation 'nil'
singleton_mutations
mutation ':foo__mutant__'
end

8
meta/true.rb Normal file
View file

@ -0,0 +1,8 @@
# encoding: utf-8
Mutant::Meta::Example.add do
source 'true'
mutation 'nil'
mutation 'false'
end

View file

@ -1,15 +0,0 @@
# encoding: utf-8
Mutant::Meta::Example.add do
source 'until true; foo; bar; end'
mutation 'until true; bar; end'
mutation 'until true; foo; end'
mutation 'until true; end'
mutation 'until false; foo; bar; end'
mutation 'until nil; foo; bar; end'
mutation 'until true; foo; nil; end'
mutation 'until true; nil; bar; end'
mutation 'until true; raise; end'
mutation 'nil'
end

17
meta/until.rb Normal file
View file

@ -0,0 +1,17 @@
# encoding: utf-8
Mutant::Meta::Example.add do
source 'until true; foo; bar; end'
singleton_mutations
mutation 'until true; bar; end'
mutation 'until true; foo; end'
mutation 'until true; end'
mutation 'until false; foo; bar; end'
mutation 'until nil; foo; bar; end'
mutation 'until true; foo; nil; end'
mutation 'until true; foo; self; end'
mutation 'until true; nil; bar; end'
mutation 'until true; self; bar; end'
mutation 'until true; raise; end'
end

View file

@ -3,6 +3,9 @@
Mutant::Meta::Example.add do
source 'while true; foo; bar; end'
singleton_mutations
mutation 'while true; self; bar; end'
mutation 'while true; foo; self; end'
mutation 'while true; bar; end'
mutation 'while true; foo; end'
mutation 'while true; end'
@ -11,14 +14,13 @@ Mutant::Meta::Example.add do
mutation 'while true; foo; nil; end'
mutation 'while true; nil; bar; end'
mutation 'while true; raise; end'
mutation 'nil'
end
Mutant::Meta::Example.add do
source 'while true; end'
singleton_mutations
mutation 'while true; raise; end'
mutation 'while false; end'
mutation 'while nil; end'
mutation 'nil'
end

View file

@ -3,8 +3,8 @@
Mutant::Meta::Example.add do
source 'yield true'
singleton_mutations
mutation 'yield false'
mutation 'yield nil'
mutation 'yield'
mutation 'nil'
end