Skip to content

Commit

Permalink
use TargetFrameworks net6.0;net7.0 for tests (#1544)
Browse files Browse the repository at this point in the history
* update dependencies (System.Text.Json)

* use <TargetFrameworks>net6.0;net7.0</TargetFrameworks> for tests

* do not use deprecated versions

* update net SDK versions

* remove unnecessary assert

* execute coverlet.core tests only for net6.0

* add CheckNugetStatus.yml and fix findings

* fix variable name

* update and consolidate versions

* upload *.diag.log files
  • Loading branch information
Bertk authored Nov 3, 2023
1 parent 91acb45 commit c62fe09
Show file tree
Hide file tree
Showing 17 changed files with 180 additions and 74 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,5 @@ test/coverlet.integration.determisticbuild/runsettings

coverage.cobertura.xml
coverage.opencover.xml
coverage.*.cobertura.xml
coverage.*.opencover.xml
2 changes: 0 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
<SystemReflectionMetadataVersion>1.6.0</SystemReflectionMetadataVersion>
<SystemCollectionsImmutableVersion>1.5.0</SystemCollectionsImmutableVersion>
<MicrosoftBuildUtilitiesCorePackageVersion>15.9.20</MicrosoftBuildUtilitiesCorePackageVersion>
<MicrosoftExtensionsDependencyModelPackageVersion>3.0.0</MicrosoftExtensionsDependencyModelPackageVersion>
<MicrosoftExtensionsFileSystemGlobbingVersion>2.0.0</MicrosoftExtensionsFileSystemGlobbingVersion>
</PropertyGroup>

</Project>
22 changes: 13 additions & 9 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
</PropertyGroup>

<ItemGroup>
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.6.133" />
</ItemGroup>

<ItemGroup>
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="7.0.0" />
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="17.5.0"/>
<PackageVersion Include="Microsoft.Build.Framework" Version="17.5.0"/>
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="17.5.0" />
<PackageVersion Include="Microsoft.Build.Framework" Version="17.5.0" />
<PackageVersion Include="Microsoft.Build.Locator" Version="1.5.5" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="2.10.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyModel" Version="7.0.0" />
Expand All @@ -31,12 +29,12 @@
vstest 17.8 version
NuGetFrameworksVersion is defined here https://github.com/microsoft/vstest/blob/9a0c41811637edf4afe0e265e08fdd1cb18109ed/eng/Versions.props#L94C1-L94C1
-->
<PackageVersion Include="NuGet.Frameworks" Version="6.5.0" />
<PackageVersion Include="NuGet.Frameworks" Version="6.6.1" />
<PackageVersion Include="NuGet.Packaging" Version="6.5.0" />
<PackageVersion Include="Mono.Cecil" Version="0.11.5" />
<PackageVersion Include="Moq" Version="4.18.4" />
<PackageVersion Include="Moq" Version="4.20.69" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.1" />
<PackageVersion Include="ReportGenerator.Core" Version="5.1.23" />
<PackageVersion Include="ReportGenerator.Core" Version="5.1.26" />
<!--For test issue 809 https://github.com/coverlet-coverage/coverlet/issues/809-->
<PackageVersion Include="LinqKit.Microsoft.EntityFrameworkCore" Version="7.1.4" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
Expand All @@ -58,7 +56,13 @@
<PackageVersion Include="xunit" Version="2.5.3" />
<PackageVersion Include="xunit.assemblyfixture" Version="2.2.0" />
<PackageVersion Include="xunit.assert" Version="2.5.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.3"/>
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageVersion Include="envdte" Version="17.7.37355" />
<PackageVersion Include="System.Buffers" Version="4.5.1" />
<PackageVersion Include="System.Memory" Version="4.5.5" />
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="System.Security.Cryptography.Pkcs" Version="6.0.4" />
<PackageVersion Include="System.Text.Encoding.CodePages" Version="6.0.0" />
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
</ItemGroup>
</Project>
</Project>
69 changes: 69 additions & 0 deletions eng/CheckNugetStatus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# File: CheckNugetStatus.yml
# the template will write lists of outdated, deprecated or vulnerable nuget packages to build log for every C# project. If a deprecated or vulnerable package is detected, an error will be written to the build log.
# Precondition: restore and build was executed before this template is used
# Limitation: dotnet SDK does not provide .NET framework MSBuild targets like "Microsoft.WebApplication.targets". This c# projects will be ignored and "An error occurred for <file name of C# project>" message is added in build log.

parameters:
condition: 'succeeded()'
enableQualitySteps: true
sourcePath: ''
nugetConfig: ''
breakBuild: false

steps:
- task: NuGetAuthenticate@0
condition: ${{parameters.condition}}
enabled: ${{parameters.enableQualitySteps}}

- task: PowerShell@2
displayName: 'Check nuget package status'
inputs:
targetType: 'inline'
pwsh: true
script: |
Write-Information -MessageData "sourcePath='${{parameters.sourcePath}}'" -InformationAction Continue
Write-Information -MessageData "nugetConfig='${{parameters.nugetConfig}}'" -InformationAction Continue
Write-Information -MessageData "#########################################" -InformationAction Continue
if (!(Test-Path "${{parameters.sourcePath}}" -PathType Container)) {
Write-Host "##vso[task.LogIssue type=error;]sourcePath does not exist."
}
$existsDeprecatedPackage = $false
$existsVulnerablePackage = $false
$projectFiles = Get-ChildItem -Path ${{parameters.sourcePath}} -Filter *.csproj -Recurse
foreach ($project in $projectFiles) {
try {
$outdatedList = dotnet list $project package --outdated --include-transitive --source https://api.nuget.org/v3/index.json
if ($LASTEXITCODE -gt 0) {
Throw "The command exited with error code: $lastexitcode"
}
$outdatedList
$deprecatedList = dotnet list $project package --deprecated --include-transitive --source https://api.nuget.org/v3/index.json
if ($deprecatedList.Length -gt 5) {
$deprecatedList
$existsDeprecatedPackage = $true
} else {
$deprecatedList[4]
}
$vulnerableList = dotnet list $project package --vulnerable --source https://api.nuget.org/v3/index.json
if ($vulnerableList.Length -gt 5) {
$vulnerableList
$existsVulnerablePackage = $true
} else {
$vulnerableList[4]
}
} catch { "An error occurred for $($project.PSChildName)" }
}
if ( $existsDeprecatedPackage -or $existsVulnerablePackage) {
Write-Host "##vso[task.LogIssue type=error;]Detected nuget package: Deprecated = $existsDeprecatedPackage, Vulnerable = $existsVulnerablePackage"
if ("${{parameters.breakBuild}}" -eq "true") {
exit 42
}
} else {
Write-Information -MessageData "Did not detected deprecated or vulnerable nuget package." -InformationAction Continue
}
exit 0
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
condition: ${{parameters.condition}}
enabled: ${{parameters.enableQualitySteps}}
8 changes: 4 additions & 4 deletions eng/azure-pipelines-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ pool:
steps:
- task: UseDotNet@2
inputs:
version: 6.0.415
displayName: Install .NET Core SDK 6.0.415
version: 6.0.416
displayName: Install .NET Core SDK 6.0.416

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

- task: NuGetAuthenticate@0
displayName: Authenticate with NuGet feeds
Expand Down
5 changes: 5 additions & 0 deletions eng/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ jobs:
ArtifactName: Packages
publishLocation: Container
condition: eq(variables['BuildConfiguration'], 'Release')
- template: CheckNugetStatus.yml
parameters:
sourcePath: '$(Build.SourcesDirectory)/src'
breakBuild: false
# nugetConfig: '$(Build.SourcesDirectory)/nuget.config'

- job: macOS
displayName: macOS
Expand Down
31 changes: 17 additions & 14 deletions eng/build.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
steps:
- task: UseDotNet@2
inputs:
version: 6.0.415
displayName: Install .NET Core SDK 6.0.415
version: 6.0.416
displayName: Install .NET Core SDK 6.0.416

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

- script: dotnet restore
displayName: Restore packages
Expand All @@ -18,23 +18,26 @@ steps:
- script: dotnet pack -c $(BuildConfiguration) --no-restore
displayName: Pack

- task: DotNetCoreCLI@2
- script: |
dotnet test test/coverlet.collector.tests/coverlet.collector.tests.csproj -c $(BuildConfiguration) --no-build -bl:test.collector.binlog --results-directory:"$(Build.SourcesDirectory)\artifacts\Reports" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.xunit.extensions]*%2c[coverlet.tests.projectsample]*" --diag:"$(Build.SourcesDirectory)\artifacts\log\$(buildConfiguration)\coverlet.collector.test.diag.log;tracelevel=verbose"
dotnet test test/coverlet.core.tests/coverlet.core.tests.csproj -c $(BuildConfiguration) --no-build -bl:test.core.binlog --results-directory:"$(Build.SourcesDirectory)\artifacts\Reports" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.xunit.extensions]*%2c[coverlet.tests.projectsample]*" --diag:"$(Build.SourcesDirectory)\artifacts\log\$(buildConfiguration)\coverlet.core.test.diag.log;tracelevel=verbose"
dotnet test test/coverlet.integration.tests/coverlet.integration.tests.csproj -c $(BuildConfiguration) --no-build -bl:test.integration.binlog --results-directory:"$(Build.SourcesDirectory)\artifacts\Reports" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.xunit.extensions]*%2c[coverlet.tests.projectsample]*" --diag:"$(Build.SourcesDirectory)\artifacts\log\$(buildConfiguration)\coverlet.integration.test.diag.log;tracelevel=verbose"
dotnet test test/coverlet.msbuild.tasks.tests/coverlet.msbuild.tasks.tests.csproj -c $(BuildConfiguration) --no-build -bl:test.msbuild.binlog --results-directory:"$(Build.SourcesDirectory)\artifacts\Reports" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.xunit.extensions]*%2c[coverlet.tests.projectsample]*" --diag:"$(Build.SourcesDirectory)\artifacts\log\$(buildConfiguration)\coverlet.msbuild.test.diag.log;tracelevel=verbose"
displayName: Run tests with coverage

