Skip to content

Add ExcludeFromCodeCoverage attribute on top of generated GitVersionI… #2306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2020

Conversation

odalet
Copy link
Contributor

@odalet odalet commented Jun 1, 2020

…nformation classes

Description

This decorates generated code with ExcludeFromCodeCoverage attribute so that it does not participate in code coverage statistics.

Related Issue

#2305

Motivation and Context

This prevents generated code from being detected as 'not covered'. Generated code should not be part of code coverage statistics.

How Has This Been Tested?

In order to make sure adding this attribute resulted in 100% coverage, I crafted a simple solution with a VB.NET, a C# and a F# project + a unit test. This project is available here: https://github.com/odalet/GitVersionTests

I couldn't achieve 100% coverage on the F# lib and detected a potential issue on the VB project. I describe these below in subsequent comments because I don't really know what way to go with these and then am opening discussions.

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@odalet
Copy link
Contributor Author

odalet commented Jun 1, 2020

So here is the problem with the VB.NET Generated code:
because it is not part of any namespace, it gets generated into the assembly's default namespace, not its 'global' namespace:

image

I suggest to enclose the generated code into this so that it behaves like the C# code:

Namespace Global
... existing class template
End Namespace

This change is not part of this PR because I wonder if I should propose another PR for this

@odalet
Copy link
Contributor Author

odalet commented Jun 1, 2020

Concerning F#, it is a bit more tricky. Modules seem to generate plenty of stuff that is not inheriting the ExcludeFromCodeCoverage attribute:

image

For now, I managed to achieve 100% coverage by changing the F# module into a static class. Something like that:

namespace global

[<AbstractClass; Sealed>]
[<global.System.Runtime.CompilerServices.CompilerGenerated>]
[<global.System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage>]
type GitVersionInformation() =
    static member Major = "1"
    static member Minor = "2"
    static member Patch = "3"
   ...

However, this being quite a big change, I didn't pushed it yet. Waiting for approval here.

…nformation classes

Fix: missing global namespace before attributes
@odalet odalet force-pushed the feature/exclude-from-coverage branch from 1d51f5e to 3efb2ab Compare June 1, 2020 16:07
Copy link
Member

@asbjornu asbjornu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't even know the attribute existed, so this seems like an obvious, low-hanging fruit. Thanks!

@asbjornu asbjornu added this to the 5.3.x milestone Jun 2, 2020
@asbjornu asbjornu merged commit 66dcbb5 into GitTools:master Jun 2, 2020
@odalet
Copy link
Contributor Author

odalet commented Jun 2, 2020

You're welcome! And what about the 2 other issues I mention above? Could you have a look at them?Should I open dedicated issues?

@asbjornu
Copy link
Member

asbjornu commented Jun 2, 2020

Yes, please open one PR per issue. I think both solutions look good, I'm just a bit unsure about the backwards compatibility of them, so let's discuss that in each provided PR.

@odalet
Copy link
Contributor Author

odalet commented Jun 2, 2020

True, both issues may raise compatibility concerns. I'll do just that and open issues when I find some time!

@odalet odalet deleted the feature/exclude-from-coverage branch June 7, 2020 13:28
@github-actions
Copy link

🎉 This issue has been resolved in version 5.3.6 🎉
The release is available on:

Your GitReleaseManager bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants