evilution 0.11.2 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.beads/.migration-hint-ts +1 -1
- data/.beads/issues.jsonl +149 -10
- data/CHANGELOG.md +23 -0
- data/README.md +13 -5
- data/lib/evilution/cli.rb +1 -0
- data/lib/evilution/config.rb +11 -1
- data/lib/evilution/mcp/mutate_tool.rb +16 -5
- data/lib/evilution/mutator/operator/compound_assignment.rb +123 -0
- data/lib/evilution/mutator/operator/integer_literal.rb +16 -44
- data/lib/evilution/mutator/registry.rb +2 -1
- data/lib/evilution/reporter/html.rb +1 -1
- data/lib/evilution/reporter/suggestion.rb +289 -1
- data/lib/evilution/version.rb +1 -1
- data/lib/evilution.rb +1 -0
- metadata +3 -2
|
@@ -23,11 +23,281 @@ module Evilution
|
|
|
23
23
|
"return_value_removal" => "Add a test that uses the return value of this method",
|
|
24
24
|
"collection_replacement" => "Add a test that checks the return value of the collection operation, not just side effects",
|
|
25
25
|
"method_call_removal" => "Add a test that depends on the return value or side effect of this method call",
|
|
26
|
-
"argument_removal" => "Add a test that verifies the correct arguments are passed to this method call"
|
|
26
|
+
"argument_removal" => "Add a test that verifies the correct arguments are passed to this method call",
|
|
27
|
+
"compound_assignment" => "Add a test that verifies the side effect of this compound assignment (the accumulated value matters)"
|
|
28
|
+
}.freeze
|
|
29
|
+
|
|
30
|
+
CONCRETE_TEMPLATES = {
|
|
31
|
+
"comparison_replacement" => lambda { |mutation|
|
|
32
|
+
method_name = parse_method_name(mutation.subject.name)
|
|
33
|
+
original_line, mutated_line = extract_diff_lines(mutation.diff)
|
|
34
|
+
<<~RSPEC.strip
|
|
35
|
+
# Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
|
|
36
|
+
# #{mutation.file_path}:#{mutation.line}
|
|
37
|
+
it 'returns the correct result at the comparison boundary in ##{method_name}' do
|
|
38
|
+
# Test with values where the original operator and mutated operator
|
|
39
|
+
# produce different results (e.g., equal values for > vs >=)
|
|
40
|
+
result = subject.#{method_name}(boundary_value)
|
|
41
|
+
expect(result).to eq(expected)
|
|
42
|
+
end
|
|
43
|
+
RSPEC
|
|
44
|
+
},
|
|
45
|
+
"arithmetic_replacement" => lambda { |mutation|
|
|
46
|
+
method_name = parse_method_name(mutation.subject.name)
|
|
47
|
+
original_line, mutated_line = extract_diff_lines(mutation.diff)
|
|
48
|
+
<<~RSPEC.strip
|
|
49
|
+
# Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
|
|
50
|
+
# #{mutation.file_path}:#{mutation.line}
|
|
51
|
+
it 'computes the correct arithmetic result in ##{method_name}' do
|
|
52
|
+
# Assert the exact numeric result, not just truthiness or sign
|
|
53
|
+
result = subject.#{method_name}(input_value)
|
|
54
|
+
expect(result).to eq(expected)
|
|
55
|
+
end
|
|
56
|
+
RSPEC
|
|
57
|
+
},
|
|
58
|
+
"boolean_operator_replacement" => lambda { |mutation|
|
|
59
|
+
method_name = parse_method_name(mutation.subject.name)
|
|
60
|
+
original_line, mutated_line = extract_diff_lines(mutation.diff)
|
|
61
|
+
<<~RSPEC.strip
|
|
62
|
+
# Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
|
|
63
|
+
# #{mutation.file_path}:#{mutation.line}
|
|
64
|
+
it 'returns the correct result when one condition is true and one is false in ##{method_name}' do
|
|
65
|
+
# Use inputs where only one operand is truthy to distinguish && from ||
|
|
66
|
+
result = subject.#{method_name}(input_value)
|
|
67
|
+
expect(result).to eq(expected)
|
|
68
|
+
end
|
|
69
|
+
RSPEC
|
|
70
|
+
},
|
|
71
|
+
"boolean_literal_replacement" => lambda { |mutation|
|
|
72
|
+
method_name = parse_method_name(mutation.subject.name)
|
|
73
|
+
original_line, mutated_line = extract_diff_lines(mutation.diff)
|
|
74
|
+
<<~RSPEC.strip
|
|
75
|
+
# Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
|
|
76
|
+
# #{mutation.file_path}:#{mutation.line}
|
|
77
|
+
it 'returns the expected boolean value from ##{method_name}' do
|
|
78
|
+
# Assert the exact true/false/nil value, not just truthiness
|
|
79
|
+
result = subject.#{method_name}(input_value)
|
|
80
|
+
expect(result).to eq(expected)
|
|
81
|
+
end
|
|
82
|
+
RSPEC
|
|
83
|
+
},
|
|
84
|
+
"negation_insertion" => lambda { |mutation|
|
|
85
|
+
method_name = parse_method_name(mutation.subject.name)
|
|
86
|
+
original_line, mutated_line = extract_diff_lines(mutation.diff)
|
|
87
|
+
<<~RSPEC.strip
|
|
88
|
+
# Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
|
|
89
|
+
# #{mutation.file_path}:#{mutation.line}
|
|
90
|
+
it 'returns the correct boolean from the predicate in ##{method_name}' do
|
|
91
|
+
# Assert the exact true/false result, not just truthiness
|
|
92
|
+
result = subject.#{method_name}(input_value)
|
|
93
|
+
expect(result).to eq(true).or eq(false)
|
|
94
|
+
end
|
|
95
|
+
RSPEC
|
|
96
|
+
},
|
|
97
|
+
"integer_literal" => lambda { |mutation|
|
|
98
|
+
method_name = parse_method_name(mutation.subject.name)
|
|
99
|
+
original_line, mutated_line = extract_diff_lines(mutation.diff)
|
|
100
|
+
<<~RSPEC.strip
|
|
101
|
+
# Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
|
|
102
|
+
# #{mutation.file_path}:#{mutation.line}
|
|
103
|
+
it 'returns the exact integer value from ##{method_name}' do
|
|
104
|
+
# Assert the exact numeric value, not just > 0 or truthy
|
|
105
|
+
result = subject.#{method_name}(input_value)
|
|
106
|
+
expect(result).to eq(expected)
|
|
107
|
+
end
|
|
108
|
+
RSPEC
|
|
109
|
+
},
|
|
110
|
+
"float_literal" => lambda { |mutation|
|
|
111
|
+
method_name = parse_method_name(mutation.subject.name)
|
|
112
|
+
original_line, mutated_line = extract_diff_lines(mutation.diff)
|
|
113
|
+
<<~RSPEC.strip
|
|
114
|
+
# Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
|
|
115
|
+
# #{mutation.file_path}:#{mutation.line}
|
|
116
|
+
it 'returns the exact float value from ##{method_name}' do
|
|
117
|
+
# Assert the exact floating-point result
|
|
118
|
+
result = subject.#{method_name}(input_value)
|
|
119
|
+
expect(result).to eq(expected)
|
|
120
|
+
end
|
|
121
|
+
RSPEC
|
|
122
|
+
},
|
|
123
|
+
"string_literal" => lambda { |mutation|
|
|
124
|
+
method_name = parse_method_name(mutation.subject.name)
|
|
125
|
+
original_line, mutated_line = extract_diff_lines(mutation.diff)
|
|
126
|
+
<<~RSPEC.strip
|
|
127
|
+
# Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
|
|
128
|
+
# #{mutation.file_path}:#{mutation.line}
|
|
129
|
+
it 'returns the exact string content from ##{method_name}' do
|
|
130
|
+
# Assert the exact string value, not just presence or non-empty
|
|
131
|
+
result = subject.#{method_name}(input_value)
|
|
132
|
+
expect(result).to eq(expected)
|
|
133
|
+
end
|
|
134
|
+
RSPEC
|
|
135
|
+
},
|
|
136
|
+
"symbol_literal" => lambda { |mutation|
|
|
137
|
+
method_name = parse_method_name(mutation.subject.name)
|
|
138
|
+
original_line, mutated_line = extract_diff_lines(mutation.diff)
|
|
139
|
+
<<~RSPEC.strip
|
|
140
|
+
# Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
|
|
141
|
+
# #{mutation.file_path}:#{mutation.line}
|
|
142
|
+
it 'returns the exact symbol from ##{method_name}' do
|
|
143
|
+
# Assert the exact symbol value, not just that it is a Symbol
|
|
144
|
+
result = subject.#{method_name}(input_value)
|
|
145
|
+
expect(result).to eq(expected)
|
|
146
|
+
end
|
|
147
|
+
RSPEC
|
|
148
|
+
},
|
|
149
|
+
"array_literal" => lambda { |mutation|
|
|
150
|
+
method_name = parse_method_name(mutation.subject.name)
|
|
151
|
+
original_line, mutated_line = extract_diff_lines(mutation.diff)
|
|
152
|
+
<<~RSPEC.strip
|
|
153
|
+
# Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
|
|
154
|
+
# #{mutation.file_path}:#{mutation.line}
|
|
155
|
+
it 'returns the expected array contents from ##{method_name}' do
|
|
156
|
+
# Assert the exact array elements, not just non-empty or truthy
|
|
157
|
+
result = subject.#{method_name}(input_value)
|
|
158
|
+
expect(result).to eq(expected)
|
|
159
|
+
end
|
|
160
|
+
RSPEC
|
|
161
|
+
},
|
|
162
|
+
"hash_literal" => lambda { |mutation|
|
|
163
|
+
method_name = parse_method_name(mutation.subject.name)
|
|
164
|
+
original_line, mutated_line = extract_diff_lines(mutation.diff)
|
|
165
|
+
<<~RSPEC.strip
|
|
166
|
+
# Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
|
|
167
|
+
# #{mutation.file_path}:#{mutation.line}
|
|
168
|
+
it 'returns the expected hash contents from ##{method_name}' do
|
|
169
|
+
# Assert the exact keys and values, not just non-empty or truthy
|
|
170
|
+
result = subject.#{method_name}(input_value)
|
|
171
|
+
expect(result).to eq(expected)
|
|
172
|
+
end
|
|
173
|
+
RSPEC
|
|
174
|
+
},
|
|
175
|
+
"collection_replacement" => lambda { |mutation|
|
|
176
|
+
method_name = parse_method_name(mutation.subject.name)
|
|
177
|
+
original_line, mutated_line = extract_diff_lines(mutation.diff)
|
|
178
|
+
<<~RSPEC.strip
|
|
179
|
+
# Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
|
|
180
|
+
# #{mutation.file_path}:#{mutation.line}
|
|
181
|
+
it 'uses the return value of the collection operation in ##{method_name}' do
|
|
182
|
+
# Assert the return value of the collection method, not just side effects
|
|
183
|
+
result = subject.#{method_name}(input_value)
|
|
184
|
+
expect(result).to eq(expected)
|
|
185
|
+
end
|
|
186
|
+
RSPEC
|
|
187
|
+
},
|
|
188
|
+
"conditional_negation" => lambda { |mutation|
|
|
189
|
+
method_name = parse_method_name(mutation.subject.name)
|
|
190
|
+
original_line, mutated_line = extract_diff_lines(mutation.diff)
|
|
191
|
+
<<~RSPEC.strip
|
|
192
|
+
# Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
|
|
193
|
+
# #{mutation.file_path}:#{mutation.line}
|
|
194
|
+
it 'exercises both branches of the conditional in ##{method_name}' do
|
|
195
|
+
# Test with inputs that make the condition true AND false
|
|
196
|
+
result = subject.#{method_name}(input_value)
|
|
197
|
+
expect(result).to eq(expected)
|
|
198
|
+
end
|
|
199
|
+
RSPEC
|
|
200
|
+
},
|
|
201
|
+
"conditional_branch" => lambda { |mutation|
|
|
202
|
+
method_name = parse_method_name(mutation.subject.name)
|
|
203
|
+
original_line, mutated_line = extract_diff_lines(mutation.diff)
|
|
204
|
+
<<~RSPEC.strip
|
|
205
|
+
# Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
|
|
206
|
+
# #{mutation.file_path}:#{mutation.line}
|
|
207
|
+
it 'exercises the removed branch of the conditional in ##{method_name}' do
|
|
208
|
+
# Test with inputs that trigger the branch removed by this mutation
|
|
209
|
+
result = subject.#{method_name}(input_value)
|
|
210
|
+
expect(result).to eq(expected)
|
|
211
|
+
end
|
|
212
|
+
RSPEC
|
|
213
|
+
},
|
|
214
|
+
"statement_deletion" => lambda { |mutation|
|
|
215
|
+
method_name = parse_method_name(mutation.subject.name)
|
|
216
|
+
original_line, _mutated_line = extract_diff_lines(mutation.diff)
|
|
217
|
+
<<~RSPEC.strip
|
|
218
|
+
# Mutation: deleted `#{original_line}` in #{mutation.subject.name}
|
|
219
|
+
# #{mutation.file_path}:#{mutation.line}
|
|
220
|
+
it 'depends on the side effect of the deleted statement in ##{method_name}' do
|
|
221
|
+
# Assert a side effect or return value that changes when this statement is removed
|
|
222
|
+
subject.#{method_name}(input_value)
|
|
223
|
+
expect(observable_side_effect).to eq(expected)
|
|
224
|
+
end
|
|
225
|
+
RSPEC
|
|
226
|
+
},
|
|
227
|
+
"method_body_replacement" => lambda { |mutation|
|
|
228
|
+
method_name = parse_method_name(mutation.subject.name)
|
|
229
|
+
original_line, mutated_line = extract_diff_lines(mutation.diff)
|
|
230
|
+
<<~RSPEC.strip
|
|
231
|
+
# Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
|
|
232
|
+
# #{mutation.file_path}:#{mutation.line}
|
|
233
|
+
it 'verifies the return value or side effects of ##{method_name}' do
|
|
234
|
+
# Assert the method produces a meaningful result, not just nil
|
|
235
|
+
result = subject.#{method_name}(input_value)
|
|
236
|
+
expect(result).to eq(expected)
|
|
237
|
+
end
|
|
238
|
+
RSPEC
|
|
239
|
+
},
|
|
240
|
+
"return_value_removal" => lambda { |mutation|
|
|
241
|
+
method_name = parse_method_name(mutation.subject.name)
|
|
242
|
+
original_line, mutated_line = extract_diff_lines(mutation.diff)
|
|
243
|
+
<<~RSPEC.strip
|
|
244
|
+
# Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
|
|
245
|
+
# #{mutation.file_path}:#{mutation.line}
|
|
246
|
+
it 'uses the return value of ##{method_name}' do
|
|
247
|
+
# Assert the caller depends on the return value, not just side effects
|
|
248
|
+
result = subject.#{method_name}(input_value)
|
|
249
|
+
expect(result).to eq(expected)
|
|
250
|
+
end
|
|
251
|
+
RSPEC
|
|
252
|
+
},
|
|
253
|
+
"method_call_removal" => lambda { |mutation|
|
|
254
|
+
method_name = parse_method_name(mutation.subject.name)
|
|
255
|
+
original_line, mutated_line = extract_diff_lines(mutation.diff)
|
|
256
|
+
<<~RSPEC.strip
|
|
257
|
+
# Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
|
|
258
|
+
# #{mutation.file_path}:#{mutation.line}
|
|
259
|
+
it 'depends on the return value or side effect of the call in ##{method_name}' do
|
|
260
|
+
# Assert the method call's effect is observable
|
|
261
|
+
result = subject.#{method_name}(input_value)
|
|
262
|
+
expect(result).to eq(expected)
|
|
263
|
+
end
|
|
264
|
+
RSPEC
|
|
265
|
+
},
|
|
266
|
+
"compound_assignment" => lambda { |mutation|
|
|
267
|
+
method_name = parse_method_name(mutation.subject.name)
|
|
268
|
+
original_line, mutated_line = extract_diff_lines(mutation.diff)
|
|
269
|
+
<<~RSPEC.strip
|
|
270
|
+
# Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
|
|
271
|
+
# #{mutation.file_path}:#{mutation.line}
|
|
272
|
+
it 'verifies the compound assignment side effect in ##{method_name}' do
|
|
273
|
+
# Assert the accumulated value after the compound assignment
|
|
274
|
+
# The mutation changes the operator, so the final value will differ
|
|
275
|
+
subject.#{method_name}(input_value)
|
|
276
|
+
expect(observable_side_effect).to eq(expected)
|
|
277
|
+
end
|
|
278
|
+
RSPEC
|
|
279
|
+
},
|
|
280
|
+
"nil_replacement" => lambda { |mutation|
|
|
281
|
+
method_name = parse_method_name(mutation.subject.name)
|
|
282
|
+
original_line, mutated_line = extract_diff_lines(mutation.diff)
|
|
283
|
+
<<~RSPEC.strip
|
|
284
|
+
# Mutation: changed `#{original_line}` to `#{mutated_line}` in #{mutation.subject.name}
|
|
285
|
+
# #{mutation.file_path}:#{mutation.line}
|
|
286
|
+
it 'asserts the nil return value from ##{method_name}' do
|
|
287
|
+
# Assert the method returns nil, not a substituted value
|
|
288
|
+
result = subject.#{method_name}(input_value)
|
|
289
|
+
expect(result).to be_nil
|
|
290
|
+
end
|
|
291
|
+
RSPEC
|
|
292
|
+
}
|
|
27
293
|
}.freeze
|
|
28
294
|
|
|
29
295
|
DEFAULT_SUGGESTION = "Add a more specific test that detects this mutation"
|
|
30
296
|
|
|
297
|
+
def initialize(suggest_tests: false)
|
|
298
|
+
@suggest_tests = suggest_tests
|
|
299
|
+
end
|
|
300
|
+
|
|
31
301
|
# Generate suggestions for survived mutations.
|
|
32
302
|
#
|
|
33
303
|
# @param summary [Result::Summary]
|
|
@@ -46,8 +316,26 @@ module Evilution
|
|
|
46
316
|
# @param mutation [Mutation]
|
|
47
317
|
# @return [String]
|
|
48
318
|
def suggestion_for(mutation)
|
|
319
|
+
if @suggest_tests
|
|
320
|
+
concrete = CONCRETE_TEMPLATES[mutation.operator_name]
|
|
321
|
+
return concrete.call(mutation) if concrete
|
|
322
|
+
end
|
|
323
|
+
|
|
49
324
|
TEMPLATES.fetch(mutation.operator_name, DEFAULT_SUGGESTION)
|
|
50
325
|
end
|
|
326
|
+
|
|
327
|
+
class << self
|
|
328
|
+
def parse_method_name(subject_name)
|
|
329
|
+
subject_name.split(/[#.]/).last
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
def extract_diff_lines(diff)
|
|
333
|
+
lines = diff.split("\n")
|
|
334
|
+
original = lines.find { |l| l.start_with?("- ") }
|
|
335
|
+
mutated = lines.find { |l| l.start_with?("+ ") }
|
|
336
|
+
[original&.sub(/^- /, "")&.strip, mutated&.sub(/^\+ /, "")&.strip]
|
|
337
|
+
end
|
|
338
|
+
end
|
|
51
339
|
end
|
|
52
340
|
end
|
|
53
341
|
end
|
data/lib/evilution/version.rb
CHANGED
data/lib/evilution.rb
CHANGED
|
@@ -35,6 +35,7 @@ require_relative "evilution/mutator/operator/regexp_mutation"
|
|
|
35
35
|
require_relative "evilution/mutator/operator/receiver_replacement"
|
|
36
36
|
require_relative "evilution/mutator/operator/send_mutation"
|
|
37
37
|
require_relative "evilution/mutator/operator/argument_nil_substitution"
|
|
38
|
+
require_relative "evilution/mutator/operator/compound_assignment"
|
|
38
39
|
require_relative "evilution/mutator/registry"
|
|
39
40
|
require_relative "evilution/equivalent/detector"
|
|
40
41
|
require_relative "evilution/isolation/fork"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: evilution
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.13.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Denis Kiselev
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-03-
|
|
11
|
+
date: 2026-03-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: diff-lcs
|
|
@@ -109,6 +109,7 @@ files:
|
|
|
109
109
|
- lib/evilution/mutator/operator/boolean_operator_replacement.rb
|
|
110
110
|
- lib/evilution/mutator/operator/collection_replacement.rb
|
|
111
111
|
- lib/evilution/mutator/operator/comparison_replacement.rb
|
|
112
|
+
- lib/evilution/mutator/operator/compound_assignment.rb
|
|
112
113
|
- lib/evilution/mutator/operator/conditional_branch.rb
|
|
113
114
|
- lib/evilution/mutator/operator/conditional_flip.rb
|
|
114
115
|
- lib/evilution/mutator/operator/conditional_negation.rb
|