- task: PublishTestResults@2
inputs:
command: test
projects: |
**/coverlet.collector.tests.csproj
**/coverlet.core.tests.csproj
**/coverlet.integration.tests.csproj
**/coverlet.msbuild.tasks.tests.csproj
arguments: -c $(BuildConfiguration) --no-build -bl:test.binlog /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.xunit.extensions]*%2c[coverlet.tests.projectsample]*" --diag:"$(Build.SourcesDirectory)\artifacts\log\$(Configuration)\coverlet.test.diag.log;tracelevel=verbose"
testRunTitle: $(Agent.JobName)
testResultsFormat: 'VSTest'
testResultsFiles: '**/*.trx'
mergeTestResults: false
publishRunAttachments: true


- template: publish-coverlet-result-files.yml

- template: publish-coverage-results.yml
parameters:
reports: $(Build.SourcesDirectory)/**/coverage.opencover.xml
reports: $(Build.SourcesDirectory)/**/*.opencover.xml
condition: and(succeeded(), eq(variables['BuildConfiguration'], 'Debug'))
assemblyfilters: '-xunit;-coverlet.testsubject;-Coverlet.Tests.ProjectSample.*'
classfilters: '-[coverlet.core.tests.samples.netstandard]*;-[coverlet.tests.xunit.extensions]*'
14 changes: 8 additions & 6 deletions eng/publish-coverlet-result-files.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
steps:
- task: CopyFiles@2
displayName: Copy tests results
displayName: Copy test results
continueOnError: true
condition: always()
inputs:
SourceFolder: '$(Build.SourcesDirectory)'
Contents: |
**/*.trx
**/*.html
**/coverage.opencover.xml
**/coverage.cobertura.xml
**/coverage.json
**/*.opencover.xml
**/*.cobertura.xml
**/*.coverage.json
**/log.txt
**/log.datacollector.*.txt
**/log.host.*.txt
Expand All @@ -25,11 +25,13 @@ steps:
TargetFolder: '$(Build.SourcesDirectory)/artifacts/TestLogs'

