Skip to content

Simplify TestRunParameters argument validation with LINQ (PR #9748 follow-up)#9749

Merged
Evangelink merged 1 commit into
mainfrom
dev/amauryleve/phase6a-review-followup
Jul 8, 2026
Merged

Simplify TestRunParameters argument validation with LINQ (PR #9748 follow-up)#9749
Evangelink merged 1 commit into
mainfrom
dev/amauryleve/phase6a-review-followup

Conversation

@Evangelink

Copy link
Copy Markdown
Member

What

Follow-up to the merged #9748 (Phase 6a), addressing the review feedback on that PR.

Change

The github-code-quality bot flagged that MSTestTestRunParametersCommandLineOptionsProvider.ValidateOptionArgumentsAsync used a foreach that implicitly filters its sequence. Replaced it with an explicit FirstOrDefault filter:

string? invalidArgument = arguments.FirstOrDefault(argument => !argument.Contains('='));
return invalidArgument is not null
    ? ValidationResult.InvalidTask(string.Format(CultureInfo.CurrentCulture, PlatformAdapterResources.TestRunParameterOptionArgumentIsNotParameter, invalidArgument))
    : ValidationResult.ValidTask;

No behavior change — it still reports the first argument missing = with the same localized message, and returns valid when all arguments contain =.

Not addressed here (deferred/informational)

The expert-review summary on #9748 raised two informational, non-blocking notes that are intentionally left out of this PR:

  • MSTEST_EXPERIMENTAL_NATIVE_MTP casing (is "1" or "true" or "True" won't match "TRUE") — the reviewer explicitly suggested harmonizing this when the flag is promoted in Phase 6b, so it's folded into that work.
  • MSTestRunSettingsConfigurationProvider.TryGet() re-parsing the XDocument — a cold path; caching is optional and not warranted yet.

Validation

  • Full build clean (warnings-as-errors).
  • MSTestAdapter.UnitTests (45) pass.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Address the code-quality review comment on #9748: replace the implicitly-filtering
foreach in MSTestTestRunParametersCommandLineOptionsProvider.ValidateOptionArgumentsAsync
with an explicit FirstOrDefault filter. No behavior change — still reports the first
argument missing '=' with the same localized message.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 8, 2026 19:07

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

This PR is a follow-up to #9748 (native MTP integration, Phase 6a) that addresses a github-code-quality bot review note. It simplifies argument validation in the MSTest-native --test-parameter command-line option provider by replacing an implicit-filtering foreach loop with an explicit FirstOrDefault LINQ query. The change is confined to the experimental native MTP path (#if !WINDOWS_UWP) and has no behavioral impact.

Changes:

  • Replaced the foreach + if (!argument.Contains('=')) early-return pattern with arguments.FirstOrDefault(argument => !argument.Contains('=')).
  • Uses a conditional expression to return InvalidTask (with the same localized TestRunParameterOptionArgumentIsNotParameter message) when an invalid argument exists, otherwise ValidTask.
Show a summary per file
File Description
src/Adapter/MSTest.TestAdapter/TestingPlatformAdapter/MSTestTestRunParametersCommandLineOptionsProvider.cs Refactors ValidateOptionArgumentsAsync to use FirstOrDefault instead of a filtering foreach; behavior (first-invalid-argument reporting and empty-array validity) is preserved.

Review details

  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Medium

@github-actions github-actions Bot 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.

Note

🤖 Automated review by GitHub Copilot. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.

✅ 22/22 dimensions clean — no findings.

The FirstOrDefault replacement is semantically equivalent to the original foreach with early return: both find the first argument not containing '=' and report it (or return valid when all arguments pass). The lambda captures no variables, so the delegate is compiler-cacheable — no allocation concern on this cold startup path. LINQ is available via implicit usings, and the existing acceptance/unit tests cover the validation behavior end-to-end.

@Evangelink
Evangelink merged commit cf0dea9 into main Jul 8, 2026
23 of 29 checks passed
@Evangelink
Evangelink deleted the dev/amauryleve/phase6a-review-followup branch July 8, 2026 19: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