Skip to content

Commit

Permalink
Merge branch 'master' into release/Habu
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveGilham committed May 16, 2024
2 parents 0deb424 + e4b1779 commit dad881f
Show file tree
Hide file tree
Showing 24 changed files with 1,199 additions and 417 deletions.
3 changes: 2 additions & 1 deletion .fantomasignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Ignore interfaces (documentation annotations)
*.fsi
Abstract.fs
Abstract.fs
Recorder.fs
19 changes: 10 additions & 9 deletions AltCover.Engine/CecilEx.fs
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,22 @@ type internal AssemblyResolver() as self =

let sources =
[ AssemblyConstants.packageEnv
[ Environment.GetEnvironmentVariable "ProgramFiles"
|> Option.ofObj
|> Option.map (fun p -> Path.Combine(p, dotnetShared))
Some <| Path.Combine(share, dotnetShared)
Some <| Path.Combine(shareLocal, dotnetShared)
AssemblyConstants.dotnetDir
|> Option.map (fun p -> Path.Combine(p, "shared"))
Some AssemblyConstants.nugetCache
[ Some AssemblyConstants.nugetCache
Some <| Path.Combine("usr", monogac)
Environment.GetEnvironmentVariable "WinDir"
|> Option.ofObj
|> Option.map (fun p -> Path.Combine(p, wingac))
Some <| Path.Combine("usr", monogac)
Environment.GetEnvironmentVariable "MONO_GAC_PREFIX"
|> Option.ofObj
|> Option.map (fun p -> Path.Combine(p, monogac)) ]
|> Option.map (fun p -> Path.Combine(p, monogac))
Environment.GetEnvironmentVariable "ProgramFiles"
|> Option.ofObj
|> Option.map (fun p -> Path.Combine(p, dotnetShared))
Some <| Path.Combine(share, dotnetShared)
Some <| Path.Combine(shareLocal, dotnetShared)
AssemblyConstants.dotnetDir
|> Option.map (fun p -> Path.Combine(p, "shared")) ]
|> List.choose id ]
|> List.concat
|> List.filter Directory.Exists
Expand Down
18 changes: 12 additions & 6 deletions AltCover.Engine/CommandLine.fs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ module internal Zip =
[<SuppressMessage("Microsoft.Reliability",
"CA2000:Dispose objects before losing scope",
Justification = "ditto, ditto.")>]
let internal openUpdate (report: string) =
if File.Exists(report + ".zip") then
let internal openUpdate (report: string) (zipped: bool) =
if zipped then
let zip =
ZipFile.Open(report + ".zip", ZipArchiveMode.Update)

Expand All @@ -85,7 +85,7 @@ module internal Zip =
new MemoryStream() :> Stream

(zip, stream)
else if File.Exists report then
else
let stream =
new FileStream(
report,
Expand All @@ -97,8 +97,14 @@ module internal Zip =
)

(null, stream :> Stream)
else
(null, new MemoryStream() :> Stream)

let internal openUpdateReport format (report: string) (zipped: bool) =
let container, stream =
openUpdate report zipped

use _ = container
use _ = stream
DocumentType.LoadReportStream format stream

type internal StringSink = Action<String>

Expand Down Expand Up @@ -496,6 +502,6 @@ module internal CommandLine =
"InstantiateArgumentExceptionCorrectlyRule",
Scope = "member", // MethodDefinition
Target =
"AltCover.CommandLine/I/transform@288::Invoke(System.String[])",
"AltCover.CommandLine/I/transform@294::Invoke(System.String[])",
Justification = "Inlined library code")>]
()
7 changes: 4 additions & 3 deletions AltCover.Engine/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -703,10 +703,11 @@ module internal Main =
|> Option.defaultValue false

let internal selectReportGenerator () =
match CoverageParameters.reportKind () with
| ReportFormat.OpenCoverWithTracking
match
CoverageParameters.reportKind ()
&&& ReportFormat.TrackMask
with
| ReportFormat.OpenCover -> OpenCover.reportGenerator ()
| ReportFormat.NativeJsonWithTracking
| ReportFormat.NativeJson -> NativeJson.reportGenerator ()
| _ -> Report.reportGenerator ()

Expand Down
33 changes: 24 additions & 9 deletions AltCover.Engine/NativeJson.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1235,10 +1235,15 @@ module
x
#endif

let internal fileToJson filename =
#if GUI
let fileToJson filename =
filename |> File.ReadAllText |> fromJsonText

#else // RUNNER
let internal streamToJson (stream: Stream) =
use r = new StreamReader(stream)
r.ReadToEnd() |> fromJsonText
#endif
#endif // GUI || RUNNER

#if RUNNER
// Instrumentation ---------------------------------------------------------
Expand Down Expand Up @@ -1421,17 +1426,27 @@ type internal DocumentType =
| XML of XDocument
| JSON of NativeJson.Modules
| Unknown
static member internal LoadReport format report =
if File.Exists report then
if
format = ReportFormat.NativeJson
|| format = ReportFormat.NativeJsonWithTracking
then
report |> NativeJson.fileToJson |> JSON
//static member internal LoadReport format report =
// if File.Exists report then
// if
// format = ReportFormat.NativeJson
// || format = ReportFormat.NativeJsonWithTracking
// then
// report |> NativeJson.fileToJson |> JSON
// else
// report |> XDocument.Load |> XML
// else
// Unknown

static member internal LoadReportStream format (report: Stream) =
if report.Length > 0 then
if format &&& ReportFormat.TrackMask = ReportFormat.NativeJson then
report |> NativeJson.streamToJson |> JSON
else
report |> XDocument.Load |> XML
else
Unknown

#endif

#if GUI || RUNNER
Expand Down
5 changes: 2 additions & 3 deletions AltCover.Engine/PostProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,7 @@ module internal PostProcess =
format
(document: XmlAbstraction)
=
match format with
| ReportFormat.OpenCoverWithTracking
match format &&& ReportFormat.TrackMask with
| ReportFormat.OpenCover ->
if counts.ContainsKey Track.Entry then
fillTrackedVisits document counts.[Track.Entry] "entry"
Expand Down Expand Up @@ -514,6 +513,6 @@ module internal PostProcess =
"PreferStringComparisonOverrideRule",
Scope = "member",
Target =
"AltCover.PostProcess/Pipe #2 stage #1 at line 331@332-1::Invoke(AltCover.XmlElementAbstraction)",
"AltCover.PostProcess/Pipe #2 stage #1 at line 330@331-1::Invoke(AltCover.XmlElementAbstraction)",
Justification = "Compiler generated")>]
()
63 changes: 35 additions & 28 deletions AltCover.Engine/Runner.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1328,11 +1328,13 @@ module internal Runner =
Justification = "meets an interface")>]
let writeNativeJsonReport
(hits: Dictionary<string, Dictionary<int, PointVisit>>)
unusedCannotBeUnderscore
format
(file: Stream)
output
=
ignore unusedCannotBeUnderscore
let zipped =
int (format &&& ReportFormat.Zipped) <> 0

let flushStart = DateTime.UtcNow
// do work here
let jsonText =
Expand All @@ -1357,17 +1359,8 @@ module internal Runner =
NativeJson.serializeToUtf8Bytes json

if Option.isSome output then
use outputFile =
new FileStream(
output.Value,
FileMode.OpenOrCreate,
FileAccess.Write,
FileShare.None,
4096,
FileOptions.SequentialScan
)

outputFile.Write(encoded, 0, encoded.Length)
Zip.save (fun s -> s.Write(encoded, 0, encoded.Length)) output.Value zipped

else
file.Seek(0L, SeekOrigin.Begin) |> ignore
file.SetLength 0L
Expand All @@ -1381,29 +1374,40 @@ module internal Runner =
report
=
let reporter (arg: string option) =
let zipped =
int (format &&& ReportFormat.Zipped) <> 0

let (container, file) =
Zip.openUpdate report

try
if
format = ReportFormat.NativeJson
|| format = ReportFormat.NativeJsonWithTracking
then
writeNativeJsonReport hits format file arg
else
Zip.openUpdate report zipped

use container' = container
use file' = file

if format &&& ReportFormat.TrackMask = ReportFormat.NativeJson then
writeNativeJsonReport hits format file arg
else
use outputFile =
match arg with
| None -> file
| _ -> new MemoryStream() :> Stream

let result =
AltCover.Counter.doFlushStream
(postProcess hits format)
pointProcess
true
hits
format
file
arg
finally
file.Dispose()
outputFile

if container.IsNotNull then
container.Dispose()
match arg with
| None -> ()
| Some x ->
outputFile.Position <- 0l
Zip.save (outputFile.CopyTo) x zipped

result

reporter

Expand Down Expand Up @@ -1513,8 +1517,11 @@ module internal Runner =
)
|> Seq.iter File.Delete

