Skip to content

Make the project function with .Net Framework classes again #286

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

Conversation

glennawatson
Copy link
Contributor

@glennawatson glennawatson commented Jan 7, 2019

This fixes #285, fixes #274 and fixes #272

Changed back to using a .NET Standard project for the coverlet.core. Allows for more targets (eg Xamarin based targets too potentially).

Also do some redirecting of StdError for the process output, xunit for example sends errors there, and put them into the log.

.NET STandard 2.1 adds RelativePath() so using a place holder until that comes out.

@codecov
Copy link

codecov bot commented Jan 7, 2019

Codecov Report

Merging #286 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #286   +/-   ##
=======================================
  Coverage   88.85%   88.85%           
=======================================
  Files          16       16           
  Lines        1875     1875           
=======================================
  Hits         1666     1666           
  Misses        209      209
Impacted Files Coverage Δ
src/coverlet.core/Instrumentation/Instrumenter.cs 98.95% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 54108b6...cd2ec73. Read the comment docs.

@@ -300,5 +300,18 @@ private string GetSourceLinkUrl(Dictionary<string, string> sourceLinkDocuments,
url = sourceLinkDocuments[keyWithBestMatch];
return url.Replace("*", replacement);
}

// This is coming to .NET Standard 2.1 as part of Path
private static string GetRelativePath(string relativeTo, string path)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move this method into a PathHelper class. See diff in this for an example https://github.com/tonerdo/coverlet/compare/remove-netcoreapp-dep?expand=1. That was me taking a stab at fixing this, feel free to ignore the implementation and just follow the structure

Copy link
Collaborator

Choose a reason for hiding this comment

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

Add unit tests as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I started to go through unit tests that the corefx team had and adapting them to my code

https://github.com/dotnet/corefx/blob/a10890f4ffe0fadf090c922578ba0e606ebdd16c/src/System.Runtime.Extensions/tests/System/IO/Path.GetRelativePath.cs

I found that mine didn't handle unix based paths correctly.

The code you had also failed some of those unit tests.

I ended up creating a .netstandard template library which allows the injected template to work in .NET Framework classes.


<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also switch coverlet.msbuild.tasks.csproj back to netstandard2.0

@glennawatson glennawatson force-pushed the glennawatson-netstandard branch from 6433c4b to cd2ec73 Compare January 8, 2019 09:50
@tonerdo
Copy link
Collaborator

tonerdo commented Jan 8, 2019

@glennawatson I'm curious how your new approach fixes this issue. Care to elaborate?

@glennawatson
Copy link
Contributor Author

glennawatson commented Jan 8, 2019

@tonerdo The issue hasn't been that the injected instrumented class (because you've been hiding xunit's outut this has been obscured as part of other people's issues by not pushing out stderror)

For example if I run against a .NET framework I get

System.TypeInitializationException : The type initializer for 'Coverlet.Core.Instrumentation.Tracker.Splat_2a9feed3-781f-482b-b285-66c3c2c3fa3d' threw an exception.
---- System.IO.FileNotFoundException : Could not load file or assembly 'System.Runtime.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Stack Trace:
   at Coverlet.Core.Instrumentation.Tracker.Splat_2a9feed3-781f-482b-b285-66c3c2c3fa3d.RecordHit(Int32 )
   at Splat.TargetFrameworkExtensions.GetTargetFrameworkName(Assembly assembly)
   at Splat.Tests.ApiApprovalTests.CheckApproval(Assembly assembly, String memberName, String filePath) in C:\source\splat\src\Splat.Tests\API\ApiApprovalTests.cs:line 40
   at Splat.Tests.ApiApprovalTests.SplatProject() in C:\source\splat\src\Splat.Tests\API\ApiApprovalTests.cs:line 35
----- Inner Stack Trace -----

The fact that your msbuild task nor the application are .NET core haven't been the issue.

The new approach basically allows cecil to inject the dependencies based on .net standard rather than the .NET core ones.

@glennawatson
Copy link
Contributor Author

Essentially since the new template project is .NET standard when you call Instrumentor.AddCustomModuleTrackerToModule it'll now when copying the field definitions and method definitions now be getting the .NET Standard versions of those copied values.

@glennawatson
Copy link
Contributor Author

@tonerdo Any movement on this one? I can go back to a .net standard approach if you want and go through the work to make the PathHelper class work with sample paths, but this resolves all those issues.

Copy link
Collaborator

@tonerdo tonerdo left a comment

Choose a reason for hiding this comment

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

LGTM!

@tonerdo tonerdo merged commit d4c51c3 into coverlet-coverage:master Jan 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Coverlet 2.5.0 throws Exception Error in Coverlet.Console 1.4.0 Version 2.5.0
2 participants