Repository navigation
Add unit test coverage for the FormatVersion task - #14307
jankratochvilcz wants to merge 1 commit into
Conversation
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
Pull request overview
Adds a new unit test suite for the FormatVersion MSBuild task to validate its version/wildcard/revision formatting behavior and error handling.
Changes:
- Added
FormatVersion_Testscovering default version behavior, wildcard+revision substitution, and pass-through behavior. - Added coverage for
FormatTypeparsing (case-insensitive),Pathformatting behavior, and invalidFormatTypefailure logging (MSB3098).
| #nullable disable | ||
|
|
||
| namespace Microsoft.Build.UnitTests | ||
| { | ||
| public sealed class FormatVersion_Tests | ||
| { | ||
| /// <summary> | ||
| /// An undefined (null or empty) Version yields the default "1.0.0.0". | ||
| /// </summary> | ||
| [Theory] | ||
| [InlineData(null)] | ||
| [InlineData("")] | ||
| public void UndefinedVersionYieldsDefault(string version) |
There was a problem hiding this comment.
Caution
agentic threat detected
Threat detection flagged this output in warn mode. Manual review is REQUIRED before any follow-up automation.
✅ 23/24 dimensions clean — 3 NITs in one dimension, no blocking or major findings.
Good first test file for FormatVersion. All 8 cases are correct and the coverage of the documented cases (null/empty default, wildcard+revision, full passthrough, Path format, case-insensitivity, invalid format type) is solid.
Findings
| # | Dimension | Severity | Summary |
|---|---|---|---|
| 16 | Idiomatic C# Patterns | NIT | #nullable disable on new file; missing ITestOutputHelper; one misaligned initializer line |
Details
NIT 1 — #nullable disable (line 8)
New files must have nullable enabled per repo policy. Remove the directive and annotate the one nullable parameter: string? version in UndefinedVersionYieldsDefault.
NIT 2 — Missing ITestOutputHelper (class declaration)
The neighbouring FormatUrl_Tests.cs and the testing instructions both require injecting ITestOutputHelper and passing it to MockEngine. Without it, task log output (errors, warnings from Log.*) is silently discarded during test runs, reducing CI debuggability. Fix:
private readonly ITestOutputHelper _output;
public FormatVersion_Tests(ITestOutputHelper output) => _output = output;
// everywhere: new MockEngine(_output)NIT 3 — Misaligned initializer member in WildcardVersionIsCombinedWithRevision (line 41)
BuildEngine = new MockEngine(), is at 12-space indent instead of 16, mismatching every other initializer in the file.
Minor style observation (not filed inline): All test locals use FormatVersion t = new FormatVersion { ... } — the neighbouring file uses var t = ..., which is also the repo preference when the type is obvious from the right-hand side. This is cosmetic but worth aligning.
Generated by Expert Code Review (on open) for #14307 · 976.3 AIC · ⊞ 32.2K
|
|
||
| namespace Microsoft.Build.UnitTests | ||
| { | ||
| public sealed class FormatVersion_Tests |
There was a problem hiding this comment.
[NIT] Idiomatic C# Patterns — Missing ITestOutputHelper injection
The directly neighbouring FormatUrl_Tests.cs follows the project convention: it injects ITestOutputHelper via the constructor and passes it to every MockEngine call. The testing instructions also mandate this. By not doing so here, task diagnostic output (errors, warnings logged via Log.*) is silently discarded during test runs, making CI failure diagnosis harder.
Suggested pattern, matching FormatUrl_Tests.cs:
public sealed class FormatVersion_Tests
{
private readonly ITestOutputHelper _output;
public FormatVersion_Tests(ITestOutputHelper output) => _output = output;
// Then everywhere:
BuildEngine = new MockEngine(_output),Optionally, a small factory method (like GetFormatUrlUnderTest() in the neighbour) would further reduce per-test boilerplate and ensure _output is always wired.
| { | ||
| FormatVersion t = new FormatVersion | ||
| { | ||
| BuildEngine = new MockEngine(), |
There was a problem hiding this comment.
[NIT] Idiomatic C# Patterns — Misaligned object-initializer member
BuildEngine is indented at the same level as FormatVersion t = new FormatVersion (12 spaces) rather than at the object-initializer member level (16 spaces), unlike every other initializer block in this file. This is likely a copy-paste or editor slip:
FormatVersion t = new FormatVersion
{
BuildEngine = new MockEngine(), // ← should be 16 spaces
Version = "1.0.0.*",
Revision = 5,
};| using Shouldly; | ||
| using Xunit; | ||
|
|
||
| #nullable disable |
There was a problem hiding this comment.
[NIT] Idiomatic C# Patterns — #nullable disable on a new file
The repo instructions are explicit: "New files: Always use nullable reference types (do NOT add #nullable disable)."
The source file under test (FormatVersion.cs) carries #nullable disable because it predates the policy — but this test file is brand new and should be nullable-enabled. The only nullable concern is the [Theory] parameter accepting null, which just needs a string? annotation:
// Remove #nullable disable, then:
public void UndefinedVersionYieldsDefault(string? version)All other members in the file are non-null strings or value types and need no further annotation.
Adds unit tests for the
FormatVersiontask (src/Tasks/FormatVersion.cs), which previously had no test file.The new
FormatVersion_Tests.cscovers behavior confirmed directly from the source:Versionyields the default1.0.0.0Version(1.0.0.*) has its trailing*replaced byRevisionVersionis passed through unchanged, regardless ofRevisionFormatType="Path"replaces dots with underscores (including after wildcard substitution)FormatTypeis parsed case-insensitivelyFormatType="Version"keeps the dotted formatFormatTypefails the task and logsMSB3098Test-only change. Uses xUnit + Shouldly with
MockEngine, matching neighboring tests. All 9 cases pass with 0 new warnings.Co-authored-by: Copilot App [email protected]