Skip to content

Commit

Permalink
Speculative change
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveGilham committed Jun 23, 2023
1 parent 8bc005b commit 6ef8394
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 4 deletions.
53 changes: 50 additions & 3 deletions AltCover.Engine/CecilEx.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ open Mono.Cecil
open Mono.Cecil.Cil

module AssemblyConstants =
let internal extensions =
[ ".dll"; ".exe"; ".winmd" ]

let internal nugetCache =
Path.Combine(
Path.Combine(
Expand Down Expand Up @@ -86,6 +89,40 @@ type internal AssemblyResolver() as self =
else
base.Resolve name

[<SuppressMessage("Gendarme.Rules.Exceptions",
"UseObjectDisposedExceptionRule",
Justification = "Not important")>]
override self.SearchDirectory
(
(name: AssemblyNameReference),
(directories: IEnumerable<string>),
(parameters: ReaderParameters)
) : AssemblyDefinition =
directories
|> Seq.choose (fun directory ->
AssemblyConstants.extensions
|> List.choose (fun extension -> // this line
let file =
Path.Combine(directory, name.Name + extension)

if File.Exists(file) then
try
if isNull parameters.AssemblyResolver then
parameters.AssemblyResolver <- self

Some(
ModuleDefinition
.ReadModule(file, parameters)
.Assembly
)
with :? System.BadImageFormatException ->
None
else
None)
|> List.tryHead)
|> Seq.tryHead
|> Option.defaultValue null

static member private AssemblyRegister (name: string) (path: string) =
let def = AssemblyResolver.ReadAssembly path // recursive
AssemblyConstants.resolutionTable.[name] <- def
Expand Down Expand Up @@ -156,8 +193,9 @@ type internal AssemblyResolver() as self =
|> Seq.filter (fun f ->
let x = Path.GetExtension f

x.Equals(".exe", StringComparison.OrdinalIgnoreCase)
|| x.Equals(".dll", StringComparison.OrdinalIgnoreCase))
AssemblyConstants.extensions
|> List.tryFind (fun ext -> x.Equals(ext, StringComparison.OrdinalIgnoreCase))
|> Option.isSome)
|> Seq.filter (fun f ->
y
.ToString()
Expand Down Expand Up @@ -363,4 +401,13 @@ module internal CecilExtension =
|> Seq.filter (fun i -> i.OpCode = OpCodes.Tail)
|> Seq.iter (fun i ->
i.OpCode <- OpCodes.Nop
i.Operand <- null)
i.Operand <- null)

[<assembly: SuppressMessage("Gendarme.Rules.Correctness",
"EnsureLocalDisposalRule",
Scope = "member", // MethodDefinition
Target =
"<StartupCode$AltCover-Engine>.$CecilEx/Pipe #1 stage #1 at line 104@104::Invoke(System.String)",
Justification =
"The whole point is to return the value, transferring ownership")>]
()
2 changes: 1 addition & 1 deletion AltCover.Monitor.Tests/MonitorTest.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module MonitorTests =
AltCover.SolutionRoot.location,
"_Reports/MonitorTestWithAltCoverCoreRunner.net7.0.xml"
),
[ (260, 37); (260, 36) ] ]
[ (218, 35); (260, 37); (260, 36) ] ]
|> List.filter (fst >> File.Exists)
|> List.sortBy (fst >> File.GetCreationTimeUtc)
|> List.last
Expand Down
2 changes: 2 additions & 0 deletions AltCover.Tests/Expecto.fs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,8 @@ module ExpectoTestManifest =
"Tests2.ShouldBeAbleToTellAnAssembly"
Tests.AltCoverTests2.ShouldBeAbleToValidateAnAssembly,
"Tests2.ShouldBeAbleToValidateAnAssembly"
Tests.AltCoverTests2.ShouldbeAbleToHandleWinmd,
"Tests2.ShouldbeAbleToHandleWinmd"
Tests.AltCoverTests2.ShouldBeAbleToLocateAReference,
"Tests2.ShouldBeAbleToLocateAReference"
Tests.AltCoverTests2.ShouldBeAbleToPrepareTheAssembly,
Expand Down
14 changes: 14 additions & 0 deletions AltCover.Tests/Tests2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,20 @@ module AltCoverTests2 =

Assert.That(x, Is.EqualTo(String.Empty, false))

[<Test>]
let ShouldbeAbleToHandleWinmd () =
use r = new AssemblyResolver()
let p = ReaderParameters()
let name = AssemblyNameReference("platform", Version("255.255.255.255"))
let path = Path.Combine(SolutionRoot.location, "ThirdParty")

// Force this call
let methodinfo = r.GetType().GetMethod("SearchDirectory")
let o = methodinfo.Invoke(r, [| name; [path]; p |])

use platform = o :?> AssemblyDefinition
test <@ platform.MainModule.FileName = Path.Combine(path, "platform.winmd") @>

[<Test>]
let ShouldBeAbleToLocateAReference () =
let where =
Expand Down
Empty file added ThirdParty/platform.dll
Empty file.
Binary file added ThirdParty/platform.winmd
Binary file not shown.

0 comments on commit 6ef8394

Please sign in to comment.