parent
49517af01c
commit
1ae2c04193
9 changed files with 63 additions and 18 deletions
|
@ -1,6 +1,7 @@
|
|||
# v0.6.1 2014-08-16
|
||||
|
||||
* Add rescue else body promotion/concatenation mutation
|
||||
* Add rescue resbody body concat-promotion mutation
|
||||
* Add rescue else body concat-promotion mutation #245
|
||||
|
||||
# v0.6.0 2014-08-11
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
---
|
||||
threshold: 18
|
||||
total_score: 1076
|
||||
total_score: 1085
|
||||
|
|
|
@ -17,14 +17,42 @@ module Mutant
|
|||
REGISTRY.fetch(node.type, Generic).new(node)
|
||||
end
|
||||
|
||||
# Generic metadata for send nodes
|
||||
# Mixin to define meta nodes
|
||||
class Node < Module
|
||||
include Concord.new(:type)
|
||||
|
||||
CONCORD = Concord.new(:node)
|
||||
|
||||
# Hook called when module gets included
|
||||
#
|
||||
# @param [Class, Module] host
|
||||
#
|
||||
# @return [undefined]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def included(host)
|
||||
REGISTRY[type] = host
|
||||
host.class_eval do
|
||||
include CONCORD, NamedChildren
|
||||
end
|
||||
end
|
||||
|
||||
end # Node
|
||||
|
||||
# Metadata for resbody nods
|
||||
class Resbody
|
||||
include Node.new(:resbody)
|
||||
|
||||
children :captures, :assignment, :body
|
||||
end # Resbody
|
||||
|
||||
# Metadata for send nodes
|
||||
class Send
|
||||
include Concord.new(:node), NamedChildren
|
||||
include Node.new(:send)
|
||||
|
||||
children :receiver, :selector
|
||||
|
||||
REGISTRY[:send] = self
|
||||
|
||||
INDEX_ASSIGNMENT_SELECTOR = :[]=
|
||||
ATTRIBUTE_ASSIGNMENT_SELECTOR_SUFFIX = '='.freeze
|
||||
|
||||
|
|
|
@ -16,7 +16,8 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def self.add(&block)
|
||||
ALL << DSL.run(block)
|
||||
file = caller.first.split(':in', 2).first
|
||||
ALL << DSL.run(file, block)
|
||||
end
|
||||
|
||||
Pathname.glob(Pathname.new(__FILE__).parent.parent.parent.join('meta', '**/*.rb'))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module Mutant
|
||||
module Meta
|
||||
class Example
|
||||
include Adamantium, Concord::Public.new(:node, :mutations)
|
||||
include Adamantium, Concord::Public.new(:file, :node, :mutations)
|
||||
|
||||
# Return a verification instance
|
||||
#
|
||||
|
@ -97,7 +97,7 @@ module Mutant
|
|||
def mutation_report
|
||||
original_node = example.node
|
||||
[
|
||||
'Original-AST:',
|
||||
"#{example.file}, Original-AST:",
|
||||
original_node.inspect,
|
||||
'Original-Source:',
|
||||
example.source,
|
||||
|
|
|
@ -12,8 +12,8 @@ module Mutant
|
|||
#
|
||||
# @api private
|
||||
#
|
||||
def self.run(block)
|
||||
instance = new
|
||||
def self.run(file, block)
|
||||
instance = new(file)
|
||||
instance.instance_eval(&block)
|
||||
instance.example
|
||||
end
|
||||
|
@ -24,7 +24,8 @@ module Mutant
|
|||
#
|
||||
# @api private
|
||||
#
|
||||
def initialize
|
||||
def initialize(file)
|
||||
@file = file
|
||||
@source = nil
|
||||
@expected = []
|
||||
end
|
||||
|
@ -40,7 +41,7 @@ module Mutant
|
|||
#
|
||||
def example
|
||||
raise 'source not defined' unless @source
|
||||
Example.new(@source, @expected)
|
||||
Example.new(@file, @source, @expected)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -34,8 +34,11 @@ module Mutant
|
|||
#
|
||||
def mutate_rescue_bodies
|
||||
children_indices(RESCUE_INDICES).each do |index|
|
||||
next unless children.at(index)
|
||||
rescue_body = children.at(index)
|
||||
next unless rescue_body
|
||||
mutate_child(index)
|
||||
resbody_body = AST::Meta.for(rescue_body).body
|
||||
emit_concat(resbody_body) if resbody_body
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -48,8 +51,11 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def emit_concat(child)
|
||||
raise unless body
|
||||
emit(s(:begin, body, child))
|
||||
if body
|
||||
emit(s(:begin, body, child))
|
||||
else
|
||||
emit(child)
|
||||
end
|
||||
end
|
||||
|
||||
# Emit body mutations
|
||||
|
|
|
@ -14,7 +14,7 @@ Mutant::Meta::Example.add do
|
|||
mutation 'def foo; self; rescue; end'
|
||||
mutation 'def foo; end'
|
||||
|
||||
# Promote rescue body
|
||||
# Promote rescue resbody bodies
|
||||
mutation 'def foo; foo; end'
|
||||
end
|
||||
|
||||
|
@ -29,10 +29,13 @@ Mutant::Meta::Example.add do
|
|||
mutation 'def a; foo; rescue; bar; else; nil; end'
|
||||
mutation 'def a; foo; rescue; bar; else; self; end'
|
||||
|
||||
# Promote and concat rescue resbody bodies
|
||||
mutation 'def a; foo; bar; end'
|
||||
|
||||
# Promote and concat else body
|
||||
mutation 'def a; foo; baz; end'
|
||||
|
||||
# Promote body
|
||||
# Promote rescue body
|
||||
mutation 'def a; foo; end'
|
||||
|
||||
# Empty body
|
||||
|
|
|
@ -9,6 +9,8 @@ Mutant::Meta::Example.add do
|
|||
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; true; end'
|
||||
|
||||
end
|
||||
|
||||
Mutant::Meta::Example.add do
|
||||
|
@ -19,6 +21,7 @@ Mutant::Meta::Example.add do
|
|||
mutation 'begin; rescue SomeException => error; false; end'
|
||||
mutation 'begin; rescue SomeException => error; nil; end'
|
||||
mutation 'begin; rescue self => error; true; end'
|
||||
mutation 'begin; true; end'
|
||||
end
|
||||
|
||||
Mutant::Meta::Example.add do
|
||||
|
@ -28,6 +31,7 @@ Mutant::Meta::Example.add do
|
|||
mutation 'begin; rescue => error; false; end'
|
||||
mutation 'begin; rescue => error; nil; end'
|
||||
mutation 'begin; rescue; true; end'
|
||||
mutation 'begin; true; end'
|
||||
end
|
||||
|
||||
Mutant::Meta::Example.add do
|
||||
|
@ -36,4 +40,5 @@ Mutant::Meta::Example.add do
|
|||
singleton_mutations
|
||||
mutation 'begin; rescue; false; end'
|
||||
mutation 'begin; rescue; nil; end'
|
||||
mutation 'begin; true end'
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue