Skip to content

Commit

Permalink
Minimum net20 proof of concept replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveGilham committed Apr 28, 2024
1 parent 9150719 commit 89baebc
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 1 deletion.
8 changes: 8 additions & 0 deletions AltCover.sln
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Cecil", "Cecil", "{F56DE54A
ThirdParty\cecil\Mono.Cecil.Rocks.pdb = ThirdParty\cecil\Mono.Cecil.Rocks.pdb
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample0", "Samples\Sample0\Sample0.csproj", "{19CE63CE-3622-409A-974D-3EA01388317E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -330,6 +332,11 @@ Global
{B42E9FBA-BDE8-4B15-B7E7-DDF237CA7881}.Debug|x86.Build.0 = Debug|Any CPU
{B42E9FBA-BDE8-4B15-B7E7-DDF237CA7881}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B42E9FBA-BDE8-4B15-B7E7-DDF237CA7881}.Release|x86.ActiveCfg = Release|Any CPU
{19CE63CE-3622-409A-974D-3EA01388317E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{19CE63CE-3622-409A-974D-3EA01388317E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19CE63CE-3622-409A-974D-3EA01388317E}.Debug|x86.ActiveCfg = Debug|Any CPU
{19CE63CE-3622-409A-974D-3EA01388317E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19CE63CE-3622-409A-974D-3EA01388317E}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -356,6 +363,7 @@ Global
{10FB27A2-9C4D-474D-A3B9-1C554038AA7E} = {2837CE07-B91F-4B8A-89B5-E7BE39A8F340}
{B42E9FBA-BDE8-4B15-B7E7-DDF237CA7881} = {2837CE07-B91F-4B8A-89B5-E7BE39A8F340}
{F56DE54A-ABD6-42F7-B61E-7BAFCCF2D787} = {97367D43-64EF-48E1-B6B4-D951C783E6E1}
{19CE63CE-3622-409A-974D-3EA01388317E} = {2837CE07-B91F-4B8A-89B5-E7BE39A8F340}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C31111CF-68A2-403F-9B06-9625FCBD48E3}
Expand Down
89 changes: 88 additions & 1 deletion Build/targets.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3334,6 +3334,93 @@ module Targets =

Actions.ValidateFSharpTypesCoverage simpleReport2)

let BasicCSharp0 =
(fun () ->
let samplePath =
"_Binaries/Sample0/Debug+AnyCPU/net20"

let binaryPath =
"_Binaries/AltCover/Release+AnyCPU/net472"

let reportSigil = "BasicCSharp0"

printfn "Instrument and run a simple executable"
Directory.ensure "./_Reports"

let simpleReport =
(Path.getFullName "./_Reports")
@@ (reportSigil + ".xml")

let binRoot = Path.getFullName binaryPath
let sampleRoot = Path.getFullName samplePath

let instrumented =
"__Instrumented." + reportSigil

let framework =
Fake.DotNet.ToolType.CreateFullFramework()

let prep =
AltCover.PrepareOptions.Primitive
{ Primitive.PrepareOptions.Create() with
// Verbosity = System.Diagnostics.TraceLevel.Verbose
TypeFilter = [ """System\.""" ]
Report = simpleReport
OutputDirectories = [| "./" + instrumented |]
ReportFormat = "NCover"
InPlace = false
Save = false }
|> AltCoverCommand.Prepare

let parameters =
{ AltCoverCommand.Options.Create prep with
ToolPath = binRoot @@ "AltCover.exe"
ToolType = framework
WorkingDirectory = sampleRoot }

AltCoverCommand.run parameters
System.Threading.Thread.Sleep(1000)

Actions.Run
(sampleRoot @@ (instrumented + "/Sample0.exe"), (sampleRoot @@ instrumented), [])
"Instrumented .exe failed"

System.Threading.Thread.Sleep(1000)

use coverageFile = // fsharplint:disable-next-line RedundantNewKeyword
new FileStream(
simpleReport,
FileMode.Open,
FileAccess.Read,
FileShare.None,
4096,
FileOptions.SequentialScan
)

use reader = XmlReader.Create(coverageFile)

let coverageDocument =
XDocument.Load(reader)

let recorded =
coverageDocument.Descendants(XName.Get("seqpnt"))
|> Seq.toList

Assert.That(
List.length recorded,
Is.EqualTo 1,
"unexpected points in " + reportSigil
)

let ones =
recorded
|> Seq.filter (fun x -> x.Attribute(XName.Get("visitcount")).Value = "1")
|> Seq.map _.Attribute(XName.Get("line")).Value
|> Seq.sort
|> Seq.toList

Assert.That(List.length ones, Is.EqualTo 1, "unexpected visits in " + reportSigil))

let BasicCSharp =
(fun () ->
Actions.SimpleInstrumentingRun
Expand Down Expand Up @@ -8284,7 +8371,7 @@ module Targets =
_Target "FSAsyncTests" FSAsyncTests
_Target "FSharpTypesDotNetRunner" FSharpTypesDotNetRunner
_Target "FSharpTypesDotNetCollecter" FSharpTypesDotNetCollecter
_Target "BasicCSharp" ignore // virus false +ve // BasicCSharp
_Target "BasicCSharp" BasicCSharp0 // virus false +ve // BasicCSharp
_Target "BasicCSharpMono" BasicCSharpMono
_Target "BasicCSharpUnderMono" BasicCSharpUnderMono
_Target "BasicCSharpMonoUnderMono" BasicCSharpMonoUnderMono
Expand Down
2 changes: 2 additions & 0 deletions Samples/Sample0/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// See https://aka.ms/new-console-template for more information
System.Console.WriteLine("Hello, World!");
9 changes: 9 additions & 0 deletions Samples/Sample0/Sample0.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net20</TargetFramework>
<LangVersion>9.0</LangVersion>
</PropertyGroup>

</Project>

0 comments on commit 89baebc

Please sign in to comment.