Skip to content
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

Skip fsharp construct with unknown source #1165

Merged

Conversation

daveMueller
Copy link
Collaborator

closes #1145

Comment on lines 122 to 130
Document document = metadataReader.GetDocument(docHandle);
string docName = _sourceRootTranslator.ResolveFilePath(metadataReader.GetString(document.Name));

Guid languageGuid = metadataReader.GetGuid(document.Language);
// We verify all docs and return false if not all are present in local
// We could have false negative if doc is not a source
// Btw check for all possible extension could be weak approach
// We exlude from the check the autogenerated source file(i.e. source generators)
if (!_fileSystem.Exists(docName) && !docName.EndsWith(".g.cs"))
// We exclude from the check the autogenerated source file(i.e. source generators)
// We exclude special F# construct https://github.com/coverlet-coverage/coverlet/issues/1145
if (!_fileSystem.Exists(docName) && !docName.EndsWith(".g.cs") && !IsUnknownModuleInFSharpAssembly(languageGuid, docName))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This logic could be extracted into a method, since it is identical with the logic in PortablePdbHasLocalSource. This helps if we need to add even more exceptions, e.g. for the null documents in VB (#1073).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, done.

Copy link
Collaborator

@MarcoRossignoli MarcoRossignoli left a comment

Choose a reason for hiding this comment

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

Some nits but here we go thx a lot!

<Choose>
<When Condition="$(MSBuildProjectName)!='coverlet.tests.projectsample.fsharp'">
<PropertyGroup>
<IsTestProject>true</IsTestProject>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you force false directly on new project coverlet.tests.projectsample.fsharp.fsproj ?
Or in future we need to add every time projects here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes sorry didn't think about this. I was getting a error when dotnet test the fsharp project and I didn't know why.
image
Took me a good amount of time to figure out it is the Directory.Build.pros. The other c# class library projects don't have this issue even when <IsTestProject>true</IsTestProject>. Seems to be a fsharp issue.

using Moq;
using Coverlet.Core.Abstractions;

namespace Coverlet.Core.Helpers.Tests
{
public class InstrumentationHelperTests
{
private readonly InstrumentationHelper _instrumentationHelper =
private InstrumentationHelper _instrumentationHelper =
Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer keep this readonly and define new one only for that test wdym?
Like you did in CanInstrumentFSharpAssemblyWithAnonymousRecord

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@MarcoRossignoli MarcoRossignoli added the bug Something isn't working label May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Coverlet fails to instrument F# projects that have "unknown" source (inline functions, anonymous records etc)
3 participants