Skip to content

Commit

Permalink
Merge branch 'develop/github/maintenance' into release/Habu
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveGilham committed May 31, 2024
2 parents dad881f + bf273fc commit 9db97e9
Show file tree
Hide file tree
Showing 36 changed files with 2,007 additions and 63 deletions.
20 changes: 13 additions & 7 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,46 @@
"isRoot": true,
"tools": {
"dotnet-reportgenerator-globaltool": {
"version": "5.2.4",
"version": "5.3.0",
"commands": [
"reportgenerator"
]
],
"rollForward": false
},
"xmldocmd": {
"version": "2.9.0",
"commands": [
"xmldocmd"
]
],
"rollForward": false
},
"altcode.gendarme-tool": {
"version": "2023.12.27.19054",
"commands": [
"gendarme"
]
],
"rollForward": false
},
"dotnet-fsharplint": {
"version": "0.23.0",
"commands": [
"dotnet-fsharplint"
]
],
"rollForward": false
},
"coveralls.net": {
"version": "4.0.1",
"commands": [
"csmacnz.Coveralls"
]
],
"rollForward": false
},
"nbgv": {
"version": "3.6.133",
"commands": [
"nbgv"
]
],
"rollForward": false
}
}
}
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.204'
dotnet-version: '8.0.300'
- name: Tools
run: dotnet tool restore
- name: Setup
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.204'
dotnet-version: '8.0.300'
- name: Tools
run: dotnet tool restore
- name: Setup
Expand Down
6 changes: 4 additions & 2 deletions AltCover.Cake/AltCover.Cake.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Cake.Core" />
<PackageReference Include="Cake.Common" />
<PackageReference Include="Cake.Common" Condition="'$(TargetFramework)' == 'netstandard2.0'" VersionOverride="1.0.0" />
<PackageReference Include="Cake.Common" Condition="'$(TargetFramework)' == 'netcoreapp3.1'" VersionOverride="2.0.0" />
<PackageReference Include="Cake.Core" Condition="'$(TargetFramework)' == 'netstandard2.0'" VersionOverride="1.0.0" />
<PackageReference Include="Cake.Core" Condition="'$(TargetFramework)' == 'netcoreapp3.1'" VersionOverride="2.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
2 changes: 1 addition & 1 deletion AltCover.DataCollector/AltCover.DataCollector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" VersionOverride="16.0.0"/>
<PackageReference Include="Microsoft.SourceLink.GitHub">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
2 changes: 1 addition & 1 deletion AltCover.Engine/AltCover.Engine.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" />
<PackageReference Include="Microsoft.Build.Utilities.Core" VersionOverride="16.0.461" />
<PackageReference Include="Microsoft.SourceLink.GitHub">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
14 changes: 9 additions & 5 deletions AltCover.Engine/Cobertura.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ module internal Cobertura =
(attribute: string)
=
report.Descendants(tag.X)
|> Seq.map (fun s ->
s.Attribute(attribute.X).Value
|> Path.GetDirectoryName)
|> Seq.map (fun s -> s.Attribute(attribute.X).Value)
|> Seq.filter (fun a -> a |> String.IsNullOrWhiteSpace |> not)
|> Seq.map Path.GetDirectoryName
|> Seq.filter (String.IsNullOrWhiteSpace >> not)
|> Seq.fold (fun s f -> s |> Set.add f) Set.empty<String>
|> Seq.sort
|> Seq.iter (fun f ->
Expand Down Expand Up @@ -112,15 +113,18 @@ module internal Cobertura =
let cname = m.Attribute("class".X).Value
let mname = m.Attribute("name".X).Value

let indexmname =
mname.Split('`') |> Seq.head

let classAt =
fn.IndexOf(cname, StringComparison.Ordinal)

let returnType = fn.Substring(0, classAt)

let methodAt =
fn.IndexOf(mname, classAt + cname.Length, StringComparison.Ordinal)
fn.IndexOf(indexmname, classAt + cname.Length, StringComparison.Ordinal)

let argsAt = methodAt + mname.Length
let argsAt = methodAt + indexmname.Length
let args = fn.Substring(argsAt)
let signature = returnType + args
(mname, signature)
Expand Down
14 changes: 10 additions & 4 deletions AltCover.Engine/LCov.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ module internal LCov =
)
|> Seq.min

let getVC (mp: XElement) =
mp.Attribute("vc".X)
|> Option.ofObj
|> Option.map _.Value
|> Option.defaultValue "0"

let internal multiSort (by: 'a -> int) (l: (string * 'a seq) seq) =
l
|> Seq.map (fun (f, ms) -> (f, ms |> Seq.sortBy by |> Seq.toList))
Expand Down Expand Up @@ -314,10 +320,10 @@ FN:4,(anonymous_0)

let sl = s.Attribute("sl".X).Value

let vc = I.getVC mp

if sl |> String.IsNullOrWhiteSpace |> not then
writer.WriteLine(
"FNDA:" + mp.Attribute("vc".X).Value + "," + n
)))
writer.WriteLine("FNDA:" + vc + "," + n)))

FNDA methods
// This list is followed by two lines containing the number of functions
Expand All @@ -339,7 +345,7 @@ FN:4,(anonymous_0)
m.Descendants("MethodPoint".X) ]
|> Seq.concat
|> Seq.exists (fun s ->
let v = s.Attribute("vc".X).Value
let v = I.getVC s
v.IsNotNull && v != "0"))

writer.WriteLine(
Expand Down
7 changes: 6 additions & 1 deletion AltCover.Engine/Naming.fs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ module internal Naming =
String.Empty

let return' =
I.fullTypeRefName def.ReturnType
let r = def.ReturnType

if r.ContainsGenericParameter then
r.FullName
else
I.fullTypeRefName r

String.Join(
String.Empty,
Expand Down
27 changes: 26 additions & 1 deletion AltCover.Engine/NativeJson.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1296,8 +1296,27 @@ module
Track = m.Track }

let getMethodRecord (s: JsonContext) (doc: string) (record: Cil.Document) =
let vtype = s.VisibleMethod.DeclaringType

let vms =
vtype.Methods |> Seq.groupBy _.FullName

let visibleMethodName =
s.VisibleMethod.FullName
let tentative = s.VisibleMethod.FullName

let group =
vms
|> Seq.find (fun (n, x) -> n.Equals(tentative, StringComparison.Ordinal))
|> snd
|> Seq.length

match group with
| 1 -> tentative
| _ ->
let update =
sprintf "`%d(" s.VisibleMethod.GenericParameters.Count

tentative.Replace("(", update)

let visibleTypeName =
s.VisibleMethod.DeclaringType.FullName
Expand Down Expand Up @@ -1507,5 +1526,11 @@ type internal DocumentType =
"AltCover.NativeJson+SeqPnt.#.ctor(System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Collections.Generic.List`1<System.String>,System.Collections.Generic.List`1<System.Int32>)",
MessageId = "v",
Justification = "Smaller JSON")>]
[<assembly: SuppressMessage("Gendarme.Rules.Globalization",
"PreferStringComparisonOverrideRule",
Scope = "member", // MethodDefinition
Target =
"AltCover.NativeJson/getMethodRecord@1299::Invoke(AltCover.NativeJson/JsonContext,System.String,Mono.Cecil.Cil.Document)",
Justification = "not at netstandard2.0")>]
()
#endif
53 changes: 45 additions & 8 deletions AltCover.Engine/OpenCover.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type internal OpenCoverContext =
Excluded: Exclusion
Files: Map<string, int>
Embeds: Map<string, string>
Names: Map<string, (MethodDefinition * XElement)>
Index: int
MethodSeq: int
MethodBr: int
Expand All @@ -47,6 +48,7 @@ type internal OpenCoverContext =
Excluded = Nothing
Files = Map.empty<string, int>
Embeds = Map.empty<string, string>
Names = Map.empty<string, (MethodDefinition * XElement)>
Index = 0
MethodSeq = 0
MethodBr = 0
Expand Down Expand Up @@ -224,14 +226,15 @@ module internal OpenCover =
methods :: s.Stack
else
s.Stack
Names = Map.empty<string, (MethodDefinition * XElement)>
Excluded = if instrumented then Nothing else ByType
ClassSeq = 0
ClassBr = 0
MethodCC = [] }

let boolString b = if b then "true" else "false"

let methodElement (methodDef: MethodDefinition) =
let methodElement (s: OpenCoverContext) (methodDef: MethodDefinition) =
let cc =
Gendarme.cyclomaticComplexity methodDef

Expand All @@ -251,14 +254,41 @@ module internal OpenCover =
XAttribute("crapScore".X, 0)
))

let addMethodContent (element: XElement) (methodDef: MethodDefinition) instrumented =
let addMethodContent
names
(element: XElement)
(methodDef: MethodDefinition)
instrumented
=
element.Add(summary ())

element.Add(
XElement("MetadataToken".X, methodDef.MetadataToken.ToUInt32().ToString())
)

element.Add(XElement("Name".X, methodDef.FullName))
let baseName = methodDef.FullName

let name = XElement("Name".X, baseName)

let newNames =
match Map.tryFind baseName names with
| None -> Map.add baseName (methodDef, name) names
| Some(def, xml) ->
let update =
sprintf "`%d(" def.GenericParameters.Count

xml.Value <- baseName.Replace("(", update)

let local =
sprintf "`%d(" methodDef.GenericParameters.Count

name.Value <- baseName.Replace("(", local)

names
|> Map.add xml.Value (def, xml)
|> Map.add name.Value (methodDef, name)

element.Add(name)

if instrumented then
element.Add(XElement("FileRef".X))
Expand All @@ -267,26 +297,27 @@ module internal OpenCover =
element.Add(seqpnts)
element.Add(XElement("BranchPoints".X))
element.Add(XElement("MethodPoint".X))
seqpnts
(seqpnts, newNames)

let visitMethod (s: OpenCoverContext) (methodDef: MethodDefinition) included =
if
s.Excluded = Nothing
&& included <> Inspections.TrackOnly
then
let instrumented = included.IsInstrumented
let cc, element = methodElement methodDef
let cc, element = methodElement s methodDef

if instrumented then
element.SetAttributeValue("skippedDueTo".X, "File")

let head = s.Stack |> Seq.head
head.Add element

let seqpnts =
addMethodContent element methodDef instrumented
let (seqpnts, names) =
addMethodContent s.Names element methodDef instrumented

{ s with
Names = names
Stack =
if instrumented then
seqpnts :: s.Stack
Expand Down Expand Up @@ -730,6 +761,12 @@ module internal OpenCover =
"PreferStringComparisonOverrideRule",
Scope = "member",
Target =
"AltCover.OpenCover/handleOrdinals@452-3::Invoke(System.Tuple`3<System.Int32,System.Int32,System.Xml.Linq.XElement>,System.Xml.Linq.XElement)",
"AltCover.OpenCover/handleOrdinals@483-3::Invoke(System.Tuple`3<System.Int32,System.Int32,System.Xml.Linq.XElement>,System.Xml.Linq.XElement)",
Justification = "Compiler generated")>]
[<assembly: SuppressMessage("Gendarme.Rules.Globalization",
"PreferStringComparisonOverrideRule",
Scope = "member", // MethodDefinition
Target =
"AltCover.OpenCover/addMethodContent@263::Invoke(Microsoft.FSharp.Collections.FSharpMap`2<System.String,System.Tuple`2<Mono.Cecil.MethodDefinition,System.Xml.Linq.XElement>>,System.Xml.Linq.XElement,Mono.Cecil.MethodDefinition,System.Boolean)",
Justification = "not netstandard2.0")>]
()
22 changes: 21 additions & 1 deletion AltCover.Engine/Report.fs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,30 @@ module internal Report =
(methodDef: MethodDefinition)
included
=
let vtype = methodDef.DeclaringType

let vms =
vtype.Methods |> Seq.groupBy _.FullName

let methodName =
let full = methodDef.FullName

let group =
vms
|> Seq.find (fun (n, x) -> n.Equals(full, StringComparison.Ordinal))
|> snd
|> Seq.length

let tentative = methodDef.Name

match group with
| 1 -> tentative
| _ -> sprintf "%s`%d" tentative methodDef.GenericParameters.Count

let element =
XElement(
"method".X,
XAttribute("name".X, methodDef.Name),
XAttribute("name".X, methodName),
// /// Mono.Cecil emits names in the form outer/inner rather than outer+inner
XAttribute("class".X, Naming.fullTypeName methodDef.DeclaringType),
XAttribute("metadataToken".X, methodDef.MetadataToken.ToUInt32().ToString()),
Expand Down
Loading

0 comments on commit 9db97e9

Please sign in to comment.