Skip to content

Commit 64ea7bc

Browse files
committed
Change to verified mutation generation
1 parent bda7ef4 commit 64ea7bc

File tree

12 files changed

+27
-30
lines changed

12 files changed

+27
-30
lines changed

lib/mutant/cli/command/util.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def print_mutations(target)
7878
node: target.node
7979
).each do |mutation|
8080
Reporter::CLI::Printer::Mutation.call(
81-
object: Mutant::Mutation::Evil.new(subject: target, node: mutation),
81+
object: Mutant::Mutation::Evil.build(subject: target, node: mutation).from_right,
8282
output: world.stdout
8383
)
8484
end

lib/mutant/meta/example.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def generated
6161
config: Mutation::Config::DEFAULT.with(operators:),
6262
node:
6363
).map do |node|
64-
Mutation::Evil.new(subject: self, node:)
64+
Mutation::Evil.build(subject: self, node:).from_right
6565
end
6666
end
6767
memoize :generated

lib/mutant/meta/example/verification.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def unexpected
9494

9595
def missing
9696
(example.expected.map(&:node) - mutations.map(&:node)).map do |node|
97-
Mutation::Evil.new(subject: example, node:)
97+
Mutation::Evil.build(subject: example, node:).from_right
9898
end
9999
end
100100
memoize :missing

lib/mutant/mutation.rb

+6-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Mutant
44
# Represent a mutated node with its subject
55
class Mutation
66
include AbstractType, Adamantium
7-
include Anima.new(:subject, :node)
7+
include Anima.new(:subject, :node, :source)
88

99
CODE_DELIMITER = "\0"
1010
CODE_RANGE = (..4)
@@ -17,14 +17,6 @@ def code
1717
end
1818
memoize :code
1919

20-
# Normalized mutation source
21-
#
22-
# @return [String]
23-
def source
24-
Unparser.unparse(node)
25-
end
26-
memoize :source
27-
2820
# Identification string
2921
#
3022
# @return [String]
@@ -84,6 +76,11 @@ def diff
8476
end
8577
memoize :diff
8678

79+
def self.build(node:, subject:)
80+
Unparser.unparse_either(node)
81+
.fmap { |source| new(node:, subject:, source:) }
82+
end
83+
8784
private
8885

8986
def sha1

lib/mutant/subject.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def mutations
1616
config: config.mutation,
1717
node:
1818
).map do |mutant|
19-
Mutation::Evil.new(subject: self, node: wrap_node(mutant))
19+
Mutation::Evil.build(subject: self, node: wrap_node(mutant)).from_right
2020
end
2121
)
2222
end
@@ -92,7 +92,7 @@ def source
9292
private
9393

9494
def neutral_mutation
95-
Mutation::Neutral.new(subject: self, node: wrap_node(node))
95+
Mutation::Neutral.build(subject: self, node: wrap_node(node)).from_right
9696
end
9797

9898
def wrap_node(node)

spec/support/shared_context.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ def setup_shared_context
3838
let(:subjects) { [subject_a] }
3939

4040
let(:mutation_a) do
41-
Mutant::Mutation::Evil.new(subject: subject_a, node: mutation_a_node)
41+
Mutant::Mutation::Evil.build(subject: subject_a, node: mutation_a_node).from_right
4242
end
4343

4444
let(:mutation_b) do
45-
Mutant::Mutation::Evil.new(subject: subject_a, node: mutation_b_node)
45+
Mutant::Mutation::Evil.build(subject: subject_a, node: mutation_b_node).from_right
4646
end
4747

4848
let(:job_a) do

spec/unit/mutant/meta/example/verification_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
let(:mutations) do
2828
generated_nodes.map do |node|
29-
Mutant::Mutation::Evil.new(subject: example, node:)
29+
Mutant::Mutation::Evil.build(subject: example, node:).from_right
3030
end
3131
end
3232

spec/unit/mutant/meta/example_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
let(:mutations) do
2828
mutation_nodes.map do |node|
29-
Mutant::Mutation::Evil.new(subject: object, node:)
29+
Mutant::Mutation::Evil.build(subject: object, node:).from_right
3030
end
3131
end
3232

spec/unit/mutant/mutation_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
let(:root_node) { s(:int, 1) }
1515

1616
let(:object) do
17-
mutation_class.new(subject: mutation_subject, node:)
17+
mutation_class.build(subject: mutation_subject, node:).from_right
1818
end
1919

2020
let(:mutation_subject) do

spec/unit/mutant/reporter/cli/printer/mutation_result_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
with(:mutation_a_test_result) { { passed: false } }
8585

8686
let(:mutation_a) do
87-
Mutant::Mutation::Neutral.new(subject: subject_a, node: s(:true))
87+
Mutant::Mutation::Neutral.build(subject: subject_a, node: s(:true)).from_right
8888
end
8989

9090
it_reports(<<~REPORT)
@@ -106,7 +106,7 @@
106106
with(:mutation_a_test_result) { { passed: false } }
107107

108108
let(:mutation_a) do
109-
Mutant::Mutation::Noop.new(subject: subject_a, node: s(:true))
109+
Mutant::Mutation::Noop.build(subject: subject_a, node: s(:true)).from_right
110110
end
111111

112112
it_reports(<<~REPORT)

spec/unit/mutant/subject/method/instance_spec.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,18 @@ def foo; end
155155

156156
let(:expected) do
157157
[
158-
Mutant::Mutation::Neutral.new(
158+
Mutant::Mutation::Neutral.build(
159159
subject: object,
160160
node: s(:begin, s(:def, :foo, s(:args), nil), memoize_node)
161-
),
162-
Mutant::Mutation::Evil.new(
161+
).from_right,
162+
Mutant::Mutation::Evil.build(
163163
subject: object,
164164
node: s(:begin, s(:def, :foo, s(:args), s(:send, nil, :raise)), memoize_node)
165-
),
166-
Mutant::Mutation::Evil.new(
165+
).from_right,
166+
Mutant::Mutation::Evil.build(
167167
subject: object,
168168
node: s(:begin, s(:def, :foo, s(:args), s(:zsuper)), memoize_node)
169-
)
169+
).from_right
170170
]
171171
end
172172

spec/unit/mutant/subject_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ def foo
100100

101101
it 'generates neutral and evil mutations' do
102102
should eql([
103-
Mutant::Mutation::Neutral.new(subject: object, node:),
104-
Mutant::Mutation::Evil.new(subject: object, node: mutation_a),
105-
Mutant::Mutation::Evil.new(subject: object, node: mutation_b)
103+
Mutant::Mutation::Neutral.build(subject: object, node:).from_right,
104+
Mutant::Mutation::Evil.build(subject: object, node: mutation_a).from_right,
105+
Mutant::Mutation::Evil.build(subject: object, node: mutation_b).from_right
106106
])
107107
end
108108
end

0 commit comments

Comments
 (0)