mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-16 20:23:20 +08:00
Cover -v and --version options in unit tests
This commit is contained in:
parent
520efe07e2
commit
17c7a4f7d6
@ -1,3 +1,5 @@
|
|||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace Spectre.Console.Tests.Unit.Cli;
|
namespace Spectre.Console.Tests.Unit.Cli;
|
||||||
|
|
||||||
public sealed partial class CommandAppTests
|
public sealed partial class CommandAppTests
|
||||||
@ -17,8 +19,10 @@ public sealed partial class CommandAppTests
|
|||||||
result.Output.ShouldStartWith("Spectre.Cli version ");
|
result.Output.ShouldStartWith("Spectre.Cli version ");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Theory]
|
||||||
public void Should_Output_Application_Version_To_The_Console_With_No_Command()
|
[InlineData("-v")]
|
||||||
|
[InlineData("--version")]
|
||||||
|
public void Should_Output_Application_Version_To_The_Console_With_No_Command(string versionOption)
|
||||||
{
|
{
|
||||||
// Given
|
// Given
|
||||||
var fixture = new CommandAppTester();
|
var fixture = new CommandAppTester();
|
||||||
@ -28,14 +32,16 @@ public sealed partial class CommandAppTests
|
|||||||
});
|
});
|
||||||
|
|
||||||
// When
|
// When
|
||||||
var result = fixture.Run("--version");
|
var result = fixture.Run(versionOption);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
result.Output.ShouldBe("1.0");
|
result.Output.ShouldBe("1.0");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Theory]
|
||||||
public void Should_Not_Display_Version_If_Not_Specified()
|
[InlineData("-v")]
|
||||||
|
[InlineData("--version")]
|
||||||
|
public void Should_Not_Display_Version_If_Not_Specified(string versionOption)
|
||||||
{
|
{
|
||||||
// Given
|
// Given
|
||||||
var fixture = new CommandAppTester();
|
var fixture = new CommandAppTester();
|
||||||
@ -45,15 +51,17 @@ public sealed partial class CommandAppTests
|
|||||||
});
|
});
|
||||||
|
|
||||||
// When
|
// When
|
||||||
var result = fixture.Run("--version");
|
var result = fixture.Run(versionOption);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
result.ExitCode.ShouldNotBe(0);
|
result.ExitCode.ShouldNotBe(0);
|
||||||
result.Output.ShouldStartWith("Error: Unexpected option 'version'");
|
result.Output.ShouldStartWith($"Error: Unexpected option '{versionOption.Replace("-", "")}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Theory]
|
||||||
public void Should_Execute_Command_Not_Output_Application_Version_To_The_Console()
|
[InlineData("-v")]
|
||||||
|
[InlineData("--version")]
|
||||||
|
public void Should_Execute_Command_Not_Output_Application_Version_To_The_Console(string versionOption)
|
||||||
{
|
{
|
||||||
// Given
|
// Given
|
||||||
var fixture = new CommandAppTester();
|
var fixture = new CommandAppTester();
|
||||||
@ -64,15 +72,17 @@ public sealed partial class CommandAppTests
|
|||||||
});
|
});
|
||||||
|
|
||||||
// When
|
// When
|
||||||
var result = fixture.Run("empty", "--version");
|
var result = fixture.Run("empty", versionOption);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
result.Output.ShouldBe(string.Empty);
|
result.Output.ShouldBe(string.Empty);
|
||||||
result.Context.ShouldHaveRemainingArgument("--version", new[] { (string)null });
|
result.Context.ShouldHaveRemainingArgument(versionOption, new[] { (string)null });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Theory]
|
||||||
public void Should_Execute_Default_Command_Not_Output_Application_Version_To_The_Console()
|
[InlineData("-v")]
|
||||||
|
[InlineData("--version")]
|
||||||
|
public void Should_Output_Application_Version_To_The_Console_With_Default_Command(string versionOption)
|
||||||
{
|
{
|
||||||
// Given
|
// Given
|
||||||
var fixture = new CommandAppTester();
|
var fixture = new CommandAppTester();
|
||||||
@ -83,15 +93,16 @@ public sealed partial class CommandAppTests
|
|||||||
});
|
});
|
||||||
|
|
||||||
// When
|
// When
|
||||||
var result = fixture.Run("--version");
|
var result = fixture.Run(versionOption);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
result.Output.ShouldBe(string.Empty);
|
result.Output.ShouldBe("1.0");
|
||||||
result.Context.ShouldHaveRemainingArgument("--version", new[] { (string)null });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Theory]
|
||||||
public void Should_Output_Application_Version_To_The_Console_With_Branch_Default_Command()
|
[InlineData("-v")]
|
||||||
|
[InlineData("--version")]
|
||||||
|
public void Should_Output_Application_Version_To_The_Console_With_Branch_Default_Command(string versionOption)
|
||||||
{
|
{
|
||||||
// Given
|
// Given
|
||||||
var fixture = new CommandAppTester();
|
var fixture = new CommandAppTester();
|
||||||
@ -105,10 +116,58 @@ public sealed partial class CommandAppTests
|
|||||||
});
|
});
|
||||||
|
|
||||||
// When
|
// When
|
||||||
var result = fixture.Run("--version");
|
var result = fixture.Run(versionOption);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
result.Output.ShouldBe("1.0");
|
result.Output.ShouldBe("1.0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("-v")]
|
||||||
|
[InlineData("--version")]
|
||||||
|
public void Should_Execute_Branch_Default_Command_Not_Output_Application_Version_To_The_Console(string versionOption)
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var fixture = new CommandAppTester();
|
||||||
|
fixture.Configure(configurator =>
|
||||||
|
{
|
||||||
|
configurator.SetApplicationVersion("1.0");
|
||||||
|
configurator.AddBranch<EmptyCommandSettings>("branch", branch =>
|
||||||
|
{
|
||||||
|
branch.SetDefaultCommand<EmptyCommand>();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// When
|
||||||
|
var result = fixture.Run("branch", versionOption);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
result.Output.ShouldBe(string.Empty);
|
||||||
|
result.Context.ShouldHaveRemainingArgument(versionOption, new[] { (string)null });
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("-v")]
|
||||||
|
[InlineData("--version")]
|
||||||
|
public void Should_Execute_Branch_Command_Not_Output_Application_Version_To_The_Console(string versionOption)
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var fixture = new CommandAppTester();
|
||||||
|
fixture.Configure(configurator =>
|
||||||
|
{
|
||||||
|
configurator.SetApplicationVersion("1.0");
|
||||||
|
configurator.AddBranch<EmptyCommandSettings>("branch", branch =>
|
||||||
|
{
|
||||||
|
branch.AddCommand<EmptyCommand>("hello");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// When
|
||||||
|
var result = fixture.Run("branch", "hello", versionOption);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
result.Output.ShouldBe(string.Empty);
|
||||||
|
result.Context.ShouldHaveRemainingArgument(versionOption, new[] { (string)null });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user