-
-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1739 from FrankRay78/1738-CommandAppTester-is-tri…
…mming-TestConsole-output
- Loading branch information
Showing
5 changed files
with
86 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/Spectre.Console.Testing/Cli/CommandAppTesterSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Spectre.Console.Testing; | ||
|
||
/// <summary> | ||
/// Represents the configuration settings for the <see cref="CommandAppTester"/> class. | ||
/// </summary> | ||
public sealed class CommandAppTesterSettings | ||
{ | ||
/// <summary> | ||
/// Gets or sets a value indicating whether whitespace should be trimmed from the console output. | ||
/// </summary> | ||
/// <remarks> | ||
/// When enabled, leading and trailing whitespace from the console output and trailing whitespace from each line will be trimmed. | ||
/// </remarks> | ||
public bool TrimConsoleOutput { get; set; } = true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/Tests/Spectre.Console.Cli.Tests/Unit/Testing/CommandAppTesterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
using System; | ||
|
||
namespace Spectre.Console.Tests.Unit.Cli.Testing; | ||
|
||
public sealed class CommandAppTesterTests | ||
{ | ||
private class CommandAppTesterCommand : Command<OptionalArgumentWithDefaultValueSettings> | ||
{ | ||
private readonly IAnsiConsole _console; | ||
|
||
public CommandAppTesterCommand(IAnsiConsole console) | ||
{ | ||
_console = console; | ||
} | ||
|
||
public override int Execute(CommandContext context, OptionalArgumentWithDefaultValueSettings settings) | ||
{ | ||
_console.Write(settings.Greeting); | ||
return 0; | ||
} | ||
} | ||
|
||
[Theory] | ||
[InlineData(false, " Hello ", " Hello ")] | ||
[InlineData(true, " Hello ", "Hello")] | ||
[InlineData(false, " Hello \n World ", " Hello \n World ")] | ||
[InlineData(true, " Hello \n World ", "Hello\n World")] | ||
public void Should_Respect_Trim_Setting(bool trim, string actual, string expected) | ||
{ | ||
// Given | ||
var settings = new CommandAppTesterSettings { TrimConsoleOutput = trim }; | ||
|
||
var app = new CommandAppTester(settings); | ||
app.SetDefaultCommand<CommandAppTesterCommand>(); | ||
app.Configure(config => | ||
{ | ||
config.PropagateExceptions(); | ||
}); | ||
|
||
// When | ||
var result = app.Run(actual); | ||
|
||
// Then | ||
result.Output.ShouldBe(expected); | ||
} | ||
} |