coverlet icon indicating copy to clipboard operation
coverlet copied to clipboard

[F#]Coverage reporting from F# lambda expressions loses branch information

Open SteveGilham opened this issue 7 years ago • 3 comments

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.

SteveGilham avatar Jun 22 '18 11:06 SteveGilham

Thanks for reporting this @SteveGilham. Quick question, is the branch information preserved in the json output format?

tonerdo avatar Jun 22 '18 11:06 tonerdo

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

SteveGilham avatar Jun 22 '18 13:06 SteveGilham

possible dup of https://github.com/tonerdo/coverlet/issues/343

MarcoRossignoli avatar Sep 28 '19 08:09 MarcoRossignoli

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.

see Consume nightly build

Bertk avatar Jan 22 '24 08:01 Bertk