Merge pull request #791 from mbj/improve/example-verification
Improve example verification
This commit is contained in:
commit
148d632c20
2 changed files with 64 additions and 16 deletions
|
@ -11,7 +11,7 @@ module Mutant
|
||||||
#
|
#
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
def success?
|
def success?
|
||||||
missing.empty? && unexpected.empty? && no_diffs.empty?
|
[missing, unexpected, no_diffs, invalid_syntax].all?(&:empty?)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Error report
|
# Error report
|
||||||
|
@ -26,6 +26,7 @@ module Mutant
|
||||||
'original_source' => example.source,
|
'original_source' => example.source,
|
||||||
'missing' => format_mutations(missing),
|
'missing' => format_mutations(missing),
|
||||||
'unexpected' => format_mutations(unexpected),
|
'unexpected' => format_mutations(unexpected),
|
||||||
|
'invalid_syntax' => format_mutations(invalid_syntax),
|
||||||
'no_diff' => no_diff_report
|
'no_diff' => no_diff_report
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
@ -34,12 +35,35 @@ module Mutant
|
||||||
|
|
||||||
# Unexpected mutations
|
# Unexpected mutations
|
||||||
#
|
#
|
||||||
# @return [Array<Parser::AST::Node>]
|
# @return [Array<Mutation>]
|
||||||
def unexpected
|
def unexpected
|
||||||
mutations.map(&:node) - example.expected
|
mutations.reject do |mutation|
|
||||||
|
example.expected.include?(mutation.node)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
memoize :unexpected
|
memoize :unexpected
|
||||||
|
|
||||||
|
# Missing mutations
|
||||||
|
#
|
||||||
|
# @return [Array<Mutation>]
|
||||||
|
def missing
|
||||||
|
(example.expected - mutations.map(&:node)).map do |node|
|
||||||
|
Mutation::Evil.new(self, node)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
memoize :missing
|
||||||
|
|
||||||
|
# Mutations that generated invalid syntax
|
||||||
|
#
|
||||||
|
# @return [Enumerable<Mutation>]
|
||||||
|
def invalid_syntax
|
||||||
|
mutations.reject do |mutation|
|
||||||
|
::Parser::CurrentRuby.parse(mutation.source)
|
||||||
|
rescue ::Parser::SyntaxError # rubocop:disable Lint/HandleExceptions
|
||||||
|
end
|
||||||
|
end
|
||||||
|
memoize :invalid_syntax
|
||||||
|
|
||||||
# Mutations with no diff to original
|
# Mutations with no diff to original
|
||||||
#
|
#
|
||||||
# @return [Enumerable<Mutation>]
|
# @return [Enumerable<Mutation>]
|
||||||
|
@ -50,14 +74,14 @@ module Mutant
|
||||||
|
|
||||||
# Mutation report
|
# Mutation report
|
||||||
#
|
#
|
||||||
# @param [Array<Parser::AST::Node>] nodes
|
# @param [Array<Mutation>] mutations
|
||||||
#
|
#
|
||||||
# @return [Array<Hash>]
|
# @return [Array<Hash>]
|
||||||
def format_mutations(nodes)
|
def format_mutations(mutations)
|
||||||
nodes.map do |node|
|
mutations.map do |mutation|
|
||||||
{
|
{
|
||||||
'node' => node.inspect,
|
'node' => mutation.node.inspect,
|
||||||
'source' => Unparser.unparse(node)
|
'source' => mutation.source
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -74,14 +98,6 @@ module Mutant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Missing mutations
|
|
||||||
#
|
|
||||||
# @return [Array<Parser::AST::Node>]
|
|
||||||
def missing
|
|
||||||
example.expected - mutations.map(&:node)
|
|
||||||
end
|
|
||||||
memoize :missing
|
|
||||||
|
|
||||||
end # Verification
|
end # Verification
|
||||||
end # Example
|
end # Example
|
||||||
end # Meta
|
end # Meta
|
||||||
|
|
|
@ -75,6 +75,7 @@ RSpec.describe Mutant::Meta::Example::Verification do
|
||||||
- node: s(:nil)
|
- node: s(:nil)
|
||||||
source: nil
|
source: nil
|
||||||
unexpected: []
|
unexpected: []
|
||||||
|
invalid_syntax: []
|
||||||
no_diff: []
|
no_diff: []
|
||||||
REPORT
|
REPORT
|
||||||
end
|
end
|
||||||
|
@ -95,6 +96,7 @@ RSpec.describe Mutant::Meta::Example::Verification do
|
||||||
source: 'false'
|
source: 'false'
|
||||||
- node: s(:nil)
|
- node: s(:nil)
|
||||||
source: nil
|
source: nil
|
||||||
|
invalid_syntax: []
|
||||||
no_diff: []
|
no_diff: []
|
||||||
REPORT
|
REPORT
|
||||||
end
|
end
|
||||||
|
@ -112,11 +114,41 @@ RSpec.describe Mutant::Meta::Example::Verification do
|
||||||
original_source: 'true'
|
original_source: 'true'
|
||||||
missing: []
|
missing: []
|
||||||
unexpected: []
|
unexpected: []
|
||||||
|
invalid_syntax: []
|
||||||
no_diff:
|
no_diff:
|
||||||
- node: s(:true)
|
- node: s(:true)
|
||||||
source: 'true'
|
source: 'true'
|
||||||
REPORT
|
REPORT
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when the generated node is invalid syntax after unparsed' do
|
||||||
|
let(:invalid_node) do
|
||||||
|
s(:op_asgn, s(:send, s(:self), :at, s(:int, 1)), :+, s(:int, 1))
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:expected_nodes) { [invalid_node] }
|
||||||
|
let(:generated_nodes) { [invalid_node] }
|
||||||
|
|
||||||
|
specify do
|
||||||
|
should eql(<<~'REPORT')
|
||||||
|
---
|
||||||
|
file: foo.rb
|
||||||
|
original_ast: s(:true)
|
||||||
|
original_source: 'true'
|
||||||
|
missing: []
|
||||||
|
unexpected: []
|
||||||
|
invalid_syntax:
|
||||||
|
- node: |-
|
||||||
|
s(:op_asgn,
|
||||||
|
s(:send,
|
||||||
|
s(:self), :at,
|
||||||
|
s(:int, 1)), :+,
|
||||||
|
s(:int, 1))
|
||||||
|
source: self.at(1) += 1
|
||||||
|
no_diff: []
|
||||||
|
REPORT
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue