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 Jun 6, 2023
2 parents a51f588 + 41bcaec commit 32b29a4
Show file tree
Hide file tree
Showing 22 changed files with 145 additions and 252 deletions.
4 changes: 2 additions & 2 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"dotnet-reportgenerator-globaltool": {
"version": "5.1.18",
"version": "5.1.21",
"commands": [
"reportgenerator"
]
Expand Down Expand Up @@ -33,7 +33,7 @@
]
},
"nbgv": {
"version": "3.5.119",
"version": "3.6.133",
"commands": [
"nbgv"
]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.202'
dotnet-version: '7.0.302'
- name: Tools
run: dotnet tool restore
- name: Setup
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.202'
dotnet-version: '7.0.302'
- name: Tools
run: dotnet tool restore
- name: Setup
Expand Down
6 changes: 3 additions & 3 deletions AltCover.Api.Tests/FSApiTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1283,9 +1283,9 @@ module FSApiTests =
let combined2 =
DotNet.CLIOptions.Many [ a2; force; fail; summary ]

test <@ combined.ForceDelete @>
test <@ combined.FailFast @>
test <@ combined.ShowSummary = "R" @>
test <@ combined2.ForceDelete @>
test <@ combined2.FailFast @>
test <@ combined2.ShowSummary = "R" @>

test
<@
Expand Down
135 changes: 0 additions & 135 deletions AltCover.Engine/CecilEx.fs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ type internal AssemblyResolver() as self =
"dotnet|shared"
.Replace('|', Path.DirectorySeparatorChar)


let sources =
[ AssemblyConstants.packageEnv
[ Environment.GetEnvironmentVariable "ProgramFiles"
Expand Down Expand Up @@ -180,140 +179,6 @@ type internal AssemblyResolver() as self =

[<AutoOpen>]
module internal CecilExtension =
let internal scopesSeen =
System.Collections.Generic.HashSet<ScopeDebugInformation>()

let internal safeOffset (point: InstructionOffset) =
if point.IsEndOfMethod then
None
else
Some point.Offset

// workround for old MCS + Cecil 0.11.4
let pruneLocalScopes (m: MethodDefinition) =
scopesSeen.Clear()

let rec pruneScope (scope: ScopeDebugInformation) =
let novel = scopesSeen.Add scope

if novel then
let scopes = scope.Scopes // non-null by construction

scopes
|> Seq.filter (fun subScope ->
let repeat =
subScope
|> Option.ofObj
|> Option.map pruneScope
|> Option.defaultValue true

repeat || subScope.Start.IsEndOfMethod)
|> Seq.toList
|> List.iter (scopes.Remove >> ignore)

not novel

m.DebugInformation.Scope
|> Option.ofObj
|> Option.map pruneScope
|> ignore

// address issue 135
let internal isResolvedProp =
typeof<InstructionOffset>
.GetProperty(
"IsResolved",
System.Reflection.BindingFlags.Instance
||| System.Reflection.BindingFlags.NonPublic
)

let etypeField =
typeof<TypeReference>
.GetField(
"etype",
System.Reflection.BindingFlags.Instance
||| System.Reflection.BindingFlags.NonPublic
)

let internal offsetTable =
System.Collections.Generic.SortedDictionary<int, Instruction>()

let unresolved (point: InstructionOffset) =
isResolvedProp.GetValue(point) :?> bool |> not

let checkScopeConstants (m: MethodDefinition) =
scopesSeen
|> Seq.iter (fun scope ->
let sus =
scope.Constants
|> Seq.filter (fun c ->
(isNull c.Value)
&& match etypeField.GetValue(c.ConstantType) :?> byte with
| 0x14uy // ElementType.Array
| 0x1duy // ElementType.SzArray
| 0x12uy // ElementType.Class
| 0x1cuy // ElementType.Object
| 0x00uy // ElementType.None
| 0x13uy // ElementType.Var
| 0x1euy // ElementType.MVar
| 0x0euy -> // ElementType.String
false
| _ -> not c.ConstantType.IsPrimitive)
|> Seq.toList

sus
|> Seq.iter (fun c ->
scope.Constants.Remove c |> ignore

sprintf "Null Constant %s elided in method %s" c.Name m.FullName
|> Output.verbose))

let prepareLocalScopes (m: MethodDefinition) =
offsetTable.Clear()
scopesSeen.Clear()

let size =
m.Body.Instructions
|> Seq.fold
(fun _ i ->
offsetTable.Add(i.Offset, i)
i.Offset + i.GetSize())
0

let resolvePoint (point: InstructionOffset) =
point
|> safeOffset
|> Option.map (fun offset ->
let o = Math.Max(offset, 0)
let ok, i = offsetTable.TryGetValue(o)

if ok then
InstructionOffset(i)
else
offsetTable.Keys
|> Seq.filter (fun kk -> o < size && kk <= o)
|> Seq.tryLast
|> Option.map (fun k -> InstructionOffset(offsetTable.[k]))
|> Option.defaultValue (InstructionOffset()))
|> Option.defaultValue (InstructionOffset())

let rec resolveScope (scope: ScopeDebugInformation) =
if scope.IsNotNull then
if scopesSeen.Add scope then
scope.Scopes // non-null by construction
|> Seq.iter resolveScope

if unresolved scope.Start then
scope.Start <- resolvePoint scope.Start

if unresolved scope.End then
scope.End <- resolvePoint scope.End

m.DebugInformation.Scope |> resolveScope

checkScopeConstants m

pruneLocalScopes m

// Adjust the IL for exception handling
// param name="handler">The exception handler</param>
Expand Down
17 changes: 9 additions & 8 deletions AltCover.Engine/Filter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -283,30 +283,31 @@ module internal Filter =
|| fullName
== typeof<CompilationMappingAttribute>.FullName)))

[<SuppressMessage("Gendarme.Rules.Globalization",
"PreferStringComparisonOverrideRule",
Justification = "not available in netstandard2.0")>]
let internal isFSharpAutoProperty (m: MethodDefinition) =
let body = m.Body.Instructions
let fullName = m.DeclaringType.FullName
let name = m.Name

if m.IsSetter then
body
|> Seq.tryFind (fun i -> i.OpCode = OpCodes.Stfld)
|> Option.map (fun i ->
let f = i.Operand :?> FieldReference

(f.DeclaringType.FullName
== m.DeclaringType.FullName)
&& m.Name.Replace("set_", String.Empty) + "@"
== f.Name)
(f.DeclaringType.FullName == fullName)
&& name.Replace("set_", String.Empty) + "@" == f.Name)
|> Option.defaultValue false
else if m.IsGetter then
body
|> Seq.tryFind (fun i -> i.OpCode = OpCodes.Ldfld)
|> Option.map (fun i ->
let f = i.Operand :?> FieldReference

(f.DeclaringType.FullName
== m.DeclaringType.FullName)
&& m.Name.Replace("get_", String.Empty) + "@"
== f.Name)
(f.DeclaringType.FullName == fullName)
&& name.Replace("get_", String.Empty) + "@" == f.Name)
|> Option.defaultValue false
else
false
Expand Down
13 changes: 2 additions & 11 deletions AltCover.Engine/Instrument.fs
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,7 @@ module internal Instrument =
let head = initialBody |> Seq.head
worker.InsertBefore(head, value (worker))
worker.InsertBefore(head, worker.Create(OpCodes.Ret))
initialBody |> Seq.iter worker.Remove
pruneLocalScopes pathGetterDef)
initialBody |> Seq.iter worker.Remove)

[ ("get_Timer", // set the timer interval in ticks
CoverageParameters.interval ()) ]
Expand All @@ -385,8 +384,7 @@ module internal Instrument =
worker.InsertBefore(head, worker.Create(OpCodes.Ldc_I4, value))
worker.InsertBefore(head, worker.Create(OpCodes.Conv_I8))
worker.InsertBefore(head, worker.Create(OpCodes.Ret))
initialBody |> Seq.iter worker.Remove
pruneLocalScopes pathGetterDef))
initialBody |> Seq.iter worker.Remove))

[<System.Diagnostics.CodeAnalysis.SuppressMessage("Gendarme.Rules.Correctness",
"EnsureLocalDisposalRule",
Expand Down Expand Up @@ -696,9 +694,6 @@ module internal Instrument =
| true ->
let mt = m.Method

if mt.HasBody then
prepareLocalScopes mt

let body = mt.Body

{ state with
Expand Down Expand Up @@ -1046,8 +1041,6 @@ module internal Instrument =
body.SimplifyMacros()
// changes "long" conditional operators to their short representation where possible
body.OptimizeMacros()
// purge dodgy scope data
state.MethodBody.Method |> pruneLocalScopes

doTrack state m

Expand Down Expand Up @@ -1333,8 +1326,6 @@ module internal Instrument =

bulkInsertBefore worker head store true |> ignore

pruneLocalScopes getterDef

let recorderFileName =
(extractName state.RecordingAssembly) + ".dll"

Expand Down
3 changes: 3 additions & 0 deletions AltCover.Engine/Json.fs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ module internal Json =
else
m0

[<SuppressMessage("Gendarme.Rules.Correctness",
"EnsureLocalDisposalRule",
Justification = "it's a wrapper")>]
let internal maybeAssembly path =
Some path
|> Option.filter File.Exists
Expand Down
2 changes: 1 addition & 1 deletion AltCover.Engine/LCov.fs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ FN:4,(anonymous_0)
vc.ToString(CultureInfo.InvariantCulture)

writer.WriteLine("DA:" + sl + "," + vcs)
(f + 1, h + if vcs == "0" then 0 else 1))
(f + 1, h + (if vcs == "0" then 0 else 1)))
(0, 0)
// At the end of a section, there is a summary about how many lines were
// found and how many were actually instrumented:
Expand Down
4 changes: 2 additions & 2 deletions AltCover.Engine/NativeJson.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ open Manatee.Json

module
#if GUI || RUNNER
internal
internal
#endif
NativeJson =
NativeJson =

type internal TimeStamp = string

Expand Down
12 changes: 9 additions & 3 deletions AltCover.Engine/Runner.fs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ type internal Threshold =

module internal Runner =

let internal defaultSummary =
[ "?"; "?"; "?"; "?"; "?"; "?" ]

let mutable internal recordingDirectory: Option<string> =
None

Expand Down Expand Up @@ -466,6 +469,9 @@ module internal Runner =
[<SuppressMessage("Gendarme.Rules.Maintainability",
"AvoidComplexMethodsRule",
Justification = "TODO: refactor even more")>]
[<SuppressMessage("Microsoft.Maintainability",
"CA1502:AvoidExcessiveComplexity",
Justification = "TODO: refactor even more")>]
let private makeOpenCoverSummary (report: XDocument) (summary: XElement) =

let l =
Expand Down Expand Up @@ -536,7 +542,7 @@ module internal Runner =
report.Root.Elements("Summary".X)
|> Seq.tryHead
|> Option.map (makeOpenCoverSummary report)
|> Option.defaultValue []
|> Option.defaultValue defaultSummary

[<SuppressMessage("Gendarme.Rules.Exceptions",
"InstantiateArgumentExceptionCorrectlyRule",
Expand Down Expand Up @@ -676,13 +682,13 @@ module internal Runner =
=
let covered =
match reportDocument with
| Unknown -> [] //(result, 0uy, String.Empty)
| Unknown -> defaultSummary
| XML report ->
report
|> match format with
| ReportFormat.NCover -> nCoverSummary
| _ -> openCoverSummary
| JSON jtext -> jsonSummary jtext // (result, 0uy, String.Empty) // TODO
| JSON jtext -> jsonSummary jtext

let best = (result, 0uy, String.Empty)

Expand Down
2 changes: 2 additions & 0 deletions AltCover.Tests/Expecto.fs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ module ExpectoTestManifest =
"Runner.SimpleJsonShouldGeneratePlausibleSummary"
Tests.AltCoverRunnerTests.ComplexJsonShouldGeneratePlausibleSummary,
"Runner.ComplexJsonShouldGeneratePlausibleSummary"
Tests.AltCoverRunnerTests.UnknownGeneratesExpectedSummary,
"Runner.UnknownGeneratesExpectedSummary"
Tests.AltCoverRunnerTests.EmptyNCoverGeneratesExpectedSummary,
"Runner.EmptyNCoverGeneratesExpectedSummary"
Tests.AltCoverRunnerTests.EmptyNCoverGeneratesExpectedTCSummary,
Expand Down
Loading

0 comments on commit 32b29a4

Please sign in to comment.