Change meta examples to allow specifying N types
This commit is contained in:
parent
ce5bcb4c62
commit
4355b23369
9 changed files with 44 additions and 43 deletions
|
@ -18,9 +18,9 @@ module Mutant
|
|||
# @return [undefined]
|
||||
#
|
||||
# rubocop:disable Performance/Caller
|
||||
def self.add(type, &block)
|
||||
def self.add(*types, &block)
|
||||
file = caller.first.split(':in', 2).first
|
||||
ALL << DSL.call(file, type, block)
|
||||
ALL << DSL.call(file, Set.new(types), block)
|
||||
end
|
||||
|
||||
Pathname.glob(Pathname.new(__dir__).parent.parent.join('meta', '*.rb'))
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
module Mutant
|
||||
module Meta
|
||||
class Example
|
||||
include Adamantium, Anima.new(:file, :node, :node_type, :expected)
|
||||
include Adamantium, Anima.new(:file, :node, :types, :expected)
|
||||
|
||||
# Verification instance for example
|
||||
#
|
||||
|
|
|
@ -9,9 +9,12 @@ module Mutant
|
|||
|
||||
# Run DSL on block
|
||||
#
|
||||
# @param [Pathname] file
|
||||
# @param [Set<Symbol>] types
|
||||
#
|
||||
# @return [Example]
|
||||
def self.call(file, type, block)
|
||||
instance = new(file, type)
|
||||
def self.call(file, types, block)
|
||||
instance = new(file, types)
|
||||
instance.instance_eval(&block)
|
||||
instance.example
|
||||
end
|
||||
|
@ -21,9 +24,9 @@ module Mutant
|
|||
# Initialize object
|
||||
#
|
||||
# @return [undefined]
|
||||
def initialize(file, type)
|
||||
def initialize(file, types)
|
||||
@file = file
|
||||
@type = type
|
||||
@types = types
|
||||
@node = nil
|
||||
@expected = []
|
||||
end
|
||||
|
@ -37,10 +40,10 @@ module Mutant
|
|||
def example
|
||||
fail 'source not defined' unless @node
|
||||
Example.new(
|
||||
file: @file,
|
||||
node: @node,
|
||||
node_type: @type,
|
||||
expected: @expected
|
||||
file: @file,
|
||||
node: @node,
|
||||
types: @types,
|
||||
expected: @expected
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -80,10 +80,3 @@ Pathname
|
|||
.glob(Pathname.new(__dir__).join('regexp', '*.rb'))
|
||||
.sort
|
||||
.each(&Kernel.public_method(:require))
|
||||
|
||||
# Re-register examples for all regular expression nodes for node_type `:regexp`
|
||||
Mutant::Meta::Example::ALL.each do |example|
|
||||
next unless example.node_type.to_s.start_with?('regexp_')
|
||||
|
||||
Mutant::Meta::Example::ALL << example.with(node_type: :regexp)
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ mutations = {
|
|||
mutations = mutations.merge(mutations.invert)
|
||||
|
||||
mutations.each do |(source_type, source_mutation), (_, regexp_mutation)|
|
||||
Mutant::Meta::Example.add source_type do
|
||||
Mutant::Meta::Example.add :regexp, source_type do
|
||||
source(source_mutation)
|
||||
|
||||
singleton_mutations
|
||||
|
|
|
@ -2,19 +2,19 @@
|
|||
|
||||
RSpec.describe Mutant::Meta::Example::DSL do
|
||||
describe '.call' do
|
||||
subject { described_class.call(file, type, block) }
|
||||
subject { described_class.call(file, types, block) }
|
||||
|
||||
let(:file) { 'foo.rb' }
|
||||
let(:node) { s(:false) }
|
||||
let(:type) { node.type }
|
||||
let(:expected) { [] }
|
||||
let(:file) { 'foo.rb' }
|
||||
let(:node) { s(:false) }
|
||||
let(:types) { Set.new([node.type]) }
|
||||
let(:expected) { [] }
|
||||
|
||||
let(:expected_example) do
|
||||
Mutant::Meta::Example.new(
|
||||
file: file,
|
||||
node: node,
|
||||
node_type: type,
|
||||
expected: expected
|
||||
file: file,
|
||||
node: node,
|
||||
types: types,
|
||||
expected: expected
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -5,10 +5,10 @@ RSpec.describe Mutant::Meta::Example::Verification do
|
|||
|
||||
let(:example) do
|
||||
Mutant::Meta::Example.new(
|
||||
file: 'foo.rb',
|
||||
node: s(:true),
|
||||
node_type: :true,
|
||||
expected: expected_nodes
|
||||
file: 'foo.rb',
|
||||
node: s(:true),
|
||||
types: [:true],
|
||||
expected: expected_nodes
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
RSpec.describe Mutant::Meta::Example do
|
||||
let(:object) do
|
||||
described_class.new(
|
||||
file: file,
|
||||
node: node,
|
||||
node_type: node.type,
|
||||
expected: mutation_nodes
|
||||
file: file,
|
||||
node: node,
|
||||
types: [node.type],
|
||||
expected: mutation_nodes
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,15 +1,20 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
Mutant::Meta::Example::ALL.each.group_by(&:node_type).each do |type, examples|
|
||||
RSpec.describe Mutant::Mutator::REGISTRY.lookup(type) do
|
||||
toplevel_nodes = examples.map { |example| example.node.type }.uniq
|
||||
aggregate = Hash.new { |hash, key| hash[key] = [] }
|
||||
|
||||
it "generates the correct mutations on #{toplevel_nodes} toplevel examples" do
|
||||
Mutant::Meta::Example::ALL
|
||||
.each_with_object(aggregate) do |example, agg|
|
||||
example.types.each do |type|
|
||||
agg[Mutant::Mutator::REGISTRY.lookup(type)] << example
|
||||
end
|
||||
end
|
||||
|
||||
aggregate.each do |mutator, examples|
|
||||
RSpec.describe mutator do
|
||||
it 'generates expected mutations' do
|
||||
examples.each do |example|
|
||||
verification = example.verification
|
||||
unless verification.success?
|
||||
fail verification.error_report
|
||||
end
|
||||
fail verification.error_report unless verification.success?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue