Code coverage of built-in functions using F # in visual studio 2012

The code coverage tool in Visual Studio 2012 marks all inline functions as uncovered even when they were closed.

Is there a way to make code coverage work for inline functions?

+6
source share
2 answers

Are inline functions built into the calling code? If this is the case, then the actual method will not be called, since the code is "nested", and for each place it uses, there is a new copy of the built-in code.

+3
source

When you write an inline function, the compiler builds the body of the function into the calling code. As discussed in the comments, it also does not output debugging information for this built-in body (and therefore you cannot enter the function - I think this can be fixed - send a request to fsbugs to microsoft dot com ).

However, the compiler also generates a dynamic version of the code - if you write say:

 let inline add ab = a + b 

then the compiled code actually has an add method. The method will be general ( 'a -> 'b -> 'c ) and uses dynamic search to find the appropriate implementation of the + operator (since .NET generators cannot represent such restrictions).

A dynamic implementation will be called when using reflection or quotes:

 open Microsoft.FSharp.Linq.RuntimeHelpers <@ add 1 2 @> |> LeafExpressionConverter.EvaluateQuotation |> printfn "Got: %A" 

If you set a breakpoint inside add and run the code above, the breakpoint will be deleted (and I believe that the code coverage tool will report the function as being covered).

But keep in mind that this is not the code that actually runs when you write add 1 2 in normal code - the executable code here is a different implementation (which uses slow dynamic search, not inlining).

+4
source

All Articles