Skip to content

Commit

Permalink
OpenCover#807 create test scenario for reported issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sawilde committed Jan 29, 2021
1 parent e6e8d7f commit e8e8294
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 2 deletions.
5 changes: 5 additions & 0 deletions main/OpenCover.Test.Samples.Fs.3.1/Library.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace OpenCover.Test.Samples.Fs._3._1

type ClassWithAutoProperty() =
member val AutoProperty = 0 with get, set

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>OpenCover.Test.Samples.Fs._3._1</RootNamespace>
<OutputType>Library</OutputType>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>..\bin\Debug\</OutputPath>
<DebugType>embedded</DebugType>
<DebugSymbols>true</DebugSymbols>
<Optimize>false</Optimize>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>..\bin\Release\</OutputPath>
<DebugType>embedded</DebugType>
<DebugSymbols>true</DebugSymbols>
<Optimize>false</Optimize>
</PropertyGroup>

<ItemGroup>
<Compile Include="Library.fs" />
<Compile Include="Program.fs" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions main/OpenCover.Test.Samples.Fs.3.1/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Program

[<EntryPoint>]
let inline main _ =
let sample = System.DateTime.UtcNow |> string
printfn "%s" sample
0
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System.IO;
using Moq;
using NUnit.Framework;
using OpenCover.Framework;
using OpenCover.Framework.Strategy;
using OpenCover.Framework.Symbols;
using log4net;
using System.Linq;
using File = OpenCover.Framework.Model.File;
using System;

namespace OpenCover.Test.Framework.Symbols
{
[TestFixture]
public class CecilSymbolManagerTestsFSharpExt31
{
private CecilSymbolManager _reader;
private string _location;
private Mock<ICommandLine> _mockCommandLine;
private Mock<IFilter> _mockFilter;
private Mock<ILog> _mockLogger;
private Mock<ITrackedMethodStrategyManager> _mockManager;
private Mock<ISymbolFileHelper> _mockSymbolFileHelper;

[SetUp]
public void Setup()
{
_mockCommandLine = new Mock<ICommandLine>();
_mockFilter = new Mock<IFilter>();
_mockLogger = new Mock<ILog>();
_mockManager = new Mock<ITrackedMethodStrategyManager>();
_mockSymbolFileHelper = new Mock<ISymbolFileHelper>();

var assemblyPath = Path.GetDirectoryName(GetType().Assembly.Location);
_location = Path.Combine(assemblyPath, "netcoreapp3.1", "OpenCover.Test.Samples.Fs.3.1.dll");

_reader = new CecilSymbolManager(_mockCommandLine.Object, _mockFilter.Object, _mockLogger.Object, null, _mockSymbolFileHelper.Object);
_reader.Initialise(_location, "OpenCover.Test.Samples.Fs.3.1");
}

[Test]
public void Issue807_IgnoresBranchesGeneratedDueToInliningFSharp()
{
// arrange
_mockFilter
.Setup(x => x.InstrumentClass(It.IsAny<string>(), It.IsAny<string>()))
.Returns(true);

var types = _reader.GetInstrumentableTypes();
var type = types.First(x => x.FullName.EndsWith("Program"));
var methods = _reader.GetMethodsForType(type, new File[0]);

var branchPoints = _reader.GetBranchPointsForToken(methods.First(x => x.FullName.Contains("::main")).MetadataToken);
Assert.AreEqual(0, branchPoints.Count());

var sequencePoints = _reader.GetSequencePointsForToken(methods.First(x => x.FullName.Contains("::main")).MetadataToken);
Assert.AreEqual(3, sequencePoints.Count());
}
}
}
1 change: 1 addition & 0 deletions main/OpenCover.Test/OpenCover.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
<Compile Include="Framework\Strategy\TrackedMethodStrategyManagerTests.cs" />
<Compile Include="Framework\Symbols\CecilSymbolManagerMdbTests.cs" />
<Compile Include="Framework\Symbols\CecilSymbolManagerTests.cs" />
<Compile Include="Framework\Symbols\CecilSymbolManagerTestsFSharpExt31.cs" />
<Compile Include="Framework\Symbols\CecilSymbolManagerTestsExt31.cs" />
<Compile Include="Framework\Symbols\SymbolFileHelperTests.cs" />
<Compile Include="Framework\Utility\PerfCountersTests.cs" />
Expand Down
Loading

0 comments on commit e8e8294

Please sign in to comment.