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

Establish Code Coverage for wpf #10514

Merged
merged 5 commits into from
Feb 27, 2025
Merged
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
2 changes: 1 addition & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
<Import Sdk="Microsoft.DotNet.Arcade.Wpf.Sdk"
Project="Sdk.targets"
Condition="!Exists('$(WpfArcadeSdkProps)') Or !Exists('$(WpfArcadeSdkTargets)')"/>

<Import Project="eng/Testing.targets"/>
</Project>
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Windows Presentation Foundation (WPF)
[![.NET Foundation](https://img.shields.io/badge/.NET%20Foundation-blueviolet.svg)](https://www.dotnetfoundation.org/)
[![Build Status](https://dnceng.visualstudio.com/public/_apis/build/status/dotnet/wpf/dotnet-wpf%20CI)](https://dnceng.visualstudio.com/public/_build/latest?definitionId=270)
[![codecov](https://codecov.io/gh/dotnet/wpf/branch/main/graph/badge.svg?flag=production)](https://codecov.io/gh/dotnet/wpf)
[![MIT License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/dotnet/wpf/blob/main/LICENSE.TXT)

Windows Presentation Foundation (WPF) is a UI framework for building Windows desktop applications.
Expand Down
25 changes: 25 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# https://docs.codecov.io/docs/codecov-yaml
# https://github.com/codecov/support/wiki/Codecov-Yaml

coverage:
range: 20..80 # 20 is red, 80 is green
round: down # always round down
precision: 5 # highest level of decimal precision
status:
project:
default: false
patch:
default: false
fixes:
- "eng/::/"

comment:
layout: "diff, flags" # coverage difference, flags below

flags: # which files to include in the reporting
production:
paths:
- src/Microsoft.DotNet.Wpf/src
test:
paths:
- src/Microsoft.DotNet.Wpf/tests/
40 changes: 40 additions & 0 deletions eng/CodeCoverage.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<Project DefaultTargets="Codecov">
<PropertyGroup>
<Language>C#</Language>
</PropertyGroup>

<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.props" />

<PropertyGroup>
<!-- We need to specify a framework in order for the Restore target to work -->
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Codecov" Version="$(CodecovVersion)" GeneratePathProperty="true" />
<PackageReference Include="ReportGenerator" Version="$(ReportGeneratorVersion)" GeneratePathProperty="true" />
</ItemGroup>
<Target Name="Codecov">
<PropertyGroup>
<_CodecovPath>$(NuGetPackageRoot)codecov\$(CodecovVersion)\tools\Codecov.exe</_CodecovPath>
<_ReportGeneratorPath>$(NuGetPackageRoot)reportgenerator\$(ReportGeneratorVersion)\tools\net47\ReportGenerator.exe</_ReportGeneratorPath>
</PropertyGroup>

<Message Importance="high" Text="&quot;$(_ReportGeneratorPath)&quot; -reports:$(ArtifactsDir)TestResults\**\coverage.opencover.xml -targetdir:$(ArtifactsDir)coverage -reporttypes:Cobertura" />
<Exec Command="&quot;$(_ReportGeneratorPath)&quot; -reports:$(ArtifactsDir)TestResults\**\coverage.opencover.xml -targetdir:$(ArtifactsDir)coverage -reporttypes:Cobertura" />

<ItemGroup>
<_CodecovArgs Include="-f;$(ArtifactsDir)coverage\Cobertura.xml" />

<!-- Report an error if the upload fails (currently disabled due to reliability issues) -->
<_CodecovArgs Include="--required" Condition="'False' == ''" />

<_CodecovFlags Include="$(Configuration)" Condition="'$(Configuration)' != ''" />
</ItemGroup>

<Message Importance="high" Text="&quot;$(_CodecovPath)&quot; @(_CodecovArgs, ' ') --flag @(_CodecovFlags, ',')" />
<Exec Command="&quot;$(_CodecovPath)&quot; @(_CodecovArgs, ' ') --flag @(_CodecovFlags, ',')" />
</Target>

<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />
</Project>
21 changes: 21 additions & 0 deletions eng/CodeCoverage.runsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<Format>opencover</Format>

<!-- https://github.com/tonerdo/coverlet/issues/618 -->
<IncludeTestAssembly>true</IncludeTestAssembly>

<SingleHit>true</SingleHit>
<Include></Include>
<Exclude></Exclude>
<ExcludeByAttribute>ExcludeFromCodeCoverage</ExcludeByAttribute>
<ExcludeByFile></ExcludeByFile>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
21 changes: 21 additions & 0 deletions eng/Testing.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project>
<!-- Set code coverage properties that reference properties not available in Directory.Build.props -->
<PropertyGroup Condition="'$(Coverage)' == 'true'">
<CoverletOutput>$(TargetDir)coverage\$(MSBuildProjectName).coverage</CoverletOutput>
<!-- https://github.com/tonerdo/coverlet/issues/363 -->
<DeterministicSourcePaths>false</DeterministicSourcePaths>
</PropertyGroup>

<PropertyGroup Condition="'$(IsTestProject)' == 'true'">
<TestRunnerAdditionalArguments>$(TestRunnerAdditionalArguments) --blame</TestRunnerAdditionalArguments>
<TestRunnerAdditionalArguments>$(TestRunnerAdditionalArguments) --blame-hang-dump-type full</TestRunnerAdditionalArguments>
<TestRunnerAdditionalArguments>$(TestRunnerAdditionalArguments) --blame-hang-timeout 10min</TestRunnerAdditionalArguments>
<TestRunnerAdditionalArguments>$(TestRunnerAdditionalArguments) --blame-crash-dump-type full</TestRunnerAdditionalArguments>
</PropertyGroup>

<PropertyGroup Condition="'$(IsTestProject)' == 'true' AND '$(Coverage)' == 'true'">
<TestRunnerAdditionalArguments>$(TestRunnerAdditionalArguments) --collect:"XPlat Code Coverage"</TestRunnerAdditionalArguments>
<TestRunnerAdditionalArguments>$(TestRunnerAdditionalArguments) --test-adapter-path "$(Pkgcoverlet_collector)/build/netstandard1.0"</TestRunnerAdditionalArguments>
<TestRunnerAdditionalArguments>$(TestRunnerAdditionalArguments) --settings "$(RepoRoot)/eng/CodeCoverage.runsettings"</TestRunnerAdditionalArguments>
</PropertyGroup>
</Project>
4 changes: 3 additions & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<PreReleaseVersionLabel>preview</PreReleaseVersionLabel>
<PreReleaseVersionIteration>3</PreReleaseVersionIteration>
<VersionPrefix>$(MajorVersion).$(MinorVersion).$(PatchVersion)</VersionPrefix>
<UseVSTestRunner>true</UseVSTestRunner>
<!--
Set assembly version to align with major and minor version, as for the patches and revisions should be manually
updated per assembly if it is serviced.
Expand Down Expand Up @@ -104,7 +105,8 @@
<!-- Code Coverage -->
<PropertyGroup>
<CoverletMSBuildPackageVersion>3.1.2</CoverletMSBuildPackageVersion>
<CodecovVersion>1.9.0</CodecovVersion>
<CodecovVersion>1.12.3</CodecovVersion>
<CoverletVersion>3.1.2</CoverletVersion>
<ReportGeneratorVersion>4.0.9</ReportGeneratorVersion>
</PropertyGroup>
<!-- External Analyzers -->
Expand Down
21 changes: 13 additions & 8 deletions eng/pipeline-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ jobs:
${{ if eq(parameters.runAsPublic, 'true') }}:
Build_Debug_x64:
_BuildConfig: Debug
_Coverage: true
# override some variables for debug
# _SignType has to be real for package publishing to succeed - do not override to test.
_Platform: x64
Expand Down Expand Up @@ -174,6 +175,7 @@ jobs:
$(_OfficialBuildIdArgs)
$(_PlatformArgs)
$(_InternalRuntimeDownloadArgs)
/p:Coverage=$(_Coverage)
displayName: Windows Build / Publish
# This condition should be kept in sync with the condition for 'Run DRTs' step
# When building on a regular pipeline (!_HelixPipeline), build as usual
Expand All @@ -191,19 +193,22 @@ jobs:
$(_PlatformArgs)
$(_InternalRuntimeDownloadArgs)
/bl:$(Build.SourcesDirectory)\artifacts\log\$(_BuildConfig)\Test.binlog
/p:Coverage=$(_Coverage)
displayName: Run xUnit Tests
condition: and(or(ne(variables['_HelixPipeline'], 'true'), and(eq(variables['_HelixPipeline'], 'true') ,eq(variables['_BuildConfig'], 'Release'), eq(variables['_PublicBuildPipeline'], 'true'), eq(variables['_ContinuousIntegrationTestsEnabled'], 'true'))), ne(variables['_Platform'], 'arm64'))
condition: and(or(ne(variables['_HelixPipeline'], 'true'), and(eq(variables['_HelixPipeline'], 'true'), eq(variables['_PublicBuildPipeline'], 'true'), eq(variables['_ContinuousIntegrationTestsEnabled'], 'true'))), eq(variables['_Platform'], 'x64'))

- task: PublishTestResults@2
displayName: Publish XUnit Test Results
inputs:
testResultsFormat: 'xUnit'
testResultsFiles: '*.xml'
searchFolder: '$(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig)'
testRunner: VSTest
testResultsFiles: '$(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig)/*.trx'
mergeTestResults: true
continueOnError: true
condition: and(eq(variables['_BuildConfig'], 'Release'), ne(variables['_Platform'], 'arm64'))

condition: and(succeededOrFailed(), eq(variables['_BuildConfig'], 'Debug'), eq(variables['_Platform'], 'x64'))

# Upload code coverage data
- script: dotnet msbuild -binaryLogger:artifacts\log\$(_configuration)\uploadCodeCov.binlog;ProjectImports=Embed -restore eng/CodeCoverage.proj
displayName: Upload coverage to codecov.io
condition: and(succeeded(), eq(variables['_Coverage'], True), eq(variables['_BuildConfig'], 'Debug'), eq(variables['_Platform'], 'x64'))
# - task: PowerShell@2
# displayName: Install .NET Core
# inputs:
Expand Down Expand Up @@ -306,4 +311,4 @@ jobs:
# searchFolder: '$(System.DefaultWorkingDirectory)\Results\'
# testRunTitle: 'Test results'
# mergeTestResults: true
# condition: eq(variables['System.TeamProject'], 'public')
# condition: eq(variables['System.TeamProject'], 'public')
Original file line number Diff line number Diff line change
Expand Up @@ -654,13 +654,15 @@ private void EnsureParameterDictionary()
private const char _equalSeparator = '=';

//This array is sorted by the ascii value of these characters.
private static ReadOnlySpan<char> AllowedCharacters => [
'!' /*33*/, '#' /*35*/ , '$' /*36*/,
'%' /*37*/, '&' /*38*/ , '\'' /*39*/,
'*' /*42*/, '+' /*43*/ , '-' /*45*/,
'.' /*46*/, '^' /*94*/ , '_' /*95*/,
'`' /*96*/, '|' /*124*/, '~' /*126*/,
];
private static readonly char[] s_allowedCharacters = [
'!' /*33*/, '#' /*35*/ , '$' /*36*/,
'%' /*37*/, '&' /*38*/ , '\'' /*39*/,
'*' /*42*/, '+' /*43*/ , '-' /*45*/,
'.' /*46*/, '^' /*94*/ , '_' /*95*/,
'`' /*96*/, '|' /*124*/, '~' /*126*/,
];

private static ReadOnlySpan<char> AllowedCharacters => s_allowedCharacters;
Copy link
Member

Choose a reason for hiding this comment

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

Why was this changed? Makes no sense?


//Linear White Space characters
private static readonly char[] _linearWhiteSpaceChars = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Shared\ModuleInitializer.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="$(CoverletVersion)" GeneratePathProperty="true" PrivateAssets="all" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@

<ItemGroup>
<PackageReference Include="Moq" Version="$(MoqPackageVersion)" />
<PackageReference Include="coverlet.msbuild" Version="$(CoverletMSBuildPackageVersion)" />
<PackageReference Include="xunit.stafact" Version="$(XUnitStaFactPackageVersion)" />
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="$(SystemConfigurationConfigurationManagerPackageVersion)" />
<PackageReference Include="System.Formats.Nrbf" Version="$(SystemFormatsNrbfVersion)" />
<PackageReference Include="System.Runtime.Serialization.Formatters" Version="$(SystemRuntimeSerializationFormattersPackageVersion)" />
<PackageReference Include="System.Drawing.Common" Version="8.0.8" />
<PackageReference Include="System.Drawing.Common" Version="$(SystemDrawingCommonVersion)" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

<ItemGroup>
<PackageReference Include="Moq" Version="$(MoqPackageVersion)" />
<PackageReference Include="coverlet.msbuild" Version="$(CoverletMSBuildPackageVersion)" />
<PackageReference Include="System.Windows.Extensions" Version="$(SystemWindowsExtensionsPackageVersion)" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
<PackageReference Include="xunit.stafact" Version="$(XUnitStaFactPackageVersion)" />
<PackageReference Include="Moq" Version="$(MoqPackageVersion)" />
<PackageReference Include="coverlet.msbuild" Version="$(CoverletMSBuildPackageVersion)" />
<PackageReference Include="$(SystemIOPackagingPackage)" Version="$(SystemIOPackagingVersion)" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="$(SystemConfigurationConfigurationManagerPackageVersion)" />
<PackageReference Include="System.Private.Windows.Core.TestUtilities" Version="$(SystemPrivateWindowsCoreTestUtilitiesVersion)" />
Expand Down
Loading