Improve AST coverage of mutant
* Uses a monkeypach extension to parser with a list of valid node types. * Add nodes, found to be uncovered to generic mutator.
This commit is contained in:
parent
43c546fe74
commit
a7c3dc5339
5 changed files with 41 additions and 19 deletions
2
Gemfile
2
Gemfile
|
@ -2,6 +2,8 @@
|
|||
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gem 'unparser', git: 'https://github.com/mbj/unparser'
|
||||
|
||||
gemspec
|
||||
|
||||
gem 'mutant', path: '.'
|
||||
|
|
|
@ -22,6 +22,30 @@ require 'anima'
|
|||
require 'concord'
|
||||
require 'rspec'
|
||||
|
||||
# Monkeypatch on parser with a list of allowed nodes.
|
||||
# Will be pushed upstream once turning out to be correct.
|
||||
module Parser
|
||||
module Meta
|
||||
NODE_TYPES =
|
||||
%w(
|
||||
true false nil int float str dstr str
|
||||
sym dsym xstr regopt regexp array splat
|
||||
array pair kwsplat hash irange erange self
|
||||
lvar ivar cvar gvar const defined? lvasgn
|
||||
ivasgn cvasgn gvasgn casgn mlhs masgn op_asgn
|
||||
op_asgn and_asgn ensure rescue arg_expr
|
||||
or_asgn and_asgn or_asgn back_ref nth_ref
|
||||
match_with_lvasgn match_current_line
|
||||
module class sclass def defs undef alias args
|
||||
cbase arg optarg restarg blockarg block_pass args def kwarg kwoptarg
|
||||
kwrestarg send super zsuper yield block send
|
||||
and not or if when case while until while_post
|
||||
until_post for break next redo return resbody
|
||||
kwbegin begin retry preexe postexe iflipflop eflipflop
|
||||
).map(&:to_sym).to_set.freeze
|
||||
end # Meta
|
||||
end # Parser
|
||||
|
||||
# Library namespace
|
||||
module Mutant
|
||||
# The empty string used within this namespace
|
||||
|
@ -139,3 +163,4 @@ require 'mutant/reporter/cli/printer/subject'
|
|||
require 'mutant/reporter/cli/printer/killer'
|
||||
require 'mutant/reporter/cli/printer/mutation'
|
||||
require 'mutant/zombifier'
|
||||
|
||||
|
|
|
@ -35,25 +35,19 @@ module Mutant
|
|||
METHOD_OPERATORS + INDEX_OPERATORS + UNARY_METHOD_OPERATORS
|
||||
).to_set.freeze
|
||||
|
||||
# Hopefully all node types parser does generate.
|
||||
# Nodes that are NOT handled by mutant.
|
||||
#
|
||||
# FIXME: Maintain this list only in unparser / parser!
|
||||
# not - 1.8 only, mutant does not support 1.8
|
||||
#
|
||||
NODE_TYPES = [
|
||||
:lvasgn, :ivasgn, :cvasgn, :gvasgn,
|
||||
:casgn, :masgn, :mlhs, :break, :rescue,
|
||||
:ensure, :resbody, :begin, :retry, :arg_expr,
|
||||
:args, :blockarg, :optarg, :kwrestarg, :kwoptarg,
|
||||
:kwarg, :restarg, :arg, :block_pass, :or, :and,
|
||||
:next, :undef, :if, :module, :cbase, :block, :send,
|
||||
:zsuper, :super, :empty, :alias, :for, :redo,
|
||||
:return, :splat, :defined?, :op_asgn, :self,
|
||||
:true, :false, :nil, :dstr, :dsym, :regexp,
|
||||
:regopt, :int, :str, :float, :sym, :pair, :hash, :array,
|
||||
:xstr, :def, :defs, :case, :when, :ivar, :lvar, :cvar, :gvar,
|
||||
:back_ref, :const, :nth_ref, :class, :sclass, :yield,
|
||||
:match_with_lvasgn, :match_current_line, :irange, :erange,
|
||||
:or_asgn, :kwbegin, :and_asgn, :while
|
||||
].to_set.freeze
|
||||
NODE_BLACKLIST = %w(
|
||||
not
|
||||
).map(&:to_sym).freeze
|
||||
|
||||
# Nodes that are NOT generated by parser but used by mutant / unparser.
|
||||
NODE_EXTRA = %w(
|
||||
empty
|
||||
).map(&:to_sym).freeze
|
||||
|
||||
NODE_TYPES = ((Parser::Meta::NODE_TYPES + NODE_EXTRA) - NODE_BLACKLIST).to_set.freeze
|
||||
|
||||
end # Mutant
|
||||
|
|
|
@ -13,7 +13,7 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def s(type, *children)
|
||||
Parser::AST::Node.new(type, children)
|
||||
::Parser::AST::Node.new(type, children)
|
||||
end
|
||||
module_function :s
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Mutant do
|
||||
|
||||
specify 'mutant should not crash for any node parser can generate' do
|
||||
Mutant::NODE_TYPES.each do |type|
|
||||
Mutant::Mutator::Registry.lookup(Mutant::NodeHelpers.s(type))
|
||||
|
|
Loading…
Add table
Reference in a new issue