Compare commits

...

2 commits

View file

@ -224,6 +224,26 @@ let tempRoot = Path.Combine(Path.GetTempPath(), $"fscheck-mutants.{Guid.NewGuid(
let worktreePath = Path.Combine(tempRoot, "worktree") let worktreePath = Path.Combine(tempRoot, "worktree")
let patchPath = Path.Combine(tempRoot, "current.patch") let patchPath = Path.Combine(tempRoot, "current.patch")
let splitNullSeparated (text: string) =
text.Split('\000', StringSplitOptions.RemoveEmptyEntries)
|> Array.toList
let repoRelativePath (path: string) =
path.Replace('/', Path.DirectorySeparatorChar)
let listUntrackedFiles () =
let exitCode, stdout, stderr = captureProcess repoRoot "git" [ "ls-files"; "--others"; "--exclude-standard"; "-z" ]
if exitCode <> 0 then fail stderr
splitNullSeparated stdout
let copyFileIntoWorktree (relativePath: string) =
let sourcePath = Path.Combine(repoRoot, repoRelativePath relativePath)
let destinationPath = Path.Combine(worktreePath, repoRelativePath relativePath)
let destinationDir = Path.GetDirectoryName destinationPath
if not (String.IsNullOrEmpty destinationDir) then
Directory.CreateDirectory(destinationDir) |> ignore
File.Copy(sourcePath, destinationPath, true)
let cleanup () = let cleanup () =
if Directory.Exists worktreePath then if Directory.Exists worktreePath then
let _ = captureProcess repoRoot "git" [ "worktree"; "remove"; "--force"; worktreePath ] let _ = captureProcess repoRoot "git" [ "worktree"; "remove"; "--force"; worktreePath ]
@ -233,6 +253,7 @@ let cleanup () =
let createWorktree () = let createWorktree () =
Directory.CreateDirectory(tempRoot) |> ignore Directory.CreateDirectory(tempRoot) |> ignore
let untrackedFiles = listUntrackedFiles ()
let exitCode, diffText, stderr = captureProcess repoRoot "git" [ "diff"; "--binary"; "HEAD" ] let exitCode, diffText, stderr = captureProcess repoRoot "git" [ "diff"; "--binary"; "HEAD" ]
if exitCode <> 0 then fail stderr if exitCode <> 0 then fail stderr
File.WriteAllText(patchPath, diffText) File.WriteAllText(patchPath, diffText)
@ -248,7 +269,14 @@ let createWorktree () =
let exitCode4, _, stderr4 = captureProcess worktreePath "git" [ "apply"; patchPath ] let exitCode4, _, stderr4 = captureProcess worktreePath "git" [ "apply"; patchPath ]
if exitCode4 <> 0 then fail stderr4 if exitCode4 <> 0 then fail stderr4
let testFilter mutation = $"FullyQualifiedName~{mutation.TestName}" for relativePath in untrackedFiles do
copyFileIntoWorktree relativePath
let fullyQualifiedTestName mutation =
let declaringType = mutation.DeclaringType.Replace('+', '.')
$"{declaringType}.{mutation.TestName}"
let testFilter mutation = $"FullyQualifiedName={fullyQualifiedTestName mutation}"
let runMutation (mutation: MutationCase) = let runMutation (mutation: MutationCase) =
let targetFile = Path.Combine(worktreePath, mutation.File.Replace('/', Path.DirectorySeparatorChar)) let targetFile = Path.Combine(worktreePath, mutation.File.Replace('/', Path.DirectorySeparatorChar))