mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Use CSharpier
This commit is contained in:
@@ -11,9 +11,7 @@ namespace CliFx.Tests;
|
||||
public class ApplicationSpecs : SpecsBase
|
||||
{
|
||||
public ApplicationSpecs(ITestOutputHelper testOutput)
|
||||
: base(testOutput)
|
||||
{
|
||||
}
|
||||
: base(testOutput) { }
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_create_an_application_with_the_default_configuration()
|
||||
@@ -24,10 +22,7 @@ public class ApplicationSpecs : SpecsBase
|
||||
.UseConsole(FakeConsole)
|
||||
.Build();
|
||||
|
||||
var exitCode = await app.RunAsync(
|
||||
Array.Empty<string>(),
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
var exitCode = await app.RunAsync(Array.Empty<string>(), new Dictionary<string, string>());
|
||||
|
||||
// Assert
|
||||
exitCode.Should().Be(0);
|
||||
@@ -40,8 +35,8 @@ public class ApplicationSpecs : SpecsBase
|
||||
var app = new CliApplicationBuilder()
|
||||
.AddCommand<NoOpCommand>()
|
||||
.AddCommandsFrom(typeof(NoOpCommand).Assembly)
|
||||
.AddCommands(new[] {typeof(NoOpCommand)})
|
||||
.AddCommandsFrom(new[] {typeof(NoOpCommand).Assembly})
|
||||
.AddCommands(new[] { typeof(NoOpCommand) })
|
||||
.AddCommandsFrom(new[] { typeof(NoOpCommand).Assembly })
|
||||
.AddCommandsFromThisAssembly()
|
||||
.AllowDebugMode()
|
||||
.AllowPreviewMode()
|
||||
@@ -53,10 +48,7 @@ public class ApplicationSpecs : SpecsBase
|
||||
.UseTypeActivator(Activator.CreateInstance!)
|
||||
.Build();
|
||||
|
||||
var exitCode = await app.RunAsync(
|
||||
Array.Empty<string>(),
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
var exitCode = await app.RunAsync(Array.Empty<string>(), new Dictionary<string, string>());
|
||||
|
||||
// Assert
|
||||
exitCode.Should().Be(0);
|
||||
@@ -71,10 +63,7 @@ public class ApplicationSpecs : SpecsBase
|
||||
.UseConsole(FakeConsole)
|
||||
.Build();
|
||||
|
||||
var exitCode = await app.RunAsync(
|
||||
Array.Empty<string>(),
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
var exitCode = await app.RunAsync(Array.Empty<string>(), new Dictionary<string, string>());
|
||||
|
||||
// Assert
|
||||
exitCode.Should().NotBe(0);
|
||||
@@ -82,4 +71,4 @@ public class ApplicationSpecs : SpecsBase
|
||||
var stdErr = FakeConsole.ReadErrorString();
|
||||
stdErr.Should().Contain("not a valid command");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,7 @@ namespace CliFx.Tests;
|
||||
public class CancellationSpecs : SpecsBase
|
||||
{
|
||||
public CancellationSpecs(ITestOutputHelper testOutput)
|
||||
: base(testOutput)
|
||||
{
|
||||
}
|
||||
: base(testOutput) { }
|
||||
|
||||
[Fact(Timeout = 15000)]
|
||||
public async Task I_can_configure_the_command_to_listen_to_the_interrupt_signal()
|
||||
@@ -41,24 +39,20 @@ public class CancellationSpecs : SpecsBase
|
||||
PipeTarget.ToStringBuilder(stdOutBuffer)
|
||||
);
|
||||
|
||||
var command =
|
||||
Cli.Wrap(Dummy.Program.FilePath).WithArguments("cancel-test") |
|
||||
pipeTarget;
|
||||
var command = Cli.Wrap(Dummy.Program.FilePath).WithArguments("cancel-test") | pipeTarget;
|
||||
|
||||
// Act & assert
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(async () =>
|
||||
await command.ExecuteAsync(
|
||||
// Forceful cancellation (not required because we have a timeout)
|
||||
CancellationToken.None,
|
||||
// Graceful cancellation
|
||||
cts.Token
|
||||
)
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(
|
||||
async () =>
|
||||
await command.ExecuteAsync(
|
||||
// Forceful cancellation (not required because we have a timeout)
|
||||
CancellationToken.None,
|
||||
// Graceful cancellation
|
||||
cts.Token
|
||||
)
|
||||
);
|
||||
|
||||
stdOutBuffer.ToString().Trim().Should().ConsistOfLines(
|
||||
"Started.",
|
||||
"Cancelled."
|
||||
);
|
||||
stdOutBuffer.ToString().Trim().Should().ConsistOfLines("Started.", "Cancelled.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -111,9 +105,6 @@ public class CancellationSpecs : SpecsBase
|
||||
exitCode.Should().NotBe(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Trim().Should().ConsistOfLines(
|
||||
"Started.",
|
||||
"Cancelled."
|
||||
);
|
||||
stdOut.Trim().Should().ConsistOfLines("Started.", "Cancelled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<PackageReference Include="Basic.Reference.Assemblies.Net70" Version="1.4.2" />
|
||||
<PackageReference Include="CliWrap" Version="3.6.4" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" PrivateAssets="all" />
|
||||
<PackageReference Include="CSharpier.MsBuild" Version="0.25.0" PrivateAssets="all" />
|
||||
<PackageReference Include="FluentAssertions" Version="6.11.0" />
|
||||
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.2" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" />
|
||||
|
||||
@@ -17,9 +17,7 @@ namespace CliFx.Tests;
|
||||
public class ConsoleSpecs : SpecsBase
|
||||
{
|
||||
public ConsoleSpecs(ITestOutputHelper testOutput)
|
||||
: base(testOutput)
|
||||
{
|
||||
}
|
||||
: base(testOutput) { }
|
||||
|
||||
[Fact(Timeout = 15000)]
|
||||
public async Task I_can_run_the_application_with_the_default_console_implementation_to_interact_with_the_system_console()
|
||||
@@ -28,8 +26,7 @@ public class ConsoleSpecs : SpecsBase
|
||||
|
||||
// Arrange
|
||||
var command =
|
||||
"Hello world" |
|
||||
Cli.Wrap(Dummy.Program.FilePath).WithArguments("console-test");
|
||||
"Hello world" | Cli.Wrap(Dummy.Program.FilePath).WithArguments("console-test");
|
||||
|
||||
// Act
|
||||
var result = await command.ExecuteBufferedAsync();
|
||||
@@ -205,10 +202,6 @@ public class ConsoleSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Trim().Should().ConsistOfLines(
|
||||
"D0",
|
||||
"A",
|
||||
"Backspace"
|
||||
);
|
||||
stdOut.Trim().Should().ConsistOfLines("D0", "A", "Backspace");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,7 @@ namespace CliFx.Tests;
|
||||
public class ConversionSpecs : SpecsBase
|
||||
{
|
||||
public ConversionSpecs(ITestOutputHelper testOutput)
|
||||
: base(testOutput)
|
||||
{
|
||||
}
|
||||
: base(testOutput) { }
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_bind_a_parameter_or_an_option_to_a_string_property()
|
||||
@@ -44,7 +42,7 @@ public class ConversionSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-f", "xyz"},
|
||||
new[] { "-f", "xyz" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -84,7 +82,7 @@ public class ConversionSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-f", "xyz"},
|
||||
new[] { "-f", "xyz" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -133,12 +131,7 @@ public class ConversionSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[]
|
||||
{
|
||||
"-f", "true",
|
||||
"-b", "false",
|
||||
"-c"
|
||||
},
|
||||
new[] { "-f", "true", "-b", "false", "-c" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -146,11 +139,7 @@ public class ConversionSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ConsistOfLines(
|
||||
"Foo = True",
|
||||
"Bar = False",
|
||||
"Baz = True"
|
||||
);
|
||||
stdOut.Should().ConsistOfLines("Foo = True", "Bar = False", "Baz = True");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -182,7 +171,7 @@ public class ConversionSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-f", "32"},
|
||||
new[] { "-f", "32" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -222,7 +211,7 @@ public class ConversionSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-f", "32.14"},
|
||||
new[] { "-f", "32.14" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -262,7 +251,7 @@ public class ConversionSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-f", "1995-04-28Z"},
|
||||
new[] { "-f", "1995-04-28Z" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -302,7 +291,7 @@ public class ConversionSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-f", "12:34:56"},
|
||||
new[] { "-f", "12:34:56" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -344,7 +333,7 @@ public class ConversionSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-f", "two"},
|
||||
new[] { "-f", "two" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -389,7 +378,7 @@ public class ConversionSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-b", "123"},
|
||||
new[] { "-b", "123" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -397,10 +386,7 @@ public class ConversionSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ConsistOfLines(
|
||||
"Foo = ",
|
||||
"Bar = 123"
|
||||
);
|
||||
stdOut.Should().ConsistOfLines("Foo = ", "Bar = 123");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -439,7 +425,7 @@ public class ConversionSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-b", "two"},
|
||||
new[] { "-b", "two" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -447,10 +433,7 @@ public class ConversionSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ConsistOfLines(
|
||||
"Foo = ",
|
||||
"Bar = 2"
|
||||
);
|
||||
stdOut.Should().ConsistOfLines("Foo = ", "Bar = 2");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -489,7 +472,7 @@ public class ConversionSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-f", "xyz"},
|
||||
new[] { "-f", "xyz" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -554,7 +537,7 @@ public class ConversionSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-f", "hello", "-b", "world"},
|
||||
new[] { "-f", "hello", "-b", "world" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -562,10 +545,7 @@ public class ConversionSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ConsistOfLines(
|
||||
"Foo = hello",
|
||||
"Bar = world"
|
||||
);
|
||||
stdOut.Should().ConsistOfLines("Foo = hello", "Bar = world");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -603,7 +583,7 @@ public class ConversionSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-f", "hello world"},
|
||||
new[] { "-f", "hello world" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -645,7 +625,7 @@ public class ConversionSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-f", "one", "two", "three"},
|
||||
new[] { "-f", "one", "two", "three" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -653,11 +633,7 @@ public class ConversionSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ConsistOfLines(
|
||||
"one",
|
||||
"two",
|
||||
"three"
|
||||
);
|
||||
stdOut.Should().ConsistOfLines("one", "two", "three");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -691,7 +667,7 @@ public class ConversionSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-f", "one", "two", "three"},
|
||||
new[] { "-f", "one", "two", "three" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -699,11 +675,7 @@ public class ConversionSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ConsistOfLines(
|
||||
"one",
|
||||
"two",
|
||||
"three"
|
||||
);
|
||||
stdOut.Should().ConsistOfLines("one", "two", "three");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -737,7 +709,7 @@ public class ConversionSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-f", "one", "two", "three"},
|
||||
new[] { "-f", "one", "two", "three" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -745,11 +717,7 @@ public class ConversionSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ConsistOfLines(
|
||||
"one",
|
||||
"two",
|
||||
"three"
|
||||
);
|
||||
stdOut.Should().ConsistOfLines("one", "two", "three");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -783,7 +751,7 @@ public class ConversionSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-f", "1", "13", "27"},
|
||||
new[] { "-f", "1", "13", "27" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -791,11 +759,7 @@ public class ConversionSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ConsistOfLines(
|
||||
"1",
|
||||
"13",
|
||||
"27"
|
||||
);
|
||||
stdOut.Should().ConsistOfLines("1", "13", "27");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -827,7 +791,7 @@ public class ConversionSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-f", "xyz"},
|
||||
new[] { "-f", "xyz" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -870,7 +834,7 @@ public class ConversionSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-f", "one", "two"},
|
||||
new[] { "-f", "one", "two" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -906,7 +870,7 @@ public class ConversionSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-f", "12.34"},
|
||||
new[] { "-f", "12.34" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -952,7 +916,7 @@ public class ConversionSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-f", "12"},
|
||||
new[] { "-f", "12" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -997,7 +961,7 @@ public class ConversionSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-f", "bar"},
|
||||
new[] { "-f", "bar" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -1007,4 +971,4 @@ public class ConversionSpecs : SpecsBase
|
||||
var stdErr = FakeConsole.ReadErrorString();
|
||||
stdErr.Should().Contain("Hello world");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,7 @@ namespace CliFx.Tests;
|
||||
public class DirectivesSpecs : SpecsBase
|
||||
{
|
||||
public DirectivesSpecs(ITestOutputHelper testOutput)
|
||||
: base(testOutput)
|
||||
{
|
||||
}
|
||||
: base(testOutput) { }
|
||||
|
||||
[Fact(Timeout = 15000)]
|
||||
public async Task I_can_use_the_debug_directive_to_make_the_application_wait_for_the_debugger_to_attach()
|
||||
@@ -32,9 +30,7 @@ public class DirectivesSpecs : SpecsBase
|
||||
cts.Cancel();
|
||||
}
|
||||
|
||||
var command =
|
||||
Cli.Wrap(Dummy.Program.FilePath).WithArguments("[debug]") |
|
||||
HandleStdOut;
|
||||
var command = Cli.Wrap(Dummy.Program.FilePath).WithArguments("[debug]") | HandleStdOut;
|
||||
|
||||
// Act & assert
|
||||
try
|
||||
@@ -70,22 +66,29 @@ public class DirectivesSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"[preview]", "cmd", "param", "-abc", "--option", "foo"},
|
||||
new Dictionary<string, string>
|
||||
{
|
||||
["ENV_QOP"] = "hello",
|
||||
["ENV_KIL"] = "world"
|
||||
}
|
||||
new[] { "[preview]", "cmd", "param", "-abc", "--option", "foo" },
|
||||
new Dictionary<string, string> { ["ENV_QOP"] = "hello", ["ENV_KIL"] = "world" }
|
||||
);
|
||||
|
||||
// Assert
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ContainAllInOrder(
|
||||
"cmd", "<param>", "[-a]", "[-b]", "[-c]", "[--option \"foo\"]",
|
||||
"ENV_QOP", "=", "\"hello\"",
|
||||
"ENV_KIL", "=", "\"world\""
|
||||
);
|
||||
stdOut
|
||||
.Should()
|
||||
.ContainAllInOrder(
|
||||
"cmd",
|
||||
"<param>",
|
||||
"[-a]",
|
||||
"[-b]",
|
||||
"[-c]",
|
||||
"[--option \"foo\"]",
|
||||
"ENV_QOP",
|
||||
"=",
|
||||
"\"hello\"",
|
||||
"ENV_KIL",
|
||||
"=",
|
||||
"\"world\""
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,7 @@ namespace CliFx.Tests;
|
||||
public class EnvironmentSpecs : SpecsBase
|
||||
{
|
||||
public EnvironmentSpecs(ITestOutputHelper testOutput)
|
||||
: base(testOutput)
|
||||
{
|
||||
}
|
||||
: base(testOutput) { }
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_configure_an_option_to_fall_back_to_an_environment_variable_if_the_user_does_not_provide_the_corresponding_argument()
|
||||
@@ -53,22 +51,15 @@ public class EnvironmentSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--foo", "42"},
|
||||
new Dictionary<string, string>
|
||||
{
|
||||
["ENV_FOO"] = "100",
|
||||
["ENV_BAR"] = "200"
|
||||
}
|
||||
new[] { "--foo", "42" },
|
||||
new Dictionary<string, string> { ["ENV_FOO"] = "100", ["ENV_BAR"] = "200" }
|
||||
);
|
||||
|
||||
// Assert
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Trim().Should().ConsistOfLines(
|
||||
"42",
|
||||
"200"
|
||||
);
|
||||
stdOut.Trim().Should().ConsistOfLines("42", "200");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -103,20 +94,14 @@ public class EnvironmentSpecs : SpecsBase
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
Array.Empty<string>(),
|
||||
new Dictionary<string, string>
|
||||
{
|
||||
["ENV_FOO"] = $"bar{Path.PathSeparator}baz"
|
||||
}
|
||||
new Dictionary<string, string> { ["ENV_FOO"] = $"bar{Path.PathSeparator}baz" }
|
||||
);
|
||||
|
||||
// Assert
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ConsistOfLines(
|
||||
"bar",
|
||||
"baz"
|
||||
);
|
||||
stdOut.Should().ConsistOfLines("bar", "baz");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -149,10 +134,7 @@ public class EnvironmentSpecs : SpecsBase
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
Array.Empty<string>(),
|
||||
new Dictionary<string, string>
|
||||
{
|
||||
["ENV_FOO"] = $"bar{Path.PathSeparator}baz"
|
||||
}
|
||||
new Dictionary<string, string> { ["ENV_FOO"] = $"bar{Path.PathSeparator}baz" }
|
||||
);
|
||||
|
||||
// Assert
|
||||
@@ -171,9 +153,7 @@ public class EnvironmentSpecs : SpecsBase
|
||||
// Arrange
|
||||
var command = Cli.Wrap(Dummy.Program.FilePath)
|
||||
.WithArguments("env-test")
|
||||
.WithEnvironmentVariables(e => e
|
||||
.Set("ENV_TARGET", "Mars")
|
||||
);
|
||||
.WithEnvironmentVariables(e => e.Set("ENV_TARGET", "Mars"));
|
||||
|
||||
// Act
|
||||
var result = await command.ExecuteBufferedAsync();
|
||||
@@ -181,4 +161,4 @@ public class EnvironmentSpecs : SpecsBase
|
||||
// Assert
|
||||
result.StandardOutput.Trim().Should().Be("Hello Mars!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,7 @@ namespace CliFx.Tests;
|
||||
public class ErrorReportingSpecs : SpecsBase
|
||||
{
|
||||
public ErrorReportingSpecs(ITestOutputHelper testOutput)
|
||||
: base(testOutput)
|
||||
{
|
||||
}
|
||||
: base(testOutput) { }
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_throw_an_exception_in_a_command_to_report_an_error_with_a_stacktrace()
|
||||
@@ -50,10 +48,9 @@ public class ErrorReportingSpecs : SpecsBase
|
||||
stdOut.Should().BeEmpty();
|
||||
|
||||
var stdErr = FakeConsole.ReadErrorString();
|
||||
stdErr.Should().ContainAllInOrder(
|
||||
"System.Exception", "Something went wrong",
|
||||
"at", "CliFx."
|
||||
);
|
||||
stdErr
|
||||
.Should()
|
||||
.ContainAllInOrder("System.Exception", "Something went wrong", "at", "CliFx.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -90,11 +87,16 @@ public class ErrorReportingSpecs : SpecsBase
|
||||
stdOut.Should().BeEmpty();
|
||||
|
||||
var stdErr = FakeConsole.ReadErrorString();
|
||||
stdErr.Should().ContainAllInOrder(
|
||||
"System.Exception", "Something went wrong",
|
||||
"System.Exception", "Another exception",
|
||||
"at", "CliFx."
|
||||
);
|
||||
stdErr
|
||||
.Should()
|
||||
.ContainAllInOrder(
|
||||
"System.Exception",
|
||||
"Something went wrong",
|
||||
"System.Exception",
|
||||
"Another exception",
|
||||
"at",
|
||||
"CliFx."
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -168,10 +170,7 @@ public class ErrorReportingSpecs : SpecsBase
|
||||
stdOut.Should().BeEmpty();
|
||||
|
||||
var stdErr = FakeConsole.ReadErrorString();
|
||||
stdErr.Should().ContainAllInOrder(
|
||||
"CliFx.Exceptions.CommandException",
|
||||
"at", "CliFx."
|
||||
);
|
||||
stdErr.Should().ContainAllInOrder("CliFx.Exceptions.CommandException", "at", "CliFx.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -211,4 +210,4 @@ public class ErrorReportingSpecs : SpecsBase
|
||||
var stdErr = FakeConsole.ReadErrorString();
|
||||
stdErr.Trim().Should().Be("Something went wrong");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,7 @@ namespace CliFx.Tests;
|
||||
public class HelpTextSpecs : SpecsBase
|
||||
{
|
||||
public HelpTextSpecs(ITestOutputHelper testOutput)
|
||||
: base(testOutput)
|
||||
{
|
||||
}
|
||||
: base(testOutput) { }
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_request_the_help_text_by_running_the_application_without_arguments_if_the_default_command_is_not_defined()
|
||||
@@ -61,7 +59,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--help"},
|
||||
new[] { "--help" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -101,7 +99,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--help"},
|
||||
new[] { "--help" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -146,7 +144,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"cmd", "--help"},
|
||||
new[] { "cmd", "--help" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -191,7 +189,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"cmd", "sub", "--help"},
|
||||
new[] { "cmd", "sub", "--help" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -214,7 +212,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"invalid-command", "--invalid-option"},
|
||||
new[] { "invalid-command", "--invalid-option" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -241,7 +239,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--help"},
|
||||
new[] { "--help" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -249,11 +247,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ContainAll(
|
||||
"App title",
|
||||
"App description",
|
||||
"App version"
|
||||
);
|
||||
stdOut.Should().ContainAll("App title", "App description", "App version");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -278,7 +272,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--help"},
|
||||
new[] { "--help" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -286,10 +280,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ContainAllInOrder(
|
||||
"DESCRIPTION",
|
||||
"Description of the default command."
|
||||
);
|
||||
stdOut.Should().ContainAllInOrder("DESCRIPTION", "Description of the default command.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -320,7 +311,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--help"},
|
||||
new[] { "--help" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -328,10 +319,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ContainAllInOrder(
|
||||
"USAGE",
|
||||
"[command]", "[...]"
|
||||
);
|
||||
stdOut.Should().ContainAllInOrder("USAGE", "[command]", "[...]");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -365,7 +353,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--help"},
|
||||
new[] { "--help" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -373,10 +361,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ContainAllInOrder(
|
||||
"USAGE",
|
||||
"<foo>", "<bar>", "<baz...>"
|
||||
);
|
||||
stdOut.Should().ContainAllInOrder("USAGE", "<foo>", "<bar>", "<baz...>");
|
||||
}
|
||||
|
||||
// https://github.com/Tyrrrz/CliFx/issues/117
|
||||
@@ -425,10 +410,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ContainAllInOrder(
|
||||
"USAGE",
|
||||
"<foo>", "<bar>", "<baz...>"
|
||||
);
|
||||
stdOut.Should().ContainAllInOrder("USAGE", "<foo>", "<bar>", "<baz...>");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -462,7 +444,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--help"},
|
||||
new[] { "--help" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -470,10 +452,9 @@ public class HelpTextSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ContainAllInOrder(
|
||||
"USAGE",
|
||||
"--foo <value>", "--baz <values...>", "[options]"
|
||||
);
|
||||
stdOut
|
||||
.Should()
|
||||
.ContainAllInOrder("USAGE", "--foo <value>", "--baz <values...>", "[options]");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -504,7 +485,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--help"},
|
||||
new[] { "--help" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -512,12 +493,16 @@ public class HelpTextSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ContainAllInOrder(
|
||||
"PARAMETERS",
|
||||
"foo", "Description of foo.",
|
||||
"OPTIONS",
|
||||
"--bar", "Description of bar."
|
||||
);
|
||||
stdOut
|
||||
.Should()
|
||||
.ContainAllInOrder(
|
||||
"PARAMETERS",
|
||||
"foo",
|
||||
"Description of foo.",
|
||||
"OPTIONS",
|
||||
"--bar",
|
||||
"Description of bar."
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -542,7 +527,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--help"},
|
||||
new[] { "--help" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -550,11 +535,16 @@ public class HelpTextSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ContainAllInOrder(
|
||||
"OPTIONS",
|
||||
"-h", "--help", "Shows help text",
|
||||
"--version", "Shows version information"
|
||||
);
|
||||
stdOut
|
||||
.Should()
|
||||
.ContainAllInOrder(
|
||||
"OPTIONS",
|
||||
"-h",
|
||||
"--help",
|
||||
"Shows help text",
|
||||
"--version",
|
||||
"Shows version information"
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -579,7 +569,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"cmd", "--help"},
|
||||
new[] { "cmd", "--help" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -588,14 +578,9 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
|
||||
stdOut.Should().ContainAllInOrder(
|
||||
"OPTIONS",
|
||||
"-h", "--help", "Shows help text"
|
||||
);
|
||||
stdOut.Should().ContainAllInOrder("OPTIONS", "-h", "--help", "Shows help text");
|
||||
|
||||
stdOut.Should().NotContainAny(
|
||||
"--version", "Shows version information"
|
||||
);
|
||||
stdOut.Should().NotContainAny("--version", "Shows version information");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -628,7 +613,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--help"},
|
||||
new[] { "--help" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -636,12 +621,22 @@ public class HelpTextSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ContainAllInOrder(
|
||||
"PARAMETERS",
|
||||
"foo", "Choices:", "One", "Two", "Three",
|
||||
"OPTIONS",
|
||||
"--bar", "Choices:", "One", "Two", "Three"
|
||||
);
|
||||
stdOut
|
||||
.Should()
|
||||
.ContainAllInOrder(
|
||||
"PARAMETERS",
|
||||
"foo",
|
||||
"Choices:",
|
||||
"One",
|
||||
"Two",
|
||||
"Three",
|
||||
"OPTIONS",
|
||||
"--bar",
|
||||
"Choices:",
|
||||
"One",
|
||||
"Two",
|
||||
"Three"
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -674,7 +669,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--help"},
|
||||
new[] { "--help" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -682,12 +677,22 @@ public class HelpTextSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ContainAllInOrder(
|
||||
"PARAMETERS",
|
||||
"foo", "Choices:", "One", "Two", "Three",
|
||||
"OPTIONS",
|
||||
"--bar", "Choices:", "One", "Two", "Three"
|
||||
);
|
||||
stdOut
|
||||
.Should()
|
||||
.ContainAllInOrder(
|
||||
"PARAMETERS",
|
||||
"foo",
|
||||
"Choices:",
|
||||
"One",
|
||||
"Two",
|
||||
"Three",
|
||||
"OPTIONS",
|
||||
"--bar",
|
||||
"Choices:",
|
||||
"One",
|
||||
"Two",
|
||||
"Three"
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -720,7 +725,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--help"},
|
||||
new[] { "--help" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -728,12 +733,22 @@ public class HelpTextSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ContainAllInOrder(
|
||||
"PARAMETERS",
|
||||
"foo", "Choices:", "One", "Two", "Three",
|
||||
"OPTIONS",
|
||||
"--bar", "Choices:", "One", "Two", "Three"
|
||||
);
|
||||
stdOut
|
||||
.Should()
|
||||
.ContainAllInOrder(
|
||||
"PARAMETERS",
|
||||
"foo",
|
||||
"Choices:",
|
||||
"One",
|
||||
"Two",
|
||||
"Three",
|
||||
"OPTIONS",
|
||||
"--bar",
|
||||
"Choices:",
|
||||
"One",
|
||||
"Two",
|
||||
"Three"
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -766,7 +781,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--help"},
|
||||
new[] { "--help" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -774,11 +789,17 @@ public class HelpTextSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ContainAllInOrder(
|
||||
"OPTIONS",
|
||||
"--foo", "Environment variable:", "ENV_FOO",
|
||||
"--bar", "Environment variable:", "ENV_BAR"
|
||||
);
|
||||
stdOut
|
||||
.Should()
|
||||
.ContainAllInOrder(
|
||||
"OPTIONS",
|
||||
"--foo",
|
||||
"Environment variable:",
|
||||
"ENV_FOO",
|
||||
"--bar",
|
||||
"Environment variable:",
|
||||
"ENV_BAR"
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -829,7 +850,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--help"},
|
||||
new[] { "--help" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -838,16 +859,34 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
|
||||
stdOut.Should().ContainAllInOrder(
|
||||
"OPTIONS",
|
||||
"--foo", "Default:", "42",
|
||||
"--bar", "Default:", "hello",
|
||||
"--baz", "Default:", "one", "two", "three",
|
||||
"--qwe", "Default:", "True",
|
||||
"--qop", "Default:", "1337",
|
||||
"--zor", "Default:", "02:03:00",
|
||||
"--lol", "Default:", "Two"
|
||||
);
|
||||
stdOut
|
||||
.Should()
|
||||
.ContainAllInOrder(
|
||||
"OPTIONS",
|
||||
"--foo",
|
||||
"Default:",
|
||||
"42",
|
||||
"--bar",
|
||||
"Default:",
|
||||
"hello",
|
||||
"--baz",
|
||||
"Default:",
|
||||
"one",
|
||||
"two",
|
||||
"three",
|
||||
"--qwe",
|
||||
"Default:",
|
||||
"True",
|
||||
"--qop",
|
||||
"Default:",
|
||||
"1337",
|
||||
"--zor",
|
||||
"Default:",
|
||||
"02:03:00",
|
||||
"--lol",
|
||||
"Default:",
|
||||
"Two"
|
||||
);
|
||||
|
||||
stdOut.Should().NotContain("not printed");
|
||||
}
|
||||
@@ -892,7 +931,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--help"},
|
||||
new[] { "--help" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -901,20 +940,23 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
|
||||
stdOut.Should().ContainAllInOrder(
|
||||
"COMMANDS",
|
||||
"cmd1", "Description of one command.",
|
||||
"cmd2", "Description of another command.",
|
||||
// `cmd2 child` will appear as an immediate command because it does not
|
||||
// have a more specific parent.
|
||||
"cmd3 child", "Description of an orphaned command."
|
||||
);
|
||||
stdOut
|
||||
.Should()
|
||||
.ContainAllInOrder(
|
||||
"COMMANDS",
|
||||
"cmd1",
|
||||
"Description of one command.",
|
||||
"cmd2",
|
||||
"Description of another command.",
|
||||
// `cmd2 child` will appear as an immediate command because it does not
|
||||
// have a more specific parent.
|
||||
"cmd3 child",
|
||||
"Description of an orphaned command."
|
||||
);
|
||||
|
||||
// `cmd2 child` will still appear in the list of `cmd2` subcommands,
|
||||
// but its description will not be visible.
|
||||
stdOut.Should().NotContain(
|
||||
"Description of another command's child command."
|
||||
);
|
||||
stdOut.Should().NotContain("Description of another command's child command.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -963,7 +1005,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--help"},
|
||||
new[] { "--help" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -971,11 +1013,18 @@ public class HelpTextSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ContainAllInOrder(
|
||||
"COMMANDS",
|
||||
"cmd1", "Subcommands:", "cmd1 child1",
|
||||
"cmd2", "Subcommands:", "cmd2 child1", "cmd2 child2"
|
||||
);
|
||||
stdOut
|
||||
.Should()
|
||||
.ContainAllInOrder(
|
||||
"COMMANDS",
|
||||
"cmd1",
|
||||
"Subcommands:",
|
||||
"cmd1 child1",
|
||||
"cmd2",
|
||||
"Subcommands:",
|
||||
"cmd2 child1",
|
||||
"cmd2 child2"
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -990,7 +1039,7 @@ public class HelpTextSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--version"},
|
||||
new[] { "--version" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -1000,4 +1049,4 @@ public class HelpTextSpecs : SpecsBase
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Trim().Should().Be("v6.9");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,7 @@ namespace CliFx.Tests;
|
||||
public class OptionBindingSpecs : SpecsBase
|
||||
{
|
||||
public OptionBindingSpecs(ITestOutputHelper testOutput)
|
||||
: base(testOutput)
|
||||
{
|
||||
}
|
||||
: base(testOutput) { }
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_bind_an_option_to_a_property_and_get_the_value_from_the_corresponding_argument_by_name()
|
||||
@@ -45,7 +43,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--foo"},
|
||||
new[] { "--foo" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -84,10 +82,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
.Build();
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-f"},
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
var exitCode = await application.RunAsync(new[] { "-f" }, new Dictionary<string, string>());
|
||||
|
||||
// Assert
|
||||
exitCode.Should().Be(0);
|
||||
@@ -130,11 +125,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[]
|
||||
{
|
||||
"--foo", "one",
|
||||
"--bar", "two"
|
||||
},
|
||||
new[] { "--foo", "one", "--bar", "two" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -142,10 +133,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ConsistOfLines(
|
||||
"Foo = one",
|
||||
"Bar = two"
|
||||
);
|
||||
stdOut.Should().ConsistOfLines("Foo = one", "Bar = two");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -182,11 +170,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[]
|
||||
{
|
||||
"-f", "one",
|
||||
"-b", "two"
|
||||
},
|
||||
new[] { "-f", "one", "-b", "two" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -194,10 +178,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ConsistOfLines(
|
||||
"Foo = one",
|
||||
"Bar = two"
|
||||
);
|
||||
stdOut.Should().ConsistOfLines("Foo = one", "Bar = two");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -234,7 +215,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-fb", "value"},
|
||||
new[] { "-fb", "value" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -242,10 +223,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ConsistOfLines(
|
||||
"Foo = ",
|
||||
"Bar = value"
|
||||
);
|
||||
stdOut.Should().ConsistOfLines("Foo = ", "Bar = value");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -279,7 +257,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--foo", "one", "two", "three"},
|
||||
new[] { "--foo", "one", "two", "three" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -287,11 +265,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ConsistOfLines(
|
||||
"one",
|
||||
"two",
|
||||
"three"
|
||||
);
|
||||
stdOut.Should().ConsistOfLines("one", "two", "three");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -325,7 +299,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"-f", "one", "two", "three"},
|
||||
new[] { "-f", "one", "two", "three" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -333,11 +307,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ConsistOfLines(
|
||||
"one",
|
||||
"two",
|
||||
"three"
|
||||
);
|
||||
stdOut.Should().ConsistOfLines("one", "two", "three");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -371,12 +341,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[]
|
||||
{
|
||||
"--foo", "one",
|
||||
"--foo", "two",
|
||||
"--foo", "three"
|
||||
},
|
||||
new[] { "--foo", "one", "--foo", "two", "--foo", "three" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -384,11 +349,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ConsistOfLines(
|
||||
"one",
|
||||
"two",
|
||||
"three"
|
||||
);
|
||||
stdOut.Should().ConsistOfLines("one", "two", "three");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -422,12 +383,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[]
|
||||
{
|
||||
"-f", "one",
|
||||
"-f", "two",
|
||||
"-f", "three"
|
||||
},
|
||||
new[] { "-f", "one", "-f", "two", "-f", "three" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -435,11 +391,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ConsistOfLines(
|
||||
"one",
|
||||
"two",
|
||||
"three"
|
||||
);
|
||||
stdOut.Should().ConsistOfLines("one", "two", "three");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -473,12 +425,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[]
|
||||
{
|
||||
"--foo", "one",
|
||||
"-f", "two",
|
||||
"--foo", "three"
|
||||
},
|
||||
new[] { "--foo", "one", "-f", "two", "--foo", "three" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -486,11 +433,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ConsistOfLines(
|
||||
"one",
|
||||
"two",
|
||||
"three"
|
||||
);
|
||||
stdOut.Should().ConsistOfLines("one", "two", "three");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -527,7 +470,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--foo", "one"},
|
||||
new[] { "--foo", "one" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -535,10 +478,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ConsistOfLines(
|
||||
"Foo = one",
|
||||
"Bar = hello"
|
||||
);
|
||||
stdOut.Should().ConsistOfLines("Foo = one", "Bar = hello");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -604,24 +544,13 @@ public class OptionBindingSpecs : SpecsBase
|
||||
.Build();
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[]
|
||||
{
|
||||
"--foo", "42",
|
||||
"--bar",
|
||||
"--baz", "xyz"
|
||||
}
|
||||
);
|
||||
var exitCode = await application.RunAsync(new[] { "--foo", "42", "--bar", "--baz", "xyz" });
|
||||
|
||||
// Assert
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ConsistOfLines(
|
||||
"Foo = 42",
|
||||
"Bar = True",
|
||||
"Baz = xyz"
|
||||
);
|
||||
stdOut.Should().ConsistOfLines("Foo = 42", "Bar = True", "Baz = xyz");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -653,7 +582,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--foo", "-13"},
|
||||
new[] { "--foo", "-13" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -725,7 +654,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--foo"},
|
||||
new[] { "--foo" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -761,7 +690,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--foo"},
|
||||
new[] { "--foo" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -797,11 +726,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[]
|
||||
{
|
||||
"--foo", "one",
|
||||
"--bar", "two"
|
||||
},
|
||||
new[] { "--foo", "one", "--bar", "two" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -837,7 +762,7 @@ public class OptionBindingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"--foo", "one", "two", "three"},
|
||||
new[] { "--foo", "one", "two", "three" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -847,4 +772,4 @@ public class OptionBindingSpecs : SpecsBase
|
||||
var stdErr = FakeConsole.ReadErrorString();
|
||||
stdErr.Should().Contain("expects a single argument, but provided with multiple");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,7 @@ namespace CliFx.Tests;
|
||||
public class ParameterBindingSpecs : SpecsBase
|
||||
{
|
||||
public ParameterBindingSpecs(ITestOutputHelper testOutput)
|
||||
: base(testOutput)
|
||||
{
|
||||
}
|
||||
: base(testOutput) { }
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_bind_a_parameter_to_a_property_and_get_the_value_from_the_corresponding_argument()
|
||||
@@ -49,7 +47,7 @@ public class ParameterBindingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"one", "two"},
|
||||
new[] { "one", "two" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -57,10 +55,7 @@ public class ParameterBindingSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ConsistOfLines(
|
||||
"Foo = one",
|
||||
"Bar = two"
|
||||
);
|
||||
stdOut.Should().ConsistOfLines("Foo = one", "Bar = two");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -106,7 +101,7 @@ public class ParameterBindingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"one", "two", "three", "four", "five", "--boo", "xxx"},
|
||||
new[] { "one", "two", "three", "four", "five", "--boo", "xxx" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -114,13 +109,9 @@ public class ParameterBindingSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ConsistOfLines(
|
||||
"Foo = one",
|
||||
"Bar = two",
|
||||
"Baz = three",
|
||||
"Baz = four",
|
||||
"Baz = five"
|
||||
);
|
||||
stdOut
|
||||
.Should()
|
||||
.ConsistOfLines("Foo = one", "Bar = two", "Baz = three", "Baz = four", "Baz = five");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -151,7 +142,7 @@ public class ParameterBindingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"one"},
|
||||
new[] { "one" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -190,7 +181,7 @@ public class ParameterBindingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"one"},
|
||||
new[] { "one" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -235,7 +226,7 @@ public class ParameterBindingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"abc"},
|
||||
new[] { "abc" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -243,10 +234,7 @@ public class ParameterBindingSpecs : SpecsBase
|
||||
exitCode.Should().Be(0);
|
||||
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Should().ConsistOfLines(
|
||||
"Foo = abc",
|
||||
"Bar = xyz"
|
||||
);
|
||||
stdOut.Should().ConsistOfLines("Foo = abc", "Bar = xyz");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -277,7 +265,7 @@ public class ParameterBindingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"one", "two", "three"},
|
||||
new[] { "one", "two", "three" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -287,4 +275,4 @@ public class ParameterBindingSpecs : SpecsBase
|
||||
var stdErr = FakeConsole.ReadErrorString();
|
||||
stdErr.Should().Contain("Unexpected parameter(s)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,7 @@ namespace CliFx.Tests;
|
||||
public class RoutingSpecs : SpecsBase
|
||||
{
|
||||
public RoutingSpecs(ITestOutputHelper testOutput)
|
||||
: base(testOutput)
|
||||
{
|
||||
}
|
||||
: base(testOutput) { }
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_configure_a_command_to_be_executed_by_default_when_the_user_does_not_specify_a_command_name()
|
||||
@@ -118,7 +116,7 @@ public class RoutingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"cmd"},
|
||||
new[] { "cmd" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -175,7 +173,7 @@ public class RoutingSpecs : SpecsBase
|
||||
|
||||
// Act
|
||||
var exitCode = await application.RunAsync(
|
||||
new[] {"cmd", "child"},
|
||||
new[] { "cmd", "child" },
|
||||
new Dictionary<string, string>()
|
||||
);
|
||||
|
||||
@@ -185,4 +183,4 @@ public class RoutingSpecs : SpecsBase
|
||||
var stdOut = FakeConsole.ReadOutputString();
|
||||
stdOut.Trim().Should().Be("cmd child");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,12 +11,11 @@ public abstract class SpecsBase : IDisposable
|
||||
|
||||
public FakeInMemoryConsole FakeConsole { get; } = new();
|
||||
|
||||
protected SpecsBase(ITestOutputHelper testOutput) =>
|
||||
TestOutput = testOutput;
|
||||
protected SpecsBase(ITestOutputHelper testOutput) => TestOutput = testOutput;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
FakeConsole.DumpToTestOutput(TestOutput);
|
||||
FakeConsole.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,7 @@ namespace CliFx.Tests;
|
||||
public class TypeActivationSpecs : SpecsBase
|
||||
{
|
||||
public TypeActivationSpecs(ITestOutputHelper testOutput)
|
||||
: base(testOutput)
|
||||
{
|
||||
}
|
||||
: base(testOutput) { }
|
||||
|
||||
[Fact]
|
||||
public async Task I_can_configure_the_application_to_use_the_default_type_activator_to_initialize_types_through_parameterless_constructors()
|
||||
@@ -225,4 +223,4 @@ public class TypeActivationSpecs : SpecsBase
|
||||
var stdErr = FakeConsole.ReadErrorString();
|
||||
stdErr.Should().Contain("Failed to create an instance of type");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,7 @@ internal static class DynamicCommandBuilder
|
||||
};
|
||||
|
||||
// Get default CliFx namespaces
|
||||
var defaultCliFxNamespaces = typeof(ICommand)
|
||||
.Assembly
|
||||
var defaultCliFxNamespaces = typeof(ICommand).Assembly
|
||||
.GetTypes()
|
||||
.Where(t => t.IsPublic)
|
||||
.Select(t => t.Namespace)
|
||||
@@ -41,10 +40,10 @@ internal static class DynamicCommandBuilder
|
||||
|
||||
// Append default imports to the source code
|
||||
var sourceCodeWithUsings =
|
||||
string.Join(Environment.NewLine, defaultSystemNamespaces.Select(n => $"using {n};")) +
|
||||
string.Join(Environment.NewLine, defaultCliFxNamespaces.Select(n => $"using {n};")) +
|
||||
Environment.NewLine +
|
||||
sourceCode;
|
||||
string.Join(Environment.NewLine, defaultSystemNamespaces.Select(n => $"using {n};"))
|
||||
+ string.Join(Environment.NewLine, defaultCliFxNamespaces.Select(n => $"using {n};"))
|
||||
+ Environment.NewLine
|
||||
+ sourceCode;
|
||||
|
||||
// Parse the source code
|
||||
var ast = SyntaxFactory.ParseSyntaxTree(
|
||||
@@ -55,10 +54,14 @@ internal static class DynamicCommandBuilder
|
||||
// Compile the code to IL
|
||||
var compilation = CSharpCompilation.Create(
|
||||
"CliFxTests_DynamicAssembly_" + Guid.NewGuid(),
|
||||
new[] {ast},
|
||||
new[] { ast },
|
||||
Net70.References.All
|
||||
.Append(MetadataReference.CreateFromFile(typeof(ICommand).Assembly.Location))
|
||||
.Append(MetadataReference.CreateFromFile(typeof(DynamicCommandBuilder).Assembly.Location)),
|
||||
.Append(
|
||||
MetadataReference.CreateFromFile(
|
||||
typeof(DynamicCommandBuilder).Assembly.Location
|
||||
)
|
||||
),
|
||||
// DLL to avoid having to define the Main() method
|
||||
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)
|
||||
);
|
||||
@@ -82,8 +85,7 @@ internal static class DynamicCommandBuilder
|
||||
using var buffer = new MemoryStream();
|
||||
var emit = compilation.Emit(buffer);
|
||||
|
||||
var emitErrors = emit
|
||||
.Diagnostics
|
||||
var emitErrors = emit.Diagnostics
|
||||
.Where(d => d.Severity >= DiagnosticSeverity.Error)
|
||||
.ToArray();
|
||||
|
||||
@@ -128,4 +130,4 @@ internal static class DynamicCommandBuilder
|
||||
|
||||
return commandTypes.Single();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,22 +8,22 @@ namespace CliFx.Tests.Utils.Extensions;
|
||||
|
||||
internal static class AssertionExtensions
|
||||
{
|
||||
public static void ConsistOfLines(
|
||||
this StringAssertions assertions,
|
||||
IEnumerable<string> lines)
|
||||
public static void ConsistOfLines(this StringAssertions assertions, IEnumerable<string> lines)
|
||||
{
|
||||
var actualLines = assertions.Subject.Split(new[] {'\n', '\r'}, StringSplitOptions.RemoveEmptyEntries);
|
||||
var actualLines = assertions.Subject.Split(
|
||||
new[] { '\n', '\r' },
|
||||
StringSplitOptions.RemoveEmptyEntries
|
||||
);
|
||||
actualLines.Should().Equal(lines);
|
||||
}
|
||||
|
||||
public static void ConsistOfLines(
|
||||
this StringAssertions assertions,
|
||||
params string[] lines) =>
|
||||
assertions.ConsistOfLines((IEnumerable<string>) lines);
|
||||
public static void ConsistOfLines(this StringAssertions assertions, params string[] lines) =>
|
||||
assertions.ConsistOfLines((IEnumerable<string>)lines);
|
||||
|
||||
public static AndConstraint<StringAssertions> ContainAllInOrder(
|
||||
this StringAssertions assertions,
|
||||
IEnumerable<string> values)
|
||||
IEnumerable<string> values
|
||||
)
|
||||
{
|
||||
var lastIndex = 0;
|
||||
|
||||
@@ -46,6 +46,6 @@ internal static class AssertionExtensions
|
||||
|
||||
public static AndConstraint<StringAssertions> ContainAllInOrder(
|
||||
this StringAssertions assertions,
|
||||
params string[] values) =>
|
||||
assertions.ContainAllInOrder((IEnumerable<string>) values);
|
||||
}
|
||||
params string[] values
|
||||
) => assertions.ContainAllInOrder((IEnumerable<string>)values);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,10 @@ namespace CliFx.Tests.Utils.Extensions;
|
||||
|
||||
internal static class ConsoleExtensions
|
||||
{
|
||||
public static void DumpToTestOutput(this FakeInMemoryConsole console, ITestOutputHelper testOutputHelper)
|
||||
public static void DumpToTestOutput(
|
||||
this FakeInMemoryConsole console,
|
||||
ITestOutputHelper testOutputHelper
|
||||
)
|
||||
{
|
||||
testOutputHelper.WriteLine("[*] Captured standard output:");
|
||||
testOutputHelper.WriteLine(console.ReadOutputString());
|
||||
@@ -13,4 +16,4 @@ internal static class ConsoleExtensions
|
||||
testOutputHelper.WriteLine("[*] Captured standard error:");
|
||||
testOutputHelper.WriteLine(console.ReadErrorString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,4 +8,4 @@ namespace CliFx.Tests.Utils;
|
||||
internal class NoOpCommand : ICommand
|
||||
{
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user