Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Behavior change when OpenCover is enabled #805

Open
7 tasks done
sharwell opened this issue Mar 13, 2018 · 1 comment
Open
7 tasks done

Behavior change when OpenCover is enabled #805

sharwell opened this issue Mar 13, 2018 · 1 comment

Comments

@sharwell
Copy link

sharwell commented Mar 13, 2018

My Framework

  • .NET 4.6.1

My Environment

  • Windows 10

I have already...

  • repeated the problem using the latest stable release of OpenCover.
  • reviewed the usage guide and usage document.
  • have looked at the opencover output xml file in an attempt to resolve the issue.
  • reviewed the current issues to check that the issue isn't already known.

My issue is related to (check only those which apply):

  • 32 or 64 bit support

Expected Behavior

Position get for item 'Goo'
Position set for item 'Goo'

Actual Behavior

Position get for item 'Goo'
Position set for item 'Bar'

Steps to reproduce the problem:

Compile the following with optimizations, and run it under OpenCover:

Imports System

Interface IMoveable
    Property Position As Integer
End Interface

Class Item
    Implements IMoveable

    Public Property Name As String

    Public Property Position As Integer Implements IMoveable.Position
        Get
            Console.WriteLine("Position get for item '{0}'", Me.Name)
            Return 0
        End Get
        Set
            Console.WriteLine("Position set for item '{0}'", Me.Name)
        End Set
    End Property
End Class

Class Program
    Shared Sub Main()
        Dim item = New Item With {.Name = "Goo"}
        Shift(item)
    End Sub

    Shared Sub Shift(Of T As {Class, IMoveable})(item As T)
        item.Position += GetOffset(item)
    End Sub

    Shared Function GetOffset(Of T)(ByRef item As T) As Integer
        item = DirectCast(DirectCast(New Item With {.Name = "Bar"}, IMoveable), T)
        Return 0
    End Function
End Class

🔗 This code was taken from the following test, which fails only when Roslyn tests are executed with OpenCover.
https://github.com/dotnet/roslyn/blob/e123a4207123d5df8c45fb1caba0fb3acbae0e00/src/Compilers/VisualBasic/Test/Semantic/Semantics/CompoundAssignment.vb#L1094-L1195

@sawilde sawilde added the medium label Jan 1, 2019
@sawilde sawilde added this to To do in OpenCover - Future Jan 6, 2019
@sawilde sawilde added the bug label Feb 11, 2019
@sawilde sawilde added this to the OpenCover 2019 (Qn) milestone Feb 11, 2019
@sawilde
Copy link
Member

sawilde commented Apr 25, 2019

@sharwell I put the above into a normal vb.net program and ran it without OpenCover and the output I got was

C:\projects\support\behaviour\behaviour\bin\Debug>behaviour.exe
Position get for item 'Goo'
Position set for item 'Bar'

Which looks correct to me - again I am not sure what the issue is since from what I can see OpenCover is making the code behave correctly. I suspect what you are trying to test is something broken in Roslyn due to optimizations being applied.

When OpenCover runs it does disable a few runtime options including disabling inlining and any code optimizations - see https://github.com/OpenCover/opencover/blob/master/main/OpenCover.Profiler/CodeCoverage.cpp#L189

@sawilde sawilde removed this from the OpenCover 2019 (Qn) milestone Jan 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Development

No branches or pull requests

2 participants