Skip to content

Commit

Permalink
Change to verified mutation generation
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Jun 29, 2024
1 parent bda7ef4 commit 64ea7bc
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lib/mutant/cli/command/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def print_mutations(target)
node: target.node
).each do |mutation|
Reporter::CLI::Printer::Mutation.call(
object: Mutant::Mutation::Evil.new(subject: target, node: mutation),
object: Mutant::Mutation::Evil.build(subject: target, node: mutation).from_right,
output: world.stdout
)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mutant/meta/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def generated
config: Mutation::Config::DEFAULT.with(operators:),
node:
).map do |node|
Mutation::Evil.new(subject: self, node:)
Mutation::Evil.build(subject: self, node:).from_right
end
end
memoize :generated
Expand Down
2 changes: 1 addition & 1 deletion lib/mutant/meta/example/verification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def unexpected

def missing
(example.expected.map(&:node) - mutations.map(&:node)).map do |node|
Mutation::Evil.new(subject: example, node:)
Mutation::Evil.build(subject: example, node:).from_right
end
end
memoize :missing
Expand Down
15 changes: 6 additions & 9 deletions lib/mutant/mutation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Mutant
# Represent a mutated node with its subject
class Mutation
include AbstractType, Adamantium
include Anima.new(:subject, :node)
include Anima.new(:subject, :node, :source)

CODE_DELIMITER = "\0"
CODE_RANGE = (..4)
Expand All @@ -17,14 +17,6 @@ def code
end
memoize :code

# Normalized mutation source
#
# @return [String]
def source
Unparser.unparse(node)
end
memoize :source

# Identification string
#
# @return [String]
Expand Down Expand Up @@ -84,6 +76,11 @@ def diff
end
memoize :diff

def self.build(node:, subject:)
Unparser.unparse_either(node)
.fmap { |source| new(node:, subject:, source:) }
end

private

def sha1
Expand Down
4 changes: 2 additions & 2 deletions lib/mutant/subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def mutations
config: config.mutation,
node:
).map do |mutant|
Mutation::Evil.new(subject: self, node: wrap_node(mutant))
Mutation::Evil.build(subject: self, node: wrap_node(mutant)).from_right
end
)
end
Expand Down Expand Up @@ -92,7 +92,7 @@ def source
private

def neutral_mutation
Mutation::Neutral.new(subject: self, node: wrap_node(node))
Mutation::Neutral.build(subject: self, node: wrap_node(node)).from_right
end

def wrap_node(node)
Expand Down
4 changes: 2 additions & 2 deletions spec/support/shared_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ def setup_shared_context
let(:subjects) { [subject_a] }

let(:mutation_a) do
Mutant::Mutation::Evil.new(subject: subject_a, node: mutation_a_node)
Mutant::Mutation::Evil.build(subject: subject_a, node: mutation_a_node).from_right
end

let(:mutation_b) do
Mutant::Mutation::Evil.new(subject: subject_a, node: mutation_b_node)
Mutant::Mutation::Evil.build(subject: subject_a, node: mutation_b_node).from_right
end

let(:job_a) do
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/mutant/meta/example/verification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

let(:mutations) do
generated_nodes.map do |node|
Mutant::Mutation::Evil.new(subject: example, node:)
Mutant::Mutation::Evil.build(subject: example, node:).from_right
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/mutant/meta/example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

let(:mutations) do
mutation_nodes.map do |node|
Mutant::Mutation::Evil.new(subject: object, node:)
Mutant::Mutation::Evil.build(subject: object, node:).from_right
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/mutant/mutation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
let(:root_node) { s(:int, 1) }

let(:object) do
mutation_class.new(subject: mutation_subject, node:)
mutation_class.build(subject: mutation_subject, node:).from_right
end

let(:mutation_subject) do
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/mutant/reporter/cli/printer/mutation_result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
with(:mutation_a_test_result) { { passed: false } }

let(:mutation_a) do
Mutant::Mutation::Neutral.new(subject: subject_a, node: s(:true))
Mutant::Mutation::Neutral.build(subject: subject_a, node: s(:true)).from_right
end

it_reports(<<~REPORT)
Expand All @@ -106,7 +106,7 @@
with(:mutation_a_test_result) { { passed: false } }

let(:mutation_a) do
Mutant::Mutation::Noop.new(subject: subject_a, node: s(:true))
Mutant::Mutation::Noop.build(subject: subject_a, node: s(:true)).from_right
end

it_reports(<<~REPORT)
Expand Down
12 changes: 6 additions & 6 deletions spec/unit/mutant/subject/method/instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,18 @@ def foo; end

let(:expected) do
[
Mutant::Mutation::Neutral.new(
Mutant::Mutation::Neutral.build(
subject: object,
node: s(:begin, s(:def, :foo, s(:args), nil), memoize_node)
),
Mutant::Mutation::Evil.new(
).from_right,
Mutant::Mutation::Evil.build(
subject: object,
node: s(:begin, s(:def, :foo, s(:args), s(:send, nil, :raise)), memoize_node)
),
Mutant::Mutation::Evil.new(
).from_right,
Mutant::Mutation::Evil.build(
subject: object,
node: s(:begin, s(:def, :foo, s(:args), s(:zsuper)), memoize_node)
)
).from_right
]
end

Expand Down
6 changes: 3 additions & 3 deletions spec/unit/mutant/subject_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ def foo

it 'generates neutral and evil mutations' do
should eql([
Mutant::Mutation::Neutral.new(subject: object, node:),
Mutant::Mutation::Evil.new(subject: object, node: mutation_a),
Mutant::Mutation::Evil.new(subject: object, node: mutation_b)
Mutant::Mutation::Neutral.build(subject: object, node:).from_right,
Mutant::Mutation::Evil.build(subject: object, node: mutation_a).from_right,
Mutant::Mutation::Evil.build(subject: object, node: mutation_b).from_right
])
end
end
Expand Down

0 comments on commit 64ea7bc

Please sign in to comment.