diff --git a/src/DemaConsulting.BuildMark/Cli/Context.cs b/src/DemaConsulting.BuildMark/Cli/Context.cs index ccd8c94a..dac89687 100644 --- a/src/DemaConsulting.BuildMark/Cli/Context.cs +++ b/src/DemaConsulting.BuildMark/Cli/Context.cs @@ -298,6 +298,7 @@ private int ParseArgument(string arg, string[] args, int index) BuildVersion = GetRequiredStringArgument(arg, args, index, "a version argument"); return index + 1; + case "--result": case "--results": ResultsFile = GetRequiredStringArgument(arg, args, index, "a results filename argument"); return index + 1; diff --git a/test/DemaConsulting.BuildMark.Tests/Cli/CliTests.cs b/test/DemaConsulting.BuildMark.Tests/Cli/CliTests.cs index f7b3949c..716dfa5a 100644 --- a/test/DemaConsulting.BuildMark.Tests/Cli/CliTests.cs +++ b/test/DemaConsulting.BuildMark.Tests/Cli/CliTests.cs @@ -203,6 +203,19 @@ public void Cli_ResultsFlag_SetsProperty() Assert.AreEqual("results.trx", context.ResultsFile); } + /// + /// Test that the Cli subsystem sets the ResultsFile property when --result (alias) is specified. + /// + [TestMethod] + public void Cli_ResultFlag_SetsProperty() + { + // Arrange & Act: create context with --result alias argument + using var context = Context.Create(["--result", "results.trx"]); + + // Assert: ResultsFile property is set to the specified value + Assert.AreEqual("results.trx", context.ResultsFile); + } + /// /// Test that the Cli subsystem writes error messages to stderr. /// diff --git a/test/DemaConsulting.BuildMark.Tests/Cli/ContextTests.cs b/test/DemaConsulting.BuildMark.Tests/Cli/ContextTests.cs index aa1950c1..206b43b5 100644 --- a/test/DemaConsulting.BuildMark.Tests/Cli/ContextTests.cs +++ b/test/DemaConsulting.BuildMark.Tests/Cli/ContextTests.cs @@ -219,6 +219,19 @@ public void Context_Create_ResultsArgument_SetsResultsFileProperty() Assert.AreEqual("results.trx", context.ResultsFile); } + /// + /// Test that Context.Create with --result (alias) argument sets ResultsFile property. + /// + [TestMethod] + public void Context_Create_ResultArgument_SetsResultsFileProperty() + { + // Create context with --result alias argument + using var context = Context.Create(["--result", "results.trx"]); + + // Verify ResultsFile property is set + Assert.AreEqual("results.trx", context.ResultsFile); + } + /// /// Test that Context.Create with --log argument creates log file. /// @@ -481,6 +494,32 @@ public void Context_Create_ResultsWithoutValue_ThrowsArgumentException() Assert.Contains("--results requires a results filename argument", caughtException.Message); } + /// + /// Test that Context.Create throws ArgumentException when --result (alias) has no value. + /// + [TestMethod] + public void Context_Create_ResultWithoutValue_ThrowsArgumentException() + { + ArgumentException? caughtException = null; + + try + { + // Attempt to create context with --result alias but no value + _ = Context.Create(["--result"]); + + // Fail test if exception was not thrown + Assert.Fail("Expected ArgumentException to be thrown"); + } + catch (ArgumentException ex) + { + caughtException = ex; + } + + // Verify exception was caught and message is correct + Assert.IsNotNull(caughtException); + Assert.Contains("--result requires a results filename argument", caughtException.Message); + } + /// /// Test that Context.Create throws ArgumentException when --log has no value. ///