Apply the mutations
This commit is contained in:
parent
c6996d5bbf
commit
c93f87d282
1 changed files with 38 additions and 2 deletions
|
|
@ -19,6 +19,25 @@ let ensureCleanWorkingDirectory () =
|
||||||
eprintfn "Uncommitted changes. Refusing to run."
|
eprintfn "Uncommitted changes. Refusing to run."
|
||||||
exit 2
|
exit 2
|
||||||
|
|
||||||
|
let applyPatch patch =
|
||||||
|
cli {
|
||||||
|
Exec "git"
|
||||||
|
Arguments [ "apply"; "-" ]
|
||||||
|
Input patch
|
||||||
|
}
|
||||||
|
|> Command.execute
|
||||||
|
|> Output.throwIfErrored
|
||||||
|
|> ignore
|
||||||
|
|
||||||
|
let restore () =
|
||||||
|
cli {
|
||||||
|
Exec "git"
|
||||||
|
Arguments [ "restore"; "--staged"; "--worktree"; "." ]
|
||||||
|
}
|
||||||
|
|> Command.execute
|
||||||
|
|> Output.throwIfErrored
|
||||||
|
|> ignore
|
||||||
|
|
||||||
let ensureBuilt projectPath =
|
let ensureBuilt projectPath =
|
||||||
cli {
|
cli {
|
||||||
Exec "dotnet"
|
Exec "dotnet"
|
||||||
|
|
@ -51,6 +70,19 @@ let getMetadataLoadContext (assemblyPath: string) =
|
||||||
|
|
||||||
new MetadataLoadContext(pathAssemblyResolver, typeof<obj>.Assembly.GetName().Name)
|
new MetadataLoadContext(pathAssemblyResolver, typeof<obj>.Assembly.GetName().Name)
|
||||||
|
|
||||||
|
let unindented (s: string) =
|
||||||
|
let lines = s.Split([| "\r\n"; "\n" |], StringSplitOptions.None)
|
||||||
|
|
||||||
|
let indexOfFirstNonEmptyLine =
|
||||||
|
lines |> Array.findIndex (not << String.IsNullOrWhiteSpace)
|
||||||
|
|
||||||
|
let identantionOfFirstNonEmptyLine =
|
||||||
|
lines[indexOfFirstNonEmptyLine] |> Seq.takeWhile Char.IsWhiteSpace |> Seq.length
|
||||||
|
|
||||||
|
lines[indexOfFirstNonEmptyLine..]
|
||||||
|
|> Seq.map (fun line -> line.Substring(min identantionOfFirstNonEmptyLine line.Length))
|
||||||
|
|> String.concat Environment.NewLine
|
||||||
|
|
||||||
let getMutationCases projectPath =
|
let getMutationCases projectPath =
|
||||||
ensureBuilt projectPath
|
ensureBuilt projectPath
|
||||||
|
|
||||||
|
|
@ -73,7 +105,7 @@ let getMutationCases projectPath =
|
||||||
| "Mutannot.MutationCaseAttribute" ->
|
| "Mutannot.MutationCaseAttribute" ->
|
||||||
Some
|
Some
|
||||||
{ TestName = $"{m.DeclaringType.FullName}.{m.Name}"
|
{ TestName = $"{m.DeclaringType.FullName}.{m.Name}"
|
||||||
Patch = attr.ConstructorArguments[0].Value :?> string }
|
Patch = attr.ConstructorArguments[0].Value :?> string |> unindented }
|
||||||
| _ -> None))
|
| _ -> None))
|
||||||
|> Seq.toList
|
|> Seq.toList
|
||||||
|
|
||||||
|
|
@ -85,9 +117,13 @@ let main argv =
|
||||||
|
|
||||||
ensureCleanWorkingDirectory ()
|
ensureCleanWorkingDirectory ()
|
||||||
|
|
||||||
|
AppDomain.CurrentDomain.ProcessExit.Add(fun _ -> restore ())
|
||||||
|
|
||||||
let projectPath = argv[0]
|
let projectPath = argv[0]
|
||||||
|
|
||||||
for mutationCase in getMutationCases projectPath do
|
for mutationCase in getMutationCases projectPath do
|
||||||
printfn "%s" <| mutationCase.ToString()
|
printfn "MUTATION\n\n%s" <| mutationCase.Patch
|
||||||
|
applyPatch mutationCase.Patch
|
||||||
|
restore ()
|
||||||
|
|
||||||
0
|
0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue