-
Notifications
You must be signed in to change notification settings - Fork 325
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
Coverlet in-process collector is not loaded for version > 1.0.0 #2221
Changes from 7 commits
1e3b893
ace24d7
c4a4f72
1fdba7f
99c243b
a165d0f
d72bbeb
6b86187
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ namespace TestPlatform.CrossPlatEngine.UnitTests.DataCollection | |
{ | ||
using System.IO; | ||
using System.Reflection; | ||
|
||
using Coverlet.Collector.DataCollection; | ||
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection; | ||
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.Interfaces; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; | ||
|
@@ -64,7 +64,7 @@ public void InProcDataCollectorShouldNotThrowExceptionIfAssemblyDoesNotContainAn | |
public void InProcDataCollectorShouldInitializeIfAssemblyContainsAnyInProcDataCollector() | ||
{ | ||
var typeInfo = typeof(TestableInProcDataCollector).GetTypeInfo(); | ||
|
||
this.assemblyLoadContext.Setup(alc => alc.LoadAssemblyFromPath(It.IsAny<string>())) | ||
.Returns(typeInfo.Assembly); | ||
|
||
|
@@ -79,6 +79,27 @@ public void InProcDataCollectorShouldInitializeIfAssemblyContainsAnyInProcDataCo | |
Assert.AreEqual(this.inProcDataCollector.AssemblyQualifiedName, typeInfo.AssemblyQualifiedName); | ||
} | ||
|
||
[TestMethod] | ||
public void InProcDataCollectorLoadCoverlet() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test verify that also if aqn shows version 1.0.0.0 we correctly load a version 9.9.9.9 of lib |
||
{ | ||
var typeInfo = typeof(CoverletInProcDataCollector).GetTypeInfo(); | ||
|
||
Assert.AreEqual("9.9.9.9", typeInfo.Assembly.GetName().Version.ToString()); | ||
|
||
this.assemblyLoadContext.Setup(alc => alc.LoadAssemblyFromPath(It.IsAny<string>())) | ||
.Returns(typeInfo.Assembly); | ||
|
||
this.inProcDataCollector = new InProcDataCollector( | ||
typeInfo.Assembly.Location, | ||
"Coverlet.Collector.DataCollection.CoverletInProcDataCollector, coverlet.collector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", | ||
typeof(InProcDataCollection).GetTypeInfo(), | ||
string.Empty, | ||
this.assemblyLoadContext.Object); | ||
|
||
Assert.IsNotNull(this.inProcDataCollector.AssemblyQualifiedName); | ||
Assert.AreEqual(this.inProcDataCollector.AssemblyQualifiedName, typeInfo.AssemblyQualifiedName); | ||
} | ||
|
||
private class TestableInProcDataCollector : InProcDataCollection | ||
{ | ||
public void Initialize(IDataCollectionSink dataCollectionSink) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Reflection; | ||
using System; | ||
|
||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollector.InProcDataCollector; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.InProcDataCollector; | ||
|
||
[assembly: AssemblyKeyFile("key.snk")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this key file for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mainly 2 reason
|
||
[assembly: AssemblyVersion("9.9.9.9")] | ||
|
||
namespace Coverlet.Collector.DataCollection | ||
{ | ||
// This class MUST have the same full name as | ||
// https://github.com/tonerdo/coverlet/blob/master/src/coverlet.collector/InProcDataCollection/CoverletInProcDataCollector.cs | ||
// to mimic real behaviour | ||
public class CoverletInProcDataCollector : InProcDataCollection | ||
{ | ||
public void Initialize(IDataCollectionSink dataCollectionSink) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void TestCaseEnd(TestCaseEndArgs testCaseEndArgs) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void TestCaseStart(TestCaseStartArgs testCaseStartArgs) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void TestSessionEnd(TestSessionEndArgs testSessionEndArgs) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void TestSessionStart(TestSessionStartArgs testSessionStartArgs) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netcoreapp2.1;net451</TargetFrameworks> | ||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\Microsoft.TestPlatform.ObjectModel\Microsoft.TestPlatform.ObjectModel.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mayankbansal018 Should we make this default ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think no, If I'm not mistaken that aqn is read from possible runsetting file so a user should have that assembly in local folder. The issue with coverlet is that we(you) inject hardcoded aqn if user provide
--collect:"XPlat Code Coverage"
.It works well for user provided collectors because there is always a runsettings file provided, but with coverlet don't, so we need a way to make it works for every version without runsettings file.
So my idea is to check only "trusted" type/lib name only for coverlet.
BTW I could miss something in the big picture.