forked from OpenCover/opencover
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OpenCover#807 create test scenario for reported issue
- Loading branch information
Showing
6 changed files
with
208 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
28 changes: 28 additions & 0 deletions
28
main/OpenCover.Test.Samples.Fs.3.1/OpenCover.Test.Samples.Fs.3.1.fsproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
60 changes: 60 additions & 0 deletions
60
main/OpenCover.Test/Framework/Symbols/CecilSymbolManagerTestsFSharpExt31.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.