- task: CopyFiles@2
displayName: Copy binlog files
displayName: Copy log files
condition: always()
inputs:
SourceFolder: '$(Build.SourcesDirectory)'
Contents: '**/*.binlog'
Contents: |
**/*.diag.log
**/*.binlog
TargetFolder: '$(Build.SourcesDirectory)/artifacts/TestLogs/BuildLogs'

- task: PublishPipelineArtifact@1
Expand Down
4 changes: 2 additions & 2 deletions src/coverlet.core/coverlet.core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyModel" VersionOverride="$(MicrosoftExtensionsDependencyModelPackageVersion)"/>
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" VersionOverride="$(MicrosoftExtensionsFileSystemGlobbingVersion)" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" VersionOverride="6.0.0"/>
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" VersionOverride="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" VersionOverride="6.0.1"/>
<PackageReference Include="Mono.Cecil" />
<PackageReference Include="System.Reflection.Metadata" VersionOverride="$(SystemReflectionMetadataVersion)" />
Expand Down
4 changes: 2 additions & 2 deletions src/coverlet.msbuild.tasks/coverlet.msbuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</ItemGroup>
</Target>

<Target Name="InstrumentModules">
<Target Name="InstrumentModules" Condition="'$(TargetPath)' != ''">
<Coverlet.MSbuild.Tasks.InstrumentationTask
Path="$(TargetPath)"
Include="$(Include)"
Expand Down Expand Up @@ -65,7 +65,7 @@
DependsOnTargets="InstrumentModules"
Condition="'$(VSTestNoBuild)' != 'true' and '$(CollectCoverage)' == 'true'" />

<Target Name="GenerateCoverageResult">
<Target Name="GenerateCoverageResult" Condition="'$(InstrumenterState)' != ''">
<PropertyGroup>
<_coverletMultiTargetFrameworksCurrentTFM Condition="'$(TargetFrameworks)' != ''" >$(TargetFramework)</_coverletMultiTargetFrameworksCurrentTFM>
</PropertyGroup>
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>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
8 changes: 6 additions & 2 deletions test/coverlet.core.tests/coverlet.core.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.10.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="ReportGenerator.Core" Version="5.1.23" />
<PackageReference Include="Moq" Version="4.20.69" />
<PackageReference Include="ReportGenerator.Core" Version="5.1.26" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="Tmds.ExecFunction" Version="0.6.0" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Collections.Immutable" Version="6.0.0" />
<PackageReference Include="System.Buffers" Version="4.5.1" />
<PackageReference Include="System.Memory" Version="4.5.5" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
</PropertyGroup>

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

</Project>
Loading

0 comments on commit c62fe09

Please sign in to comment.