[F#]Coverage reporting from F# lambda expressions loses branch information
Code under test
namespace ClassLibrary1
open System
open System.IO
open System.Linq
module CommandLine =
let internal WriteColoured (writer:TextWriter) colour operation =
let original = Console.ForegroundColor
try
Console.ForegroundColor <- colour
operation writer
finally
Console.ForegroundColor <- original
let Usage ((intro:string), (options:obj seq), (options2:obj seq)) =
WriteColoured Console.Error ConsoleColor.Yellow (fun w -> if options.Any() || options2.Any() then
w.WriteLine intro
if options.Any() then
w.WriteLine("options")
if options.Any() && options2.Any() then
w.WriteLine "binder"
if options2.Any() then
w.WriteLine("options2")
else if options.Any() then
w.WriteLine "orbinder"
w.WriteLine "tail")
driven by test code
[Fact]
public void Test1()
{
var l = new object[] { };
var m = new object[] { l };
ClassLibrary1.CommandLine.Usage("string", l, l);
ClassLibrary1.CommandLine.Usage("string", m, m);
}
run dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
The report to the console is | ClassLibrary1 | 100% | 92.9% | 100% |
The XML report, however, contains no branch points.
Thanks for reporting this @SteveGilham. Quick question, is the branch information preserved in the json output format?
Branches, but no lines, are present for class ClassLibrary1.CommandLine/Usage@17 (i.e. the lambda) in the Invoke method; the OpenCover format has the class, but with no methods.
In both cases lines that correspond to code in the lambda are reported as belonging to the containing method Usage
possible dup of https://github.com/tonerdo/coverlet/issues/343
The issue might be out-dated because new releases are available.
Please reopen the issue if the bug still exists and can be reproduced with latest preview from coverlet nightly build.