Make mutations patch-based

This commit is contained in:
Sven van Heugten 2026-05-12 08:07:43 +02:00
parent 10ddbef963
commit 2dc2c288fb
No known key found for this signature in database
GPG key ID: D612F88666F4F660
3 changed files with 21 additions and 20 deletions

View file

@ -6,17 +6,22 @@ open Xunit
type CalculatorTests() =
[<Fact>]
[<MutationCase("calc-add-one", "Example.Tests/Calculator.fs", 4, "value + 1", "value - 1")>]
member _.AddOne_increments() =
Assert.Equal(42, Calculator.addOne 41)
[<MutationCase("""
diff --git a/Example.Tests/Calculator.fs b/Example.Tests/Calculator.fs
index cfcce3b..39be7f3 100644
--- a/Example.Tests/Calculator.fs
+++ b/Example.Tests/Calculator.fs
@@ -1,7 +1,7 @@
namespace Example
[<Fact>]
[<MutationCase("calc-abs-diff-branch", "Example.Tests/Calculator.fs", 7, "left - right", "right - left")>]
member _.AbsoluteDifference_preserves_order() =
Assert.Equal(7, Calculator.absoluteDifference 10 3)
module Calculator =
- let addOne value = value + 1
+ let addOne value = value - 1
[<Fact>]
[<MutationCase("calc-leap-year-century", "Example.Tests/Calculator.fs", 10, "year % 100 <> 0", "year % 100 = 0")>]
member _.LeapYear_handles_centuries() =
Assert.True(Calculator.isLeapYear 2000)
Assert.False(Calculator.isLeapYear 1900)
let absoluteDifference left right =
if left >= right then left - right else right - left
member _.AddOne_increments() =
Assert.Equal(42, Calculator.addOne 41)
""")>]
member _.AddOne_increments() = Assert.Equal(42, Calculator.addOne 41)

View file

@ -3,11 +3,7 @@ namespace Mutannot
open System
[<AttributeUsage(AttributeTargets.Method, AllowMultiple = true)>]
type MutationCaseAttribute(id: string, file: string, line: int, find: string, replace: string) =
type MutationCaseAttribute(patch: string) =
inherit Attribute()
member _.Id = id
member _.File = file
member _.Line = line
member _.Find = find
member _.Replace = replace
member _.Patch = patch

View file

@ -4,7 +4,7 @@ open System.Reflection
open System.Runtime.InteropServices
open Fli
type MutationCase = { TestName: string; Id: string }
type MutationCase = { TestName: string; Patch: string }
let ensureBuilt projectPath =
cli {
@ -60,7 +60,7 @@ let getMutationCases projectPath =
| "Mutannot.MutationCaseAttribute" ->
Some
{ TestName = $"{m.DeclaringType.FullName}.{m.Name}"
Id = attr.ConstructorArguments[0].Value :?> string }
Patch = attr.ConstructorArguments[0].Value :?> string }
| _ -> None))
|> Seq.toList