Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/design/sonar-mark/cli/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,16 @@ Using `IDisposable` rather than a finalizer is appropriate because the resource
- `SonarMark-Validation-JUnitFormat` — JUnit XML file extension is accepted by `ResultsFile`
- `SonarMark-Enforce-Mode` — `Enforce` flag is parsed and stored
- `SonarMark-Enforce-ExitCode` — `ExitCode` returns 1 when `_hasErrors` is true
- `SonarMark-Context-ResultAlias` — `--result` is accepted as a legacy alias for `--results`

## Backward Compatibility

### Legacy `--result` Alias

The `ArgumentParser` accepts `--result` as a fall-through case immediately before `--results`
in the switch statement. Both spellings invoke the same `GetRequiredStringArgument` call and
set the same `ResultsFile` property, so downstream code is unaffected.

This alias is intentionally omitted from help text and user-facing documentation because it
exists only to avoid breaking existing automation scripts that pre-date the canonical
`--results` spelling. New users and new scripts should always use `--results`.
11 changes: 11 additions & 0 deletions docs/reqstream/sonar-mark/cli/context.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,14 @@ sections:
tests:
- Context_Create_ResultsFile_SetsResultsProperty
- Context_Create_MissingResultsFilename_ThrowsException

- id: SonarMark-Context-ResultAlias
title: The tool shall accept --result as a legacy alias for --results to preserve backward compatibility.
justification: |
Existing automation scripts and CI pipelines may use --result (without the trailing 's') from
before the canonical --results spelling was established. Accepting the alias prevents breakage
for those consumers without requiring a coordinated migration, while new users are directed to
the canonical --results flag via documentation and help text.
tests:
- Context_Create_ResultAlias_SetsResultsProperty
- Context_Create_MissingResultAliasFilename_ThrowsException
2 changes: 2 additions & 0 deletions src/DemaConsulting.SonarMark/Cli/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ private int ParseArgument(string arg, string[] args, int index)
Branch = GetRequiredStringArgument(arg, args, index, "a branch name argument");
return index + 1;

// Accept --result as a legacy alias so older scripts continue working
case "--result":
case "--results":
ResultsFile = GetRequiredStringArgument(arg, args, index, "a results filename argument");
return index + 1;
Expand Down
25 changes: 25 additions & 0 deletions test/DemaConsulting.SonarMark.Tests/Cli/ContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,4 +461,29 @@ public void Context_Create_MissingResultsFilename_ThrowsException()
var ex = Assert.ThrowsExactly<ArgumentException>(() => Context.Create(["--results"]));
Assert.Contains("--results requires a results filename argument", ex.Message);
}

/// <summary>
/// Test that --result (legacy alias) sets the ResultsFile property.
/// </summary>
[TestMethod]
public void Context_Create_ResultAlias_SetsResultsProperty()
{
// Act
using var context = Context.Create(["--result", "results.trx"]);

// Assert
Assert.AreEqual("results.trx", context.ResultsFile);
Assert.AreEqual(0, context.ExitCode);
}

/// <summary>
/// Test that --result (legacy alias) requires a filename argument.
/// </summary>
[TestMethod]
public void Context_Create_MissingResultAliasFilename_ThrowsException()
{
// Act/Assert
var ex = Assert.ThrowsExactly<ArgumentException>(() => Context.Create(["--result"]));
Assert.Contains("--result requires a results filename argument", ex.Message);
}
}