Skip to content

Fix Roslyn analyzer tutorial: Correct test case categorization #47120

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

Merged
merged 3 commits into from
Jul 8, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 7, 2025

The "Create tests for valid declarations" section incorrectly categorized some test cases as failing when they actually pass due to existing analyzer logic.

Problem

The tutorial stated that four test cases "you haven't handled yet" would fail when running tests:

  • VariableIsAlreadyConst_NoDiagnostic
  • NoInitializer_NoDiagnostic
  • InitializerIsNotConstant_NoDiagnostic
  • MultipleInitializers_NoDiagnostic

However, the first two tests actually pass because the analyzer already handles these conditions:

  • Already const declarations: Filtered out by the const keyword check in the analyzer
  • No initializer declarations: Handled by data flow analysis that detects assignments outside the declaration

Solution

Reorganized the documentation to correctly categorize the tests:

Tests that pass (already handled):

  • Variable assigned after initialization (existing example)
  • Variable already declared as const (moved from "failing" section)
  • Variable with no initializer (moved from "failing" section)

Tests that actually fail (need to be implemented):

  • Variable initializer is not a constant
  • Multiple variables where not all can be made constant

Updated the text from "you'll see these new test cases fail" to "you'll see these last two test cases fail" for accuracy.

Impact

Tutorial readers will no longer be confused by tests that the documentation claims should fail but actually pass, making the learning experience clearer and more accurate.

Fixes #23501.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


Internal previews

📄 File 🔗 Preview link
docs/csharp/roslyn-sdk/tutorials/how-to-write-csharp-analyzer-code-fix.md docs/csharp/roslyn-sdk/tutorials/how-to-write-csharp-analyzer-code-fix

@dotnet-policy-service dotnet-policy-service bot added okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. labels Jul 7, 2025
@Copilot Copilot AI changed the title [WIP] Create tests for valid declarations: Some tests the writeup says should fail do not fail Fix Roslyn analyzer tutorial: Correct test case categorization Jul 7, 2025
@Copilot Copilot AI requested a review from BillWagner July 7, 2025 18:47
Copilot finished work on behalf of BillWagner July 7, 2025 18:47
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

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

Overall, this is great, but I had one additional task before we say this is ready.

Copilot finished work on behalf of BillWagner July 8, 2025 14:09
@Copilot Copilot AI requested a review from BillWagner July 8, 2025 14:09
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

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

Thanks @copilot

This LGTM.

@BillWagner BillWagner marked this pull request as ready for review July 8, 2025 14:16
@BillWagner BillWagner requested a review from a team as a code owner July 8, 2025 14:16
@BillWagner BillWagner requested a review from IEvangelist July 8, 2025 14:17
@IEvangelist IEvangelist merged commit 2e0eb05 into main Jul 8, 2025
10 checks passed
@IEvangelist IEvangelist deleted the copilot/fix-23501 branch July 8, 2025 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet-csharp/svc okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. roslyn-sdk/subsvc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create tests for valid declarations: Some tests the writeup says should fail do not fail
3 participants