Skip to content

Fix MSTest analyzer violations breaking main#54807

Merged
Evangelink merged 2 commits into
dotnet:mainfrom
Evangelink:evangelink/fix-mstest-analyzer-violations-main
Jun 17, 2026
Merged

Fix MSTest analyzer violations breaking main#54807
Evangelink merged 2 commits into
dotnet:mainfrom
Evangelink:evangelink/fix-mstest-analyzer-violations-main

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Problem

PR #54766 enabled the Recommended MSTest analyzers as build errors. PR #54758 merged ~2 minutes later, and its Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests code contains assertions that those analyzers now flag — so main is currently red and every open MSTest migration PR is blocked (their merge builds fail on these same errors).

Fix

Resolve the analyzer violations in the two affected files (no behavior change):

  • CommandResultAssertions.MSTest.cs: MSTEST0037 (Assert.IsTrue(a == b) -> Assert.AreEqual; Assert.IsFalse(a == b) -> Assert.AreNotEqual) and MSTEST0023 (Assert.IsTrue(!x) -> Assert.IsFalse(x)).
  • LocalizeTemplateTests.cs: MSTEST0037 (Assert.AreEqual(n, x.Length) -> Assert.HasCount(n, x)).

Verification

  • Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests builds clean (0 warnings / 0 errors) with the analyzers enabled.

This unblocks #54722 #54723 #54724 #54725 #54726 #54729 #54730 #54732 #54759 #54761 #54785 #54787.

…tionTests)

PR dotnet#54766 enabled the Recommended MSTest analyzers as errors; dotnet#54758 merged shortly
after with violations that are now build errors, leaving main red and blocking all
open migration PRs. Fix the two affected files:
- CommandResultAssertions.MSTest.cs: MSTEST0037 (IsTrue(a==b)->AreEqual, IsFalse(a==b)
  ->AreNotEqual) and MSTEST0023 (IsTrue(!x)->IsFalse(x)).
- LocalizeTemplateTests.cs: MSTEST0037 (AreEqual(n, x.Length)->HasCount(n, x)).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 16, 2026 20:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes MSTest “Recommended” analyzer violations introduced as build errors, restoring clean builds for Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests and unblocking the ongoing MSTest migration PR stack.

Changes:

  • Replace equality-in-boolean asserts with Assert.AreEqual / Assert.AreNotEqual in the MSTest CommandResultAssertions helper.
  • Replace negated Assert.IsTrue(!...) patterns with Assert.IsFalse(...).
  • Replace AreEqual(expected, array.Length) with Assert.HasCount(expected, array) in localization integration tests.
Show a summary per file
File Description
test/TemplateEngine/Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests/LocalizeTemplateTests.cs Uses Assert.HasCount for file count assertions to satisfy MSTest analyzers.
test/TemplateEngine/Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests/CommandResultAssertions.MSTest.cs Updates assertions to analyzer-preferred forms (AreEqual/AreNotEqual/IsFalse) while preserving behavior.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

@Evangelink

Copy link
Copy Markdown
Member Author

/ba-g #54813

The CI failure on this PR is not related to its changes. This PR only modifies two files in Microsoft.TemplateEngine.Authoring.Tasks.IntegrationTests (CommandResultAssertions.MSTest.cs, LocalizeTemplateTests.cs) — MSTest analyzer fixes (Assert.IsTrue(a==b)AreEqual, IsTrue(!x)IsFalse(x), AreEqual(n, x.Length)HasCount). The build compiles cleanly.

The only failing tests are in dotnet.Tests, in the RunFileTests_* family (RunFileTests_BuildCommands.Build_Library_MultiTarget, RunFileTests_CscOnlyAndApi.MSBuildGet_Consistent) — the known-flaky file-based-program build race tracked in #54813 (MSB4025: project file could not be loaded). These have no connection to this PR's Authoring.Tasks analyzer changes.

@Evangelink Evangelink merged commit 6dc9009 into dotnet:main Jun 17, 2026
23 of 25 checks passed
@Evangelink Evangelink deleted the evangelink/fix-mstest-analyzer-violations-main branch June 17, 2026 08:42
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 23, 2026
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.

3 participants