Skip to content

Commit

Permalink
Mitigate exception messages from tidying the recorder assembly
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveGilham committed Apr 7, 2024
1 parent 8f9ffe5 commit 77c8001
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
2 changes: 2 additions & 0 deletions AltCover.Engine/Runner.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,8 @@ module internal Runner =
|> J.getFirstOperandAsNumber
|> enum

use _ = fst pair

let hits =
Dictionary<string, Dictionary<int, PointVisit>>()

Expand Down
3 changes: 3 additions & 0 deletions AltCover.Engine/Strings.eo.resx
Original file line number Diff line number Diff line change
Expand Up @@ -471,4 +471,7 @@ Se la opcio ne ĉeestas, tiam la defaŭlta estas 'OC'.</value>
<data name="portable" xml:space="preserve">
<value>Laŭvola: porteblaj operacioj - priraporta raporto, kontroldosiero kaj registritaj datumoj samlokaj kun la registrilo.</value>
</data>
<data name="FailedToDelete" xml:space="preserve">
<value>Malsukcesis forigi dosieron {0}</value>
</data>
</root>
3 changes: 3 additions & 0 deletions AltCover.Engine/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,7 @@ If the option is not present, then the default is 'OC'.</value>
<data name="portable" xml:space="preserve">
<value>Optional: portable operations - coverage report, control file and recorded data co-located with the recorder assembly</value>
</data>
<data name="FailedToDelete" xml:space="preserve">
<value>Failed to delete file {0}</value>
</data>
</root>
13 changes: 10 additions & 3 deletions AltCover.Engine/Tasks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,20 @@ type RetryDelete() =
Justification = "MSBuild tasks use arrays")>]
member val Files: string array = [||] with get, set

member internal self.Write message =
``base``.Log.LogMessage(MessageImportance.High, message)
[<SuppressMessage("Gendarme.Rules.Performance",
"AvoidUnusedParametersRule",
Justification = "Replace the raw exception dump")>]
member internal self.Write0 (o: string->unit) (f:string) (_:string) : unit =
CommandLine.Format.Local("FailedToDelete", f)
|> o

member internal self.Write (f:string) (dummy:string) : unit =
self.Write0 (``base``.Log.LogWarning) f dummy

override self.Execute() =
if self.Files.IsNotNull then
self.Files
|> Seq.filter File.Exists
|> Seq.iter (CommandLine.I.doRetry File.Delete self.Write 10 1000 0)
|> Seq.iter (fun f -> (CommandLine.I.doRetry File.Delete (self.Write f) 100 100 0 f))

true
11 changes: 10 additions & 1 deletion AltCover.Tests/Tests3.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4899,14 +4899,23 @@ module AltCoverTests3 =
monitor ("Hello")
test <@ builder.ToString() = "Hello" @>

let write0 =
subject
.GetType()
.GetMethod("Write0", BindingFlags.NonPublic ||| BindingFlags.Instance)

let mutable written = "written"
write0.Invoke(subject, [| (fun x -> written <- x); "xx"; "yy" |]) |> ignore
test <@ written = "Failed to delete file xx" @>

let write =
subject
.GetType()
.GetMethod("Write", BindingFlags.NonPublic ||| BindingFlags.Instance)

let ex =
Assert.Throws<TargetInvocationException>(fun () ->
write.Invoke(subject, [| "xx" |]) |> ignore)
write.Invoke(subject, [| "xx"; "yy" |]) |> ignore)

test <@ ex.InnerException.GetType().FullName = "System.InvalidOperationException" @>
// Recorder.fs => Recorder.Tests

0 comments on commit 77c8001

Please sign in to comment.