Skip to content

Commit 4a3816b

Browse files
committed
Drop mutants that contain no source changes
1 parent dd1ee7b commit 4a3816b

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

Sources/CoreMutation/Mutation.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ extension Mutation {
3333
replacement: $0.mutate()
3434
)
3535
}
36+
.drop { $0.replacement == file.code }
3637
.uniqued(on: \.replacement)
3738

3839
return Array(mutants)

Tests/CoreMutationTests/MutationTests.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ struct MutationTests {
1616
#expect(mutants.isEmpty)
1717
}
1818

19-
@Test("no change")
20-
func noChange() throws {
19+
@Test("change")
20+
func change() throws {
2121

2222
let mutation = Mutation(name: "test") { file in
2323
[Mutation.Change(start: .start, end: .end) { "replacement" }]
@@ -34,6 +34,18 @@ struct MutationTests {
3434
#expect(mutants[0].original == "original")
3535
#expect(mutants[0].replacement == "replacement")
3636
}
37+
38+
@Test("no changes")
39+
func noChanges() throws {
40+
41+
let mutation = Mutation(name: "test") { file in
42+
[Mutation.Change(start: .start, end: .end) { file.code }]
43+
}
44+
45+
let file = Source.File(name: "name", path: "path", code: "original")
46+
let mutants = mutation.mutants(for: file)
47+
#expect(mutants.isEmpty)
48+
}
3749
}
3850

3951
@Suite("Name")

Tests/SyntaxMutationTests/SyntaxMutationTests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,24 @@ struct SyntaxMutationTests {
7070
let name = "Daniel"
7171
""")
7272
}
73+
74+
@Test("non changes are not counted")
75+
func nonChanges() {
76+
77+
final class Visitor: MutationVisitor {
78+
79+
override func visit(_ node: CodeBlockItemListSyntax) -> SyntaxVisitorContinueKind {
80+
record(before: node, after: node)
81+
return super.visit(node)
82+
}
83+
}
84+
85+
let mutation = Mutation(name: "Replace File", visitor: Visitor.self)
86+
let file = Source.File(name: "name", path: "path", code: """
87+
let name = "Daniel"
88+
""")
89+
90+
let mutants = mutation.mutants(for: file)
91+
#expect(mutants.isEmpty)
92+
}
7393
}

0 commit comments

Comments
 (0)