Unit test to reproduce the -v/--version bug

This commit is contained in:
Frank Ray
2024-01-06 16:38:33 +00:00
committed by Patrik Svensson
parent 5a52c1f277
commit d03c10623c
3 changed files with 48 additions and 0 deletions

View File

@ -586,5 +586,28 @@ public sealed partial class CommandAppTests
result.Output.ShouldBe("Error: Command 'dog' is missing required argument 'AGE'.");
}
}
/// <summary>
/// -v or --version switches should result in the Version option being set
/// on VersionSettings, and then VersionCommand.Execute(...) being called
/// </summary>
[InlineData("-v")]
[InlineData("--version")]
[Theory]
public void Should_Run_Custom_Version_Command(string versionOption)
{
// Given
var app = new CommandAppTester();
app.Configure(configurator =>
{
configurator.AddCommand<Spectre.Console.Tests.Data.VersionCommand>("CustomVersionCommand");
});
// When
var result = app.Run("CustomVersionCommand", versionOption, "1.2.5");
// Then
result.Output.ShouldBe("VersionCommand ran, Version: 1.2.5");
}
}
}