Skip to content

Commit

Permalink
Merge branch 'master' into release/Genbu
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveGilham committed Nov 9, 2020
2 parents 31203cd + 0cfec59 commit 5dcad38
Show file tree
Hide file tree
Showing 226 changed files with 18,941 additions and 3,797 deletions.
8 changes: 4 additions & 4 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
"isRoot": true,
"tools": {
"dotnet-reportgenerator-globaltool": {
"version": "4.6.1",
"version": "4.7.1",
"commands": [
"reportgenerator"
]
},
"fake-cli": {
"version": "5.20.1",
"version": "5.20.3",
"commands": [
"fake"
]
},
"xmldocmd": {
"version": "2.1.0",
"version": "2.3.0",
"commands": [
"xmldocmd"
]
},
"altcode.gendarme-tool": {
"version": "2020.6.12.11211-pre-release",
"version": "2020.7.21.12091-pre-release",
"commands": [
"gendarme"
]
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,9 @@ Demo/MultiTest/**/coverage.xml
TestResults/
AltCover/Abstract.fs
Tests.Visualizer/Reports/
.fake
.ionide
AltCover.Engine/Abstract.fsi
Sample22/Sample22.fsproj
Sample22/coverage.xml
buildsample*.fsx.lock
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: csharp
mono: latest
dist: xenial
dotnet: 3.1.301
dotnet: 3.1.403
addons:
apt:
sources:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.0;net47</TargetFrameworks>
<TargetFrameworks>netcoreapp3.0;net472</TargetFrameworks>
<IsPackable>false</IsPackable>
<AssemblyName>AltCover.Api.Tests</AssemblyName>
<AssetTargetFallback>$(AssetTargetFallback);netcoreapp1.0;</AssetTargetFallback>
<GenerateProgramFile>false</GenerateProgramFile>
<OutputType Condition="'$(TargetFramework)' != 'net47'">Exe</OutputType>
<OutputType Condition="'$(TargetFramework)' == 'net47'">Library</OutputType>
<OutputType Condition="'$(TargetFramework)' != 'net472'">Exe</OutputType>
<OutputType Condition="'$(TargetFramework)' == 'net472'">Library</OutputType>
<!-- NO!! SolutionDir Condition="'$(SolutionDir)' == '$(ProjectDir)'">$(ProjectDir)../</SolutionDir -->
<AssemblySearchPaths Condition="'$(TargetFramework)' == 'net47'">$(AssemblySearchPaths);{GAC}</AssemblySearchPaths>
<AssemblySearchPaths Condition="'$(TargetFramework)' == 'net472'">$(AssemblySearchPaths);{GAC}</AssemblySearchPaths>
<OutputPath>$(SolutionDir)_Binaries/$(AssemblyName)/$(Configuration)+$(Platform)/</OutputPath>
<IntermediateOutputPath>$(SolutionDir)_Intermediate/$(AssemblyName)/$(Configuration)+$(Platform)/</IntermediateOutputPath>
<OtherFlags>--keyfile:$(ProjectDir)..\Build\Infrastructure.snk</OtherFlags>
Expand Down Expand Up @@ -37,45 +37,45 @@
<EmbeddedResource Include="..\Tests\Sample1WithOpenCover.xml" Link="Sample1WithOpenCover.xml" />
<Compile Include="..\_Generated\SolutionRoot.fs" Link="SolutionRoot.fs" />
<Compile Include="..\_Generated\AssemblyVersion.fs" Link="AssemblyVersion.fs" />
<Compile Include="..\Tests\TestCommon.fs" Link="TestCommon.fs" />
<Compile Include="FSApiTests.fs" />
<Compile Include="Program.fs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Expecto" Version="9.0.0" Condition="'$(TargetFramework)' != 'net47'" />
<PackageReference Include="Expecto.TestResults" Version="8.13.2" Condition="'$(TargetFramework)' != 'net47'" />
<PackageReference Include="Expecto" Version="9.0.2" Condition="'$(TargetFramework)' != 'net472'" />
<PackageReference Include="Expecto.TestResults" Version="8.13.2" Condition="'$(TargetFramework)' != 'net472'" />
<PackageReference Include="System.ValueTuple" />
<PackageReference Include="Unquote" Version="5.0.0" Condition="'$(TargetFramework)' != 'net47'" />
<Reference Include="Unquote" Condition="'$(TargetFramework)' == 'net47'">
<PackageReference Include="Unquote" Version="5.0.0" Condition="'$(TargetFramework)' != 'net472'" />
<Reference Include="Unquote" Condition="'$(TargetFramework)' == 'net472'">
<HintPath>..\ThirdParty\Unquote.dll</HintPath>
</Reference>
<PackageReference Include="coverlet.collector" Version="1.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="YoloDev.Expecto.TestSdk" Version="0.9.2" Condition="'$(TargetFramework)' != 'net47'" />
<PackageReference Include="YoloDev.Expecto.TestSdk" Version="0.9.2" Condition="'$(TargetFramework)' != 'net472'" />
<PackageReference Include="Mono.Cecil" Version="0.11.2" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net47" Version="1.0.0" Condition="'$(TargetFramework)' == 'net47'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net472" Version="1.0.0" Condition="'$(TargetFramework)' == 'net472'">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AltCover.DotNet\altcover.dotnet.core.fsproj" />
<ProjectReference Include="..\AltCover.Toolkit\altcover.toolkit.core.fsproj" />
<ProjectReference Include="..\AltCover\altcover.core.fsproj" />
<ProjectReference Include="..\Sample18\sample18.core.fsproj" />
<ProjectReference Include="..\AltCover.DotNet\AltCover.DotNet.fsproj" />
<ProjectReference Include="..\AltCover.Toolkit\AltCover.Toolkit.fsproj" />
<ProjectReference Include="..\AltCover.Engine\AltCover.Engine.fsproj" />
<ProjectReference Include="..\Sample18\Sample18.fsproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="FSharp.Core" Version="4.7.0" Condition="'$(TargetFramework)' != 'net47'" />
<PackageReference Update="FSharp.Core" Version="4.5.2" Condition="'$(TargetFramework)' == 'net47'" />
<PackageReference Update="FSharp.Core" Version="5.0.0" />
<PackageReference Update="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
</Project>
45 changes: 18 additions & 27 deletions AltCover.Api.Tests/FSApiTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,8 @@ open System.Xml.Schema

open AltCover
open Microsoft.FSharp.Reflection
open Swensen.Unquote

#if NETCOREAPP3_0
[<AttributeUsage(AttributeTargets.Method)>]
type TestAttribute() = class
inherit Attribute()
end
#else
type TestAttribute = NUnit.Framework.TestAttribute
#endif

module FSApiTests =
let SolutionDir() =
SolutionRoot.location

[<Test>]
let FormatFromCoverletMeetsSpec() =
Expand Down Expand Up @@ -127,7 +115,7 @@ module FSApiTests =
[<Test>]
let OpenCoverToLcov() =
use stream=
Assembly.GetExecutingAssembly().GetManifestResourceStream("altcover.api.tests.core.HandRolledMonoCoverage.xml")
Assembly.GetExecutingAssembly().GetManifestResourceStream("AltCover.Api.Tests.HandRolledMonoCoverage.xml")
let doc = XDocument.Load(stream)
use stream2 = new MemoryStream()
CoverageFormats.ConvertToLcov doc stream2
Expand All @@ -136,7 +124,7 @@ module FSApiTests =
let result = rdr.ReadToEnd().Replace("\r", String.Empty)

use stream3 =
Assembly.GetExecutingAssembly().GetManifestResourceStream("altcover.api.tests.core.HandRolledMonoCoverage.lcov")
Assembly.GetExecutingAssembly().GetManifestResourceStream("AltCover.Api.Tests.HandRolledMonoCoverage.lcov")
use rdr2 = new StreamReader(stream3)
let expected = rdr2.ReadToEnd().Replace("\r", String.Empty)

Expand All @@ -145,7 +133,7 @@ module FSApiTests =
[<Test>]
let OpenCoverToBarChart() =
use stream=
Assembly.GetExecutingAssembly().GetManifestResourceStream("altcover.api.tests.core.HandRolledMonoCoverage.xml")
Assembly.GetExecutingAssembly().GetManifestResourceStream("AltCover.Api.Tests.HandRolledMonoCoverage.xml")
let doc = XDocument.Load stream
use mstream = new MemoryStream()
let rewrite = Xhtml.ConvertToBarChart doc
Expand All @@ -155,7 +143,7 @@ module FSApiTests =
let result = rdr.ReadToEnd().Replace("\r", String.Empty)

use stream2 =
Assembly.GetExecutingAssembly().GetManifestResourceStream("altcover.api.tests.core.HandRolledMonoCoverage.html")
Assembly.GetExecutingAssembly().GetManifestResourceStream("AltCover.Api.Tests.HandRolledMonoCoverage.html")
use rdr2 = new StreamReader(stream2)
let expected = rdr2.ReadToEnd().Replace("&#x2442;", "\u2442").Replace("\r", String.Empty)

Expand All @@ -165,7 +153,7 @@ module FSApiTests =
[<Test>]
let OpenCoverToNCover() =
use stream=
Assembly.GetExecutingAssembly().GetManifestResourceStream("altcover.api.tests.core.HandRolledMonoCoverage.xml")
Assembly.GetExecutingAssembly().GetManifestResourceStream("AltCover.Api.Tests.HandRolledMonoCoverage.xml")
let doc = XDocument.Load stream
use mstream = new MemoryStream()
let rewrite = CoverageFormats.ConvertToNCover doc
Expand All @@ -175,7 +163,7 @@ module FSApiTests =
let result = rdr.ReadToEnd().Replace("\r", String.Empty)

use stream2 =
Assembly.GetExecutingAssembly().GetManifestResourceStream("altcover.api.tests.core.HandRolledToNCover.xml")
Assembly.GetExecutingAssembly().GetManifestResourceStream("AltCover.Api.Tests.HandRolledToNCover.xml")
use rdr2 = new StreamReader(stream2)
let time = (rewrite.Descendants(XName.Get "coverage")
|> Seq.head).Attribute(XName.Get "startTime").Value
Expand All @@ -196,7 +184,7 @@ module FSApiTests =
[<Test>]
let FormatsConvertToXmlDocument() =
use stream =
Assembly.GetExecutingAssembly().GetManifestResourceStream("altcover.api.tests.core.HandRolledMonoCoverage.html")
Assembly.GetExecutingAssembly().GetManifestResourceStream("AltCover.Api.Tests.HandRolledMonoCoverage.html")
use rdr = new StreamReader(stream)
let expected = rdr.ReadToEnd().Replace("html >", "html>").Replace("\r", String.Empty).Replace("&#x2442;", "\u2442")
rdr.BaseStream.Position <- 0L
Expand All @@ -213,7 +201,7 @@ module FSApiTests =
[<Test>]
let FormatsConvertToXDocument() =
use stream =
Assembly.GetExecutingAssembly().GetManifestResourceStream("altcover.api.tests.core.HandRolledMonoCoverage.html")
Assembly.GetExecutingAssembly().GetManifestResourceStream("AltCover.Api.Tests.HandRolledMonoCoverage.html")
use rdr = new StreamReader(stream)
let expected = rdr.ReadToEnd().Replace("\r", String.Empty).Replace("&#x2442;", "\u2442")
rdr.BaseStream.Position <- 0L
Expand Down Expand Up @@ -242,7 +230,7 @@ module FSApiTests =
[<Test>]
let NCoverToCobertura() =
use stream=
Assembly.GetExecutingAssembly().GetManifestResourceStream("altcover.api.tests.core.Sample1WithNCover.xml")
Assembly.GetExecutingAssembly().GetManifestResourceStream("AltCover.Api.Tests.Sample1WithNCover.xml")
let doc = XDocument.Load(stream)
doc.Descendants()
|> Seq.map (fun n -> n.Attribute(XName.Get "excluded"))
Expand All @@ -257,7 +245,7 @@ module FSApiTests =
let result = rdr.ReadToEnd().Replace("\r", String.Empty)

use stream3 =
Assembly.GetExecutingAssembly().GetManifestResourceStream("altcover.api.tests.core.Sample1WithNCover.cob.xml")
Assembly.GetExecutingAssembly().GetManifestResourceStream("AltCover.Api.Tests.Sample1WithNCover.cob.xml")
use rdr2 = new StreamReader(stream3)

let coverage = cob.Descendants(XName.Get "coverage") |> Seq.head
Expand All @@ -272,7 +260,7 @@ module FSApiTests =
[<Test>]
let NCoverToBarChart() =
use stream=
Assembly.GetExecutingAssembly().GetManifestResourceStream("altcover.api.tests.core.GenuineNCover158.Xml")
Assembly.GetExecutingAssembly().GetManifestResourceStream("AltCover.Api.Tests.GenuineNCover158.Xml")
let doc = XDocument.Load stream
use mstream = new MemoryStream()
let rewrite = Xhtml.ConvertToBarChart doc
Expand All @@ -282,7 +270,7 @@ module FSApiTests =
let result = rdr.ReadToEnd().Replace("html >", "html>").Replace("\r", String.Empty)

use stream2 =
Assembly.GetExecutingAssembly().GetManifestResourceStream("altcover.api.tests.core.GenuineNCover158Chart.html")
Assembly.GetExecutingAssembly().GetManifestResourceStream("AltCover.Api.Tests.GenuineNCover158Chart.html")
use rdr2 = new StreamReader(stream2)
let expected = rdr2.ReadToEnd().Replace("\r", String.Empty)

Expand All @@ -292,7 +280,7 @@ module FSApiTests =
[<Test>]
let OpenCoverBranchCompression() =
use stream=
Assembly.GetExecutingAssembly().GetManifestResourceStream("altcover.api.tests.core.Compressible.xml")
Assembly.GetExecutingAssembly().GetManifestResourceStream("AltCover.Api.Tests.Compressible.xml")
let doc = XDocument.Load stream

[("CompressInterior", true, false)
Expand All @@ -307,7 +295,7 @@ module FSApiTests =
let result = rdr.ReadToEnd().Replace("\r", String.Empty)

use stream2 =
Assembly.GetExecutingAssembly().GetManifestResourceStream("altcover.api.tests.core."+ test + ".xml")
Assembly.GetExecutingAssembly().GetManifestResourceStream("AltCover.Api.Tests."+ test + ".xml")
use rdr2 = new StreamReader(stream2)
let expected = rdr2.ReadToEnd().Replace("\r", String.Empty)

Expand Down Expand Up @@ -430,10 +418,13 @@ module FSApiTests =
test <@ DotNet.ToTestArguments prep coll combined =
"/p:AltCover=\"true\" /p:AltCoverReportFormat=\"OpenCover\" /p:AltCoverShowStatic=\"-\" /p:AltCoverShowSummary=\"R\" /p:AltCoverForce=\"true\" /p:AltCoverFailFast=\"true\"" @>

#if SOURCEMAP
let SolutionDir() =
SolutionRoot.location

let internal mangleFile (f:String) =
f.Replace(@"C:\Users\steve\Documents\GitHub\altcover", SolutionRoot.location).Replace('\\', Path.DirectorySeparatorChar)

#if SOURCEMAP
[<Test>]
let NCoverFindsFiles() =
use stream =
Expand Down
55 changes: 10 additions & 45 deletions AltCover.Api.Tests/Program.fs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
namespace AltCover.Expecto.Tests
namespace Tests

#if NETCOREAPP3_0

open Expecto
open Mono.Cecil
open Mono.Cecil.Cil
open Mono.Cecil.Rocks
open Swensen.Unquote

module TestMain =
let sync = System.Object()

module ExpectoMain =
let regular = [
Tests.TestCommonTests.ExerciseItAll, "TestCommonTests.ExerciseItAll"
Tests.TestCommonTests.SelfTest, "TestCommonTests.SelfTest"
Tests.FSApiTests.FormatFromCoverletMeetsSpec, "FSApiTests.FormatFromCoverlet"
Tests.FSApiTests.PostprocessShouldRestoreBranchOnlyOpenCoverState, "FSApiTests.PostprocessShouldRestoreBranchOnlyOpenCoverState"
Tests.FSApiTests.OpenCoverToLcov, "FSApiTests.OpenCoverToLcov"
Expand All @@ -36,47 +32,16 @@ module TestMain =
[]

let consistencyCheck() =
let here = System.Reflection.Assembly.GetExecutingAssembly().Location
let def = Mono.Cecil.AssemblyDefinition.ReadAssembly(here)

let testMethods = def.MainModule.GetTypes()
|> Seq.collect (fun t -> t.Methods)
|> Seq.filter (fun m -> m.CustomAttributes |> isNull |> not)
|> Seq.filter (fun m -> m.CustomAttributes |> Seq.exists (fun a -> a.AttributeType.Name = "TestAttribute"))
|> Seq.map (fun m -> m.DeclaringType.FullName + "::" + m.Name)

let lookup = def.MainModule.GetAllTypes()
|> Seq.filter (fun t -> t.Methods |> Seq.exists(fun m -> m.Name = "Invoke"))
|> Seq.map (fun t -> (t.FullName.Replace("/","+"), t.Methods |> Seq.find(fun m -> m.Name = "Invoke")))
|> Map.ofSeq

let calls = regular
|> List.map (fst
>> (fun f -> f.GetType().FullName.Replace("/","+"))
>> (fun f -> Map.find f lookup)
>> (fun f -> f.Body.Instructions |> Seq.find (fun i -> i.OpCode = OpCodes.Call))
>> (fun i -> let m = (i.Operand :?> MethodDefinition)
m.DeclaringType.FullName + "::" + m.Name))
|> Set.ofList

let omitted = testMethods
|> Seq.filter (fun t -> (Set.contains t calls) |> not)
|> Seq.toList

// cover all but the special cases
test <@ omitted = [] @>
ExpectoTestCommon.consistencyCheck regular []

[<Tests>]
let tests =
testList "AltCover.Api.Tests"
<| ((((consistencyCheck, "ConsistencyCheck") :: regular)
|> List.map (fun (f,name) -> testCase name f))
@ specials)
ExpectoTestCommon.makeTests "AltCoverApiTests" consistencyCheck regular specials ignore

module Program =
[<EntryPoint>]
let main argv =
module UnitTestStub =
[<EntryPoint; System.Runtime.CompilerServices.CompilerGenerated>]
let unitTestStub argv =
let writeResults = TestResults.writeNUnitSummary ("AltCover.Api.TestResults.xml", "AltCover.Api.Tests")
let config = defaultConfig.appendSummaryHandler writeResults
runTestsWithArgs config argv TestMain.tests
runTestsWithArgs config argv ExpectoMain.tests
#endif
Loading

0 comments on commit 5dcad38

Please sign in to comment.