mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-07-05 12:08:16 +08:00
Improved unit test coverage using Spectre.Console.Tests.Data.VersionCommand
This commit is contained in:

committed by
Patrik Svensson

parent
4ac88b5d3f
commit
c4a97f3c89
@ -34,10 +34,6 @@ public sealed partial class CommandAppTests
|
|||||||
{
|
{
|
||||||
// Given
|
// Given
|
||||||
var fixture = new CommandAppTester();
|
var fixture = new CommandAppTester();
|
||||||
fixture.Configure(configurator =>
|
|
||||||
{
|
|
||||||
configurator.AddCommand<EmptyCommand>("empty");
|
|
||||||
});
|
|
||||||
|
|
||||||
// When
|
// When
|
||||||
var result = fixture.Run(helpOption);
|
var result = fixture.Run(helpOption);
|
||||||
@ -46,27 +42,6 @@ public sealed partial class CommandAppTests
|
|||||||
result.Output.ShouldNotContain("-v, --version Prints version information");
|
result.Output.ShouldNotContain("-v, --version Prints version information");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData("-?")]
|
|
||||||
[InlineData("-h")]
|
|
||||||
[InlineData("--help")]
|
|
||||||
public void Help_Should_Not_Include_Application_Version_Flag_For_Command(string helpOption)
|
|
||||||
{
|
|
||||||
// Given
|
|
||||||
var fixture = new CommandAppTester();
|
|
||||||
fixture.Configure(configurator =>
|
|
||||||
{
|
|
||||||
configurator.SetApplicationVersion("1.0");
|
|
||||||
configurator.AddCommand<EmptyCommand>("empty");
|
|
||||||
});
|
|
||||||
|
|
||||||
// When
|
|
||||||
var result = fixture.Run("empty", helpOption);
|
|
||||||
|
|
||||||
// Then
|
|
||||||
result.Output.ShouldNotContain("-v, --version Prints version information");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("-?")]
|
[InlineData("-?")]
|
||||||
[InlineData("-h")]
|
[InlineData("-h")]
|
||||||
@ -88,6 +63,27 @@ public sealed partial class CommandAppTests
|
|||||||
result.Output.ShouldContain("-v, --version Prints version information");
|
result.Output.ShouldContain("-v, --version Prints version information");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("-?")]
|
||||||
|
[InlineData("-h")]
|
||||||
|
[InlineData("--help")]
|
||||||
|
public void Help_Should_Not_Include_Application_Version_Flag_For_Command(string helpOption)
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var fixture = new CommandAppTester();
|
||||||
|
fixture.Configure(configurator =>
|
||||||
|
{
|
||||||
|
configurator.SetApplicationVersion("1.0");
|
||||||
|
configurator.AddCommand<EmptyCommand>("empty");
|
||||||
|
});
|
||||||
|
|
||||||
|
// When
|
||||||
|
var result = fixture.Run("empty", helpOption);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
result.Output.ShouldNotContain("-v, --version Prints version information");
|
||||||
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("-?")]
|
[InlineData("-?")]
|
||||||
[InlineData("-h")]
|
[InlineData("-h")]
|
||||||
@ -125,39 +121,17 @@ public sealed partial class CommandAppTests
|
|||||||
configurator.SetApplicationVersion("1.0");
|
configurator.SetApplicationVersion("1.0");
|
||||||
configurator.AddBranch<EmptyCommandSettings>("branch", branch =>
|
configurator.AddBranch<EmptyCommandSettings>("branch", branch =>
|
||||||
{
|
{
|
||||||
branch.AddCommand<EmptyCommand>("hello");
|
branch.AddCommand<EmptyCommand>("empty");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// When
|
// When
|
||||||
var result = fixture.Run("branch", "hello", helpOption);
|
var result = fixture.Run("branch", "empty", helpOption);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
result.Output.ShouldNotContain("-v, --version Prints version information");
|
result.Output.ShouldNotContain("-v, --version Prints version information");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData("-?")]
|
|
||||||
[InlineData("-h")]
|
|
||||||
[InlineData("--help")]
|
|
||||||
public void Help_Should_Include_Command_Version_Flag_For_Command(string helpOption)
|
|
||||||
{
|
|
||||||
// Given
|
|
||||||
var fixture = new CommandAppTester();
|
|
||||||
fixture.Configure(configurator =>
|
|
||||||
{
|
|
||||||
configurator.SetApplicationVersion("1.0");
|
|
||||||
configurator.AddCommand<Spectre.Console.Tests.Data.VersionCommand>("empty");
|
|
||||||
});
|
|
||||||
|
|
||||||
// When
|
|
||||||
var result = fixture.Run("empty", helpOption);
|
|
||||||
|
|
||||||
// Then
|
|
||||||
result.Output.ShouldContain("-v, --version The command version");
|
|
||||||
result.Output.ShouldNotContain("-v, --version Prints version information");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// When a command with a version flag in the settings is set as the application default command,
|
/// When a command with a version flag in the settings is set as the application default command,
|
||||||
/// then override the in-built Application Version flag with the command version flag instead.
|
/// then override the in-built Application Version flag with the command version flag instead.
|
||||||
@ -186,6 +160,28 @@ public sealed partial class CommandAppTests
|
|||||||
result.Output.ShouldNotContain("-v, --version Prints version information");
|
result.Output.ShouldNotContain("-v, --version Prints version information");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("-?")]
|
||||||
|
[InlineData("-h")]
|
||||||
|
[InlineData("--help")]
|
||||||
|
public void Help_Should_Include_Command_Version_Flag_For_Command(string helpOption)
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var fixture = new CommandAppTester();
|
||||||
|
fixture.Configure(configurator =>
|
||||||
|
{
|
||||||
|
configurator.SetApplicationVersion("1.0");
|
||||||
|
configurator.AddCommand<Spectre.Console.Tests.Data.VersionCommand>("hello");
|
||||||
|
});
|
||||||
|
|
||||||
|
// When
|
||||||
|
var result = fixture.Run("hello", helpOption);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
result.Output.ShouldContain("-v, --version The command version");
|
||||||
|
result.Output.ShouldNotContain("-v, --version Prints version information");
|
||||||
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("-?")]
|
[InlineData("-?")]
|
||||||
[InlineData("-h")]
|
[InlineData("-h")]
|
||||||
@ -235,8 +231,6 @@ public sealed partial class CommandAppTests
|
|||||||
result.Output.ShouldContain("-v, --version The command version");
|
result.Output.ShouldContain("-v, --version The command version");
|
||||||
result.Output.ShouldNotContain("-v, --version Prints version information");
|
result.Output.ShouldNotContain("-v, --version Prints version information");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user