Skip to content

Commit 90d14b3

Browse files
EvangelinkCopilot
andauthored
Expand behavior-focused coverage across TestFx (#12158)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent b866b0a commit 90d14b3

266 files changed

Lines changed: 43802 additions & 104 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎eng/validate-code-coverage-settings.ps1‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,18 @@ foreach ($settingsFile in $SettingsFiles) {
9898
$sourceIncludes = @($settings.SelectNodes("/Configuration/CodeCoverage/Sources/Include/Source") |
9999
ForEach-Object { $_.InnerText })
100100

101+
$attributes = $settings.SelectSingleNode("/Configuration/CodeCoverage/Attributes")
102+
$attributeExcludes = $settings.SelectSingleNode("/Configuration/CodeCoverage/Attributes/Exclude")
103+
if ($null -eq $attributes -or $attributes.GetAttribute("mergeDefaults") -ine "False" -or
104+
$null -eq $attributeExcludes -or $attributeExcludes.HasChildNodes) {
105+
throw "Production coverage must not exclude attribute-marked bodies in '$settingsFile'."
106+
}
107+
108+
$doesNotReturn = $settings.SelectSingleNode("/Configuration/DoesNotReturnAttribute")
109+
if ($null -eq $doesNotReturn -or $doesNotReturn.InnerText -ine "None") {
110+
throw "Coverage must retain reachable assertion-scope continuations in '$settingsFile'."
111+
}
112+
101113
foreach ($pattern in $moduleIncludes) {
102114
if (-not $pattern.EndsWith('\.dll$') -and -not $pattern.EndsWith('\.exe$')) {
103115
throw "The assembly regex lost its literal extension in '$settingsFile': '$pattern'."
@@ -135,7 +147,7 @@ foreach ($settingsFile in $SettingsFiles) {
135147
"C:\coverage-validation\src\Polyfills\Index.cs",
136148
"/coverage-validation/src/Polyfills/Index.cs"
137149
)) {
138-
Assert-PatternMatch $sourceExcludes $path $true "Compatibility shims must be excluded by '$settingsFile'."
150+
Assert-PatternMatch $sourceExcludes $path $false "Compatibility bodies must remain measurable in '$settingsFile'."
139151
}
140152

141153
foreach ($path in @(

‎test/Directory.Build.targets‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,6 @@
155155
<_CodeCoverageExcludedSource Include="TestInfrastructure">
156156
<Pattern>$([System.Text.RegularExpressions.Regex]::Escape('$(_CodeCoverageTestInfrastructureRoot)').Insert(0, '^')).*</Pattern>
157157
</_CodeCoverageExcludedSource>
158-
<!-- Keep repository-owned validation and process-lifetime logic measurable while excluding BCL compatibility shims. -->
159-
<_CodeCoverageExcludedSource Include="Polyfills">
160-
<Pattern>(^|[\\/])Polyfills[\\/](?!Ensure\.cs$|ProcessExtensions\.cs$).*\.cs$</Pattern>
161-
</_CodeCoverageExcludedSource>
162158
<_CodeCoverageExcludedSource Update="@(_CodeCoverageExcludedSource)">
163159
<XmlPattern>$([System.String]::Copy('%(_CodeCoverageExcludedSource.Pattern)').Replace('&amp;', '&amp;amp;').Replace('&lt;', '&amp;lt;').Replace('&gt;', '&amp;gt;'))</XmlPattern>
164160
</_CodeCoverageExcludedSource>
@@ -168,10 +164,16 @@
168164
<ItemGroup>
169165
<_CodeCoverageSettingsLine Include="Declaration" Value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;" />
170166
<_CodeCoverageSettingsLine Include="ConfigurationStart" Value="&lt;Configuration&gt;" />
167+
<_CodeCoverageSettingsLine Include="DoesNotReturnAttribute" Value=" &lt;DoesNotReturnAttribute&gt;None&lt;/DoesNotReturnAttribute&gt;" />
171168
<_CodeCoverageSettingsLine Include="IncludeSourceLinkedTestAssembly"
172169
Condition="'$(CodeCoverageIncludeSourceLinkedProductionCode)' == 'true'"
173170
Value=" &lt;IncludeTestAssembly&gt;True&lt;/IncludeTestAssembly&gt;" />
174171
<_CodeCoverageSettingsLine Include="CodeCoverageStart" Value=" &lt;CodeCoverage&gt;" />
172+
<!-- Measure all production bodies, including compatibility helpers and opt-out-marked code.
173+
Module/source filters still keep test infrastructure, packages and generated artifacts out. -->
174+
<_CodeCoverageSettingsLine Include="AttributesStart" Value=" &lt;Attributes mergeDefaults=&quot;False&quot;&gt;" />
175+
<_CodeCoverageSettingsLine Include="AttributesExclude" Value=" &lt;Exclude /&gt;" />
176+
<_CodeCoverageSettingsLine Include="AttributesEnd" Value=" &lt;/Attributes&gt;" />
175177
<_CodeCoverageSettingsLine Include="ModulePathsStart" Value=" &lt;ModulePaths mergeDefaults=&quot;False&quot;&gt;" />
176178
<_CodeCoverageSettingsLine Include="ModuleIncludeStart" Value=" &lt;Include&gt;" />
177179
<_CodeCoverageSettingsLine Include="@(_CodeCoverageProjectReference)">

‎test/UnitTests/MSTest.Analyzers.UnitTests/AnalyzerDiagnosticContinuationTests.cs‎

Lines changed: 446 additions & 0 deletions
Large diffs are not rendered by default.

‎test/UnitTests/MSTest.Analyzers.UnitTests/CodeFixContinuationTests.cs‎

Lines changed: 431 additions & 0 deletions
Large diffs are not rendered by default.

‎test/UnitTests/MSTest.Analyzers.UnitTests/CodeFixRegistrationContinuationTests.cs‎

Lines changed: 438 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Microsoft.CodeAnalysis;
5+
6+
using VerifyCS = MSTest.Analyzers.Test.CSharpCodeFixVerifier<
7+
MSTest.Analyzers.DependsOnShouldBeValidAnalyzer,
8+
Microsoft.CodeAnalysis.Testing.EmptyCodeFixProvider>;
9+
10+
namespace MSTest.Analyzers.Test;
11+
12+
[TestClass]
13+
public sealed class DependencySignatureContinuationTests
14+
{
15+
[TestMethod]
16+
[DataRow("T first, T second", "U first, U second")]
17+
[DataRow("System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<T[,]>> value", "System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<U[,]>> value")]
18+
[DataRow("T[] first, int[,] second", "U[] first, int[,] second")]
19+
[DataRow("dynamic first, T second", "object first, U second")]
20+
[DataRow("int* first, T second", "int* first, U second")]
21+
public async Task StructurallyEqualHiddenSignatures_DoNotInventCycles(string baseParameters, string derivedParameters)
22+
{
23+
string source = $$"""
24+
using Microsoft.VisualStudio.TestTools.UnitTesting;
25+
public unsafe class Base
26+
{
27+
[TestMethod, DependsOn(nameof(Other))]
28+
public void Run<T>({{baseParameters}}) { }
29+
[TestMethod]
30+
public void Other() { }
31+
}
32+
[TestClass]
33+
public unsafe class Tests : Base
34+
{
35+
[TestMethod]
36+
public new void Run<U>({{derivedParameters}}) { }
37+
[TestMethod, DependsOn(nameof(Run))]
38+
public new void Other() { }
39+
}
40+
""";
41+
var test = new VerifyCS.Test { TestCode = source };
42+
test.SolutionTransforms.Add((solution, projectId) => solution.WithProjectCompilationOptions(
43+
projectId, ((Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions)solution.GetProject(projectId)!.CompilationOptions!).WithAllowUnsafe(true)));
44+
await test.RunAsync();
45+
}
46+
47+
[TestMethod]
48+
[DataRow("T[] value", "U[,] value")]
49+
[DataRow("System.Collections.Generic.List<T> first, int second", "System.Collections.Generic.List<U> first, string second")]
50+
[DataRow("int* first, T second", "long* first, U second")]
51+
public async Task StructurallyDifferentOverloads_PreserveRealCycle(string baseParameters, string derivedParameters)
52+
{
53+
string source = $$"""
54+
using Microsoft.VisualStudio.TestTools.UnitTesting;
55+
public unsafe class Base
56+
{
57+
[TestMethod, {|#0:DependsOn("Other")|}]
58+
public void Run<T>({{baseParameters}}) { }
59+
}
60+
[TestClass]
61+
public unsafe class Tests : Base
62+
{
63+
[TestMethod]
64+
public void Run<U>({{derivedParameters}}) { }
65+
[TestMethod, {|#1:DependsOn(nameof(Run))|}]
66+
public void Other() { }
67+
}
68+
""";
69+
var test = new VerifyCS.Test { TestCode = source };
70+
test.SolutionTransforms.Add((solution, projectId) => solution.WithProjectCompilationOptions(
71+
projectId, ((Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions)solution.GetProject(projectId)!.CompilationOptions!).WithAllowUnsafe(true)));
72+
test.ExpectedDiagnostics.Add(VerifyCS.Diagnostic(DependsOnShouldBeValidAnalyzer.CycleRule)
73+
.WithLocation(0).WithArguments("Tests.Run > Tests.Other > Tests.Run"));
74+
test.ExpectedDiagnostics.Add(VerifyCS.Diagnostic(DependsOnShouldBeValidAnalyzer.CycleRule)
75+
.WithLocation(1).WithArguments("Tests.Other > Tests.Run > Tests.Other"));
76+
await test.RunAsync();
77+
}
78+
}

0 commit comments

Comments
 (0)