Skip to content

Add tests for types with primary constructors (stacked on #4142) - #4143

Merged
AArnott merged 1 commit into
masterfrom
csharp12-primary-constructor-types
Oct 8, 2026
Merged

AArnott merged 1 commit into
masterfrom
csharp12-primary-constructor-types

Conversation

@AArnott

@AArnott AArnott commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Part of #4044 / #4006 (C# 12 primary constructors).

Stacked on #4142 (record handling). Many of these tests run on record/record struct as well as class/struct with primary constructors, and they only pass once #4142's record fixes are in. Please review and merge #4142 first.

This ports @bjornhellander's 50f071c47 (bjornhellander/NewStyleCopAnalyzers#147) with his authorship kept. It adds tests for types with primary constructor parameter lists across these rules: SA1137, SA1201–SA1206, SA1214, SA1400, SA1505, SA1600, SA1601, SA1604–SA1608, SA1613, SA1614, SA1616, SA1618, SA1619, SA1620–SA1622, SA1625, SA1629 and SA1648. The tests were merged into the existing upstream test classes, use ConfigureAwait(false) and [WorkItem(4006)], and the SA1201 expectations were updated to upstream's message arguments ("A field" / "a property").

Behavior change (code fixes only)

Older Roslyn versions report some diagnostics twice: on positional records (dotnet/roslyn#53136) and in files with top-level statements (dotnet/roslyn#58561). When that happens, the fix-all for two code fixes ended up with duplicate or overlapping text changes:

  • SA1629CodeFixProvider now adds each period only once.
  • IndentationCodeFixProvider (SA1137) now skips text changes it has already added.

Analyzer diagnostics don't change in this PR. The tests expect the duplicate diagnostics where older compilers produce them, through overridable GetExpectedResult… methods.

Tests

On Linux, all primary-constructor tests pass on C# 9–15 except the SA1201–SA1204/SA1214 code-fix tests, which fail only because of CRLF line endings, the same way existing ordering fix tests do on Linux. CI (Windows) is the real check.

@AArnott
AArnott added this pull request to stack #4144 October 8, 2026 04:26
@codecov

codecov Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.84568% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.47%. Comparing base (5fa97a1) to head (4057d07).
⚠️ Report is 26 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4143      +/-   ##
==========================================
+ Coverage   97.44%   97.47%   +0.02%     
==========================================
  Files        1154     1212      +58     
  Lines      126586   127945    +1359     
  Branches     4206     4207       +1     
==========================================
+ Hits       123357   124719    +1362     
+ Misses       2115     2114       -1     
+ Partials     1114     1112       -2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AArnott
AArnott marked this pull request as ready for review October 8, 2026 04:41
@AArnott
AArnott force-pushed the csharp12-primary-constructor-types branch from 3f158e8 to 9530fee Compare October 8, 2026 16:24
Base automatically changed from records-ordering-documentation to master October 8, 2026 17:28
…and SA1629 code fixes to handle duplicate diagnostics

From bjornhellander/NewStyleCopAnalyzers#147.

Adapted while cherry-picking: the tests were merged into the existing upstream test classes and use
ConfigureAwait(false) and WorkItem(4006). The IndentationCodeFixProvider change was applied to the upstream
code, which did not yet skip duplicate text changes. The SA1201 expectations use the upstream message
arguments ("A field", "a property").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 50f071c475a82407585b599603f920f4a39b4214)
@AArnott
AArnott force-pushed the csharp12-primary-constructor-types branch from 9530fee to 4057d07 Compare October 8, 2026 17:36
@AArnott
AArnott merged commit e3dc2d8 into master Oct 8, 2026
25 checks passed
@AArnott
AArnott deleted the csharp12-primary-constructor-types branch October 8, 2026 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants