mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 08:52:50 +08:00
Unit test to reproduce the -v/--version bug
This commit is contained in:
parent
5a52c1f277
commit
d03c10623c
@ -0,0 +1,18 @@
|
|||||||
|
namespace Spectre.Console.Tests.Data;
|
||||||
|
|
||||||
|
public sealed class VersionCommand : Command<VersionSettings>
|
||||||
|
{
|
||||||
|
private readonly IAnsiConsole _console;
|
||||||
|
|
||||||
|
public VersionCommand(IAnsiConsole console)
|
||||||
|
{
|
||||||
|
_console = console;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int Execute(CommandContext context, VersionSettings settings)
|
||||||
|
{
|
||||||
|
_console.WriteLine($"VersionCommand ran, Version: {settings.Version ?? string.Empty}");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
namespace Spectre.Console.Tests.Data;
|
||||||
|
|
||||||
|
public sealed class VersionSettings : CommandSettings
|
||||||
|
{
|
||||||
|
[CommandOption("-v|--version")]
|
||||||
|
public string Version { get; set; }
|
||||||
|
}
|
@ -586,5 +586,28 @@ public sealed partial class CommandAppTests
|
|||||||
result.Output.ShouldBe("Error: Command 'dog' is missing required argument 'AGE'.");
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user