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

Bumpver #1473

Merged
merged 1 commit into from
May 16, 2023
Merged

Bumpver #1473

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PackageReference Update="Microsoft.Extensions.DependencyModel" Version="2.1.0" />
<PackageReference Update="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Update="Microsoft.Extensions.FileSystemGlobbing" Version="2.0.1" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<!-- https://github.com/coverlet-coverage/coverlet/issues/1042 -->
<PackageReference Update="Microsoft.TestPlatform.ObjectModel" Version="16.9.1" />
<PackageReference Update="Mono.Cecil" Version="0.11.1" />
Expand All @@ -21,8 +21,8 @@
We can check minimum supported package version here https://github.com/Microsoft/vstest/blob/master/src/Microsoft.TestPlatform.ObjectModel/Microsoft.TestPlatform.ObjectModel.csproj#L37
-->
<PackageReference Update="System.Reflection.Metadata" Version="1.5.0" />
<PackageReference Update="xunit" Version="2.4.1" />
<PackageReference Update="xunit.assert" Version="2.4.1" />
<PackageReference Update="xunit" Version="2.4.2" />
<PackageReference Update="xunit.assert" Version="2.4.2" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.4.1"/>
<PackageReference Update="Tmds.ExecFunction" Version="0.4.0" />
</ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions Documentation/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
-Allign published nuget package version to github release version [#1413](https://github.com/coverlet-coverage/coverlet/issues/1413)
-Sync nuget and github release versions [#1122](https://github.com/coverlet-coverage/coverlet/issues/1122)

### Improvements
-Migration of the project to .NET 6.0 [#1473](https://github.com/coverlet-coverage/coverlet/pull/1473)

### Breaking changes
- New parameter `ExcludeAssembliesWithoutSources` to control automatic assembly exclusion [1164](https://github.com/coverlet-coverage/coverlet/issues/1164). The parameter `InstrumentModulesWithoutLocalSources` has been removed. since it can be handled by setting `ExcludeAssembliesWithoutSources` to `None`.
- The default heuristics for determining whether to instrument an assembly has been changed. In previous versions any missing source file was taken as a signal that it was a third-party project that shouldn't be instrumented, with exceptions for some common file name patterns for source generators. Now only assemblies where no source files at all can be found are excluded from instrumentation, and the code for detecting source generator files have been removed. To get back to the behaviour that at least one missing file is sufficient to exclude an assembly, set `ExcludeAssembliesWithoutSources` to `MissingAny`, or use assembly exclusion filters for more fine-grained control.
Expand Down
10 changes: 10 additions & 0 deletions eng/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ steps:
version: 5.0.401
displayName: Install .NET Core SDK 5.0.401

- task: UseDotNet@2
inputs:
version: 6.0.408
displayName: Install .NET Core SDK 6.0.408

- task: UseDotNet@2
inputs:
version: 7.0.203
displayName: Install .NET Core SDK 7.0.203

- script: dotnet restore
displayName: Restore packages

Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "5.0.401",
"version": "6.0.408",
"rollForward": "latestMajor"
}
}
4 changes: 2 additions & 2 deletions src/coverlet.console/coverlet.console.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<ToolCommandName>coverlet</ToolCommandName>
<PackAsTool>true</PackAsTool>
<AssemblyTitle>coverlet.console</AssemblyTitle>
Expand Down
62 changes: 29 additions & 33 deletions src/coverlet.core/Helpers/InstrumentationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,18 @@ public bool HasPdb(string module, out bool embedded)

public bool EmbeddedPortablePdbHasLocalSource(string module, AssemblySearchType excludeAssembliesWithoutSources)
{
using (Stream moduleStream = _fileSystem.OpenRead(module))
using (var peReader = new PEReader(moduleStream))
using Stream moduleStream = _fileSystem.OpenRead(module);
using var peReader = new PEReader(moduleStream);
foreach (DebugDirectoryEntry entry in peReader.ReadDebugDirectory())
{
foreach (DebugDirectoryEntry entry in peReader.ReadDebugDirectory())
if (entry.Type == DebugDirectoryEntryType.EmbeddedPortablePdb)
{
if (entry.Type == DebugDirectoryEntryType.EmbeddedPortablePdb)
{
using MetadataReaderProvider embeddedMetadataProvider = peReader.ReadEmbeddedPortablePdbDebugDirectoryData(entry);
MetadataReader metadataReader = embeddedMetadataProvider.GetMetadataReader();
using MetadataReaderProvider embeddedMetadataProvider = peReader.ReadEmbeddedPortablePdbDebugDirectoryData(entry);
MetadataReader metadataReader = embeddedMetadataProvider.GetMetadataReader();

if (!MatchDocumentsWithSources(module, excludeAssembliesWithoutSources, metadataReader))
{
return false;
}
if (!MatchDocumentsWithSources(module, excludeAssembliesWithoutSources, metadataReader))
{
return false;
}
}
}
Expand All @@ -150,31 +148,29 @@ public bool EmbeddedPortablePdbHasLocalSource(string module, AssemblySearchType

public bool PortablePdbHasLocalSource(string module, AssemblySearchType excludeAssembliesWithoutSources)
{
using (Stream moduleStream = _fileSystem.OpenRead(module))
using (var peReader = new PEReader(moduleStream))
using Stream moduleStream = _fileSystem.OpenRead(module);
using var peReader = new PEReader(moduleStream);
foreach (DebugDirectoryEntry entry in peReader.ReadDebugDirectory())
{
foreach (DebugDirectoryEntry entry in peReader.ReadDebugDirectory())
if (entry.Type == DebugDirectoryEntryType.CodeView)
{
if (entry.Type == DebugDirectoryEntryType.CodeView)
CodeViewDebugDirectoryData codeViewData = peReader.ReadCodeViewDebugDirectoryData(entry);
using Stream pdbStream = _fileSystem.OpenRead(_sourceRootTranslator.ResolveFilePath(codeViewData.Path));
using var metadataReaderProvider = MetadataReaderProvider.FromPortablePdbStream(pdbStream);
MetadataReader metadataReader = null;
try
{
metadataReader = metadataReaderProvider.GetMetadataReader();
}
catch (BadImageFormatException)
{
_logger.LogWarning($"{nameof(BadImageFormatException)} during MetadataReaderProvider.FromPortablePdbStream in InstrumentationHelper.PortablePdbHasLocalSource, unable to check if module has got local source.");
return true;
}

if (!MatchDocumentsWithSources(module, excludeAssembliesWithoutSources, metadataReader))
{
CodeViewDebugDirectoryData codeViewData = peReader.ReadCodeViewDebugDirectoryData(entry);
using Stream pdbStream = _fileSystem.OpenRead(_sourceRootTranslator.ResolveFilePath(codeViewData.Path));
using var metadataReaderProvider = MetadataReaderProvider.FromPortablePdbStream(pdbStream);
MetadataReader metadataReader = null;
try
{
metadataReader = metadataReaderProvider.GetMetadataReader();
}
catch (BadImageFormatException)
{
_logger.LogWarning($"{nameof(BadImageFormatException)} during MetadataReaderProvider.FromPortablePdbStream in InstrumentationHelper.PortablePdbHasLocalSource, unable to check if module has got local source.");
return true;
}

if (!MatchDocumentsWithSources(module, excludeAssembliesWithoutSources, metadataReader))
{
return false;
}
return false;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="$(RepoRoot)src\coverlet.msbuild.tasks\coverlet.msbuild.props" />

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
<Import Project="$(RepoRoot)src\coverlet.msbuild.tasks\coverlet.msbuild.props" />

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions test/coverlet.core.tests/Instrumentation/InstrumenterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,11 @@ public void CanInstrumentFSharpAssemblyWithAnonymousRecord()
string sample = Directory.GetFiles(Directory.GetCurrentDirectory(), "coverlet.tests.projectsample.fsharp.dll").First();
var instrumentationHelper =
new InstrumentationHelper(new ProcessExitHandler(), new RetryHelper(), new FileSystem(), new Mock<ILogger>().Object,
new SourceRootTranslator(sample, new Mock<ILogger>().Object, new FileSystem(), new AssemblyAdapter()));
new SourceRootTranslator(Assembly.GetExecutingAssembly().Location, new Mock<ILogger>().Object, new FileSystem(), new AssemblyAdapter()));

var instrumenter = new Instrumenter(sample, "_coverlet_tests_projectsample_fsharp", new CoverageParameters(), loggerMock.Object, instrumentationHelper,
new FileSystem(), new SourceRootTranslator(sample, loggerMock.Object, new FileSystem(), new AssemblyAdapter()), new CecilSymbolHelper());

new FileSystem(), new SourceRootTranslator(Assembly.GetExecutingAssembly().Location, loggerMock.Object, new FileSystem(), new AssemblyAdapter()), new CecilSymbolHelper());
Assert.True(instrumentationHelper.HasPdb(sample, out bool embedded));
Assert.False(embedded);
Assert.True(instrumenter.CanInstrument());
Expand Down
2 changes: 1 addition & 1 deletion test/coverlet.core.tests/coverlet.core.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="$(RepoRoot)src\coverlet.msbuild.tasks\coverlet.msbuild.props" />

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
<NoWarn>$(NoWarn);CS8002</NoWarn>
<MSBuildWarningsAsMessages>NU1702</MSBuildWarningsAsMessages>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="$(MSBuildThisFileDirectory)\DeterministicTest.props" />

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
<AssemblyName>coverletsample.integration.determisticbuild</AssemblyName>
<RestoreSources>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
<AssemblyName>coverletsamplelib.integration.template</AssemblyName>
<IsTestProject>false</IsTestProject>
Expand All @@ -10,8 +10,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1"/>
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1"/>
</ItemGroup>

</Project>
16 changes: 9 additions & 7 deletions test/coverlet.integration.tests/BaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private protected string GetPackageVersion(string filter)
}
}

private protected ClonedTemplateProject CloneTemplateProject(bool cleanupOnDispose = true, string testSDKVersion = "16.5.0")
private protected ClonedTemplateProject CloneTemplateProject(bool cleanupOnDispose = true, string testSDKVersion = "17.5.0")
{
DirectoryInfo finalRoot = Directory.CreateDirectory($"{Guid.NewGuid().ToString("N")[..6]}{Interlocked.Increment(ref s_folderSuffix)}");
foreach (string file in (Directory.GetFiles($"../../../../coverlet.integration.template", "*.cs")
Expand Down Expand Up @@ -248,12 +248,14 @@ private protected void AssertCoverage(ClonedTemplateProject clonedTemplateProjec
bool coverageChecked = false;
foreach (string coverageFile in clonedTemplateProject.GetFiles(filter))
{
JsonConvert.DeserializeObject<Modules>(File.ReadAllText(coverageFile))
.Document("DeepThought.cs")
.Class("Coverlet.Integration.Template.DeepThought")
.Method("System.Int32 Coverlet.Integration.Template.DeepThought::AnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything()")
.AssertLinesCovered((6, 1), (7, 1), (8, 1));
coverageChecked = true;
Classes? document = JsonConvert.DeserializeObject<Modules>(File.ReadAllText(coverageFile))?.Document("DeepThought.cs");
if (document != null)
{
document.Class("Coverlet.Integration.Template.DeepThought")
.Method("System.Int32 Coverlet.Integration.Template.DeepThought::AnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything()")
.AssertLinesCovered((6, 1), (7, 1), (8, 1));
coverageChecked = true;
}
}

Assert.True(coverageChecked, $"Coverage check fail\n{standardOutput}");
Expand Down
16 changes: 9 additions & 7 deletions test/coverlet.integration.tests/DeterministicBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ private protected void AssertCoverage(string standardOutput = "", bool checkDete
string reportFilePath = "";
foreach (string coverageFile in Directory.GetFiles(_testProjectPath, "coverage.json", SearchOption.AllDirectories))
{
JsonConvert.DeserializeObject<Modules>(File.ReadAllText(coverageFile))
.Document("DeepThought.cs")
.Class("Coverlet.Integration.DeterministicBuild.DeepThought")
.Method("System.Int32 Coverlet.Integration.DeterministicBuild.DeepThought::AnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything()")
.AssertLinesCovered((6, 1), (7, 1), (8, 1));
coverageChecked = true;
reportFilePath = coverageFile;
Classes? document = JsonConvert.DeserializeObject<Modules>(File.ReadAllText(coverageFile))?.Document("DeepThought.cs");
if (document != null)
{
document.Class("Coverlet.Integration.DeterministicBuild.DeepThought")
.Method("System.Int32 Coverlet.Integration.DeterministicBuild.DeepThought::AnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything()")
.AssertLinesCovered((6, 1), (7, 1), (8, 1));
coverageChecked = true;
reportFilePath = coverageFile;
}
}
Assert.True(coverageChecked, $"Coverage check fail\n{standardOutput}");
File.Delete(reportFilePath);
Expand Down
Loading