let zipped =
int (format &&& ReportFormat.Zipped) <> 0

let document =
DocumentType.LoadReport format report
Zip.openUpdateReport format (Option.defaultValue report output) zipped

J.doSummaries document format result)
255
Expand Down
32 changes: 20 additions & 12 deletions AltCover.Engine/Visitor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -412,27 +412,35 @@ module internal CoverageParameters =
else
path

let internal reportFormat () =
let internal reportFormat0 () =
let fmt = reportKind ()

if
fmt = ReportFormat.OpenCover
&& (trackingNames.Any() || interval () > 0)
then
ReportFormat.OpenCoverWithTracking
ReportFormat.OpenCover
||| ReportFormat.WithTracking
else if
fmt = ReportFormat.NativeJson
&& (trackingNames.Any() || interval () > 0)
then
ReportFormat.NativeJsonWithTracking
ReportFormat.NativeJson
||| ReportFormat.WithTracking
else
fmt

let internal reportFormat () =
let raw = reportFormat0 ()

if zipReport.Value then
raw ||| ReportFormat.Zipped
else
raw

let internal isTracking () =
match reportFormat () with
| ReportFormat.OpenCoverWithTracking
| ReportFormat.NativeJsonWithTracking -> true
| _ -> false
int (reportFormat () &&& ReportFormat.WithTracking)
<> 0

let withBranches () = reportFormat () <> ReportFormat.NCover

Expand Down Expand Up @@ -1674,30 +1682,30 @@ module internal Visitor =
"AvoidMessageChainsRule",
Scope = "member",
Target =
"AltCover.Visitor/I/generated@1403::Invoke(Mono.Cecil.Cil.Instruction)",
"AltCover.Visitor/I/generated@1411::Invoke(Mono.Cecil.Cil.Instruction)",
Justification = "No direct call available")>]
[<assembly: SuppressMessage("Gendarme.Rules.Exceptions",
"InstantiateArgumentExceptionCorrectlyRule",
Scope = "member", // MethodDefinition
Target =
"AltCover.Visitor/I/start@1249::Invoke(Microsoft.FSharp.Core.FSharpFunc`2<Mono.Cecil.Cil.Instruction,System.Int32>,Microsoft.FSharp.Collections.FSharpList`1<Mono.Cecil.Cil.Instruction>)",
"AltCover.Visitor/I/start@1257::Invoke(Microsoft.FSharp.Core.FSharpFunc`2<Mono.Cecil.Cil.Instruction,System.Int32>,Microsoft.FSharp.Collections.FSharpList`1<Mono.Cecil.Cil.Instruction>)",
Justification = "Inlined library code")>]
[<assembly: SuppressMessage("Gendarme.Rules.Exceptions",
"InstantiateArgumentExceptionCorrectlyRule",
Scope = "member", // MethodDefinition
Target =
"AltCover.Visitor/I/finish@1252::Invoke(Microsoft.FSharp.Core.FSharpFunc`2<Mono.Cecil.Cil.Instruction,System.Int32>,Microsoft.FSharp.Collections.FSharpList`1<Mono.Cecil.Cil.Instruction>)",
"AltCover.Visitor/I/finish@1260::Invoke(Microsoft.FSharp.Core.FSharpFunc`2<Mono.Cecil.Cil.Instruction,System.Int32>,Microsoft.FSharp.Collections.FSharpList`1<Mono.Cecil.Cil.Instruction>)",
Justification = "Inlined library code")>]
[<assembly: SuppressMessage("Gendarme.Rules.Naming",
"UseCorrectCasingRule",
Scope = "member", // MethodDefinition
Target =
"AltCover.Visitor/I/sp@1560-2::Invoke(AltCover.SeqPnt)",
"AltCover.Visitor/I/sp@1568-2::Invoke(AltCover.SeqPnt)",
Justification = "Inlined library code")>]
[<assembly: SuppressMessage("Gendarme.Rules.Naming",
"UseCorrectCasingRule",
Scope = "member", // MethodDefinition
Target =
"AltCover.Visitor/I/Pipe #2 stage #10 at line 1463@1463::Invoke(AltCover.GoTo)",
"AltCover.Visitor/I/Pipe #2 stage #10 at line 1471@1471::Invoke(AltCover.GoTo)",
Justification = "Inlined library code")>]
()
Loading

0 comments on commit dad881f

Please sign in to comment.