diff --git a/CliFx.Tests/CliApplicationTests.cs b/CliFx.Tests/CliApplicationTests.cs index e61e17e..74c8ca3 100644 --- a/CliFx.Tests/CliApplicationTests.cs +++ b/CliFx.Tests/CliApplicationTests.cs @@ -27,7 +27,7 @@ namespace CliFx.Tests var exitCodeValue = await application.RunAsync(); // Assert - Assert.That(exitCodeValue, Is.EqualTo(expectedExitCode.Value)); + Assert.That(exitCodeValue, Is.EqualTo(expectedExitCode.Value), "Exit code"); } } } \ No newline at end of file diff --git a/CliFx.Tests/CommandOptionConverterTests.cs b/CliFx.Tests/CommandOptionConverterTests.cs index 0d90c58..59b43ab 100644 --- a/CliFx.Tests/CommandOptionConverterTests.cs +++ b/CliFx.Tests/CommandOptionConverterTests.cs @@ -11,56 +11,39 @@ namespace CliFx.Tests { private static IEnumerable GetData_ConvertOption() { - yield return new TestCaseData("value", typeof(string), "value") - .SetName("To string"); + yield return new TestCaseData("value", typeof(string), "value"); - yield return new TestCaseData("value", typeof(object), "value") - .SetName("To object"); + yield return new TestCaseData("value", typeof(object), "value"); - yield return new TestCaseData("true", typeof(bool), true) - .SetName("To bool (true)"); + yield return new TestCaseData("true", typeof(bool), true); - yield return new TestCaseData("false", typeof(bool), false) - .SetName("To bool (false)"); + yield return new TestCaseData("false", typeof(bool), false); - yield return new TestCaseData(null, typeof(bool), true) - .SetName("To bool (switch)"); + yield return new TestCaseData(null, typeof(bool), true); - yield return new TestCaseData("123", typeof(int), 123) - .SetName("To int"); + yield return new TestCaseData("123", typeof(int), 123); - yield return new TestCaseData("123.45", typeof(double), 123.45) - .SetName("To double"); + yield return new TestCaseData("123.45", typeof(double), 123.45); - yield return new TestCaseData("28 Apr 1995", typeof(DateTime), new DateTime(1995, 04, 28)) - .SetName("To DateTime"); + yield return new TestCaseData("28 Apr 1995", typeof(DateTime), new DateTime(1995, 04, 28)); - yield return new TestCaseData("28 Apr 1995", typeof(DateTimeOffset), new DateTimeOffset(new DateTime(1995, 04, 28))) - .SetName("To DateTimeOffset"); + yield return new TestCaseData("28 Apr 1995", typeof(DateTimeOffset), new DateTimeOffset(new DateTime(1995, 04, 28))); - yield return new TestCaseData("00:14:59", typeof(TimeSpan), new TimeSpan(00, 14, 59)) - .SetName("To TimeSpan"); + yield return new TestCaseData("00:14:59", typeof(TimeSpan), new TimeSpan(00, 14, 59)); - yield return new TestCaseData("value2", typeof(TestEnum), TestEnum.Value2) - .SetName("To enum"); + yield return new TestCaseData("value2", typeof(TestEnum), TestEnum.Value2); - yield return new TestCaseData("666", typeof(int?), 666) - .SetName("To int? (with value)"); + yield return new TestCaseData("666", typeof(int?), 666); - yield return new TestCaseData(null, typeof(int?), null) - .SetName("To int? (no value)"); + yield return new TestCaseData(null, typeof(int?), null); - yield return new TestCaseData("value3", typeof(TestEnum?), TestEnum.Value3) - .SetName("To enum? (with value)"); + yield return new TestCaseData("value3", typeof(TestEnum?), TestEnum.Value3); - yield return new TestCaseData(null, typeof(TestEnum?), null) - .SetName("To enum? (no value)"); + yield return new TestCaseData(null, typeof(TestEnum?), null); - yield return new TestCaseData("01:00:00", typeof(TimeSpan?), new TimeSpan(01, 00, 00)) - .SetName("To TimeSpan? (with value)"); + yield return new TestCaseData("01:00:00", typeof(TimeSpan?), new TimeSpan(01, 00, 00)); - yield return new TestCaseData(null, typeof(TimeSpan?), null) - .SetName("To TimeSpan? (no value)"); + yield return new TestCaseData(null, typeof(TimeSpan?), null); } [Test] diff --git a/CliFx.Tests/CommandOptionParserTests.cs b/CliFx.Tests/CommandOptionParserTests.cs index cc88b11..d986069 100644 --- a/CliFx.Tests/CommandOptionParserTests.cs +++ b/CliFx.Tests/CommandOptionParserTests.cs @@ -10,28 +10,24 @@ namespace CliFx.Tests { private static IEnumerable GetData_ParseOptions() { - yield return new TestCaseData( - new string[0], - CommandOptionSet.Empty - ).SetName("No arguments"); + yield return new TestCaseData(new string[0], CommandOptionSet.Empty); yield return new TestCaseData( - new[] {"--argument", "value"}, + new[] {"--option", "value"}, new CommandOptionSet(new Dictionary { - {"argument", "value"} + {"option", "value"} }) - ).SetName("Single argument"); + ); yield return new TestCaseData( - new[] {"--argument1", "value1", "--argument2", "value2", "--argument3", "value3"}, + new[] {"--option1", "value1", "--option2", "value2"}, new CommandOptionSet(new Dictionary { - {"argument1", "value1"}, - {"argument2", "value2"}, - {"argument3", "value3"} + {"option1", "value1"}, + {"option2", "value2"} }) - ).SetName("Multiple arguments"); + ); yield return new TestCaseData( new[] {"-a", "value"}, @@ -39,27 +35,25 @@ namespace CliFx.Tests { {"a", "value"} }) - ).SetName("Single short argument"); + ); yield return new TestCaseData( - new[] {"-a", "value1", "-b", "value2", "-c", "value3"}, + new[] {"-a", "value1", "-b", "value2"}, new CommandOptionSet(new Dictionary { {"a", "value1"}, - {"b", "value2"}, - {"c", "value3"} + {"b", "value2"} }) - ).SetName("Multiple short arguments"); + ); yield return new TestCaseData( - new[] {"--argument1", "value1", "-b", "value2", "--argument3", "value3"}, + new[] {"--option1", "value1", "-b", "value2"}, new CommandOptionSet(new Dictionary { - {"argument1", "value1"}, - {"b", "value2"}, - {"argument3", "value3"} + {"option1", "value1"}, + {"b", "value2"} }) - ).SetName("Multiple mixed arguments"); + ); yield return new TestCaseData( new[] {"--switch"}, @@ -67,17 +61,16 @@ namespace CliFx.Tests { {"switch", null} }) - ).SetName("Single switch"); + ); yield return new TestCaseData( - new[] {"--switch1", "--switch2", "--switch3"}, + new[] {"--switch1", "--switch2"}, new CommandOptionSet(new Dictionary { {"switch1", null}, - {"switch2", null}, - {"switch3", null} + {"switch2", null} }) - ).SetName("Multiple switches"); + ); yield return new TestCaseData( new[] {"-s"}, @@ -85,40 +78,38 @@ namespace CliFx.Tests { {"s", null} }) - ).SetName("Single short switch"); + ); yield return new TestCaseData( - new[] {"-a", "-b", "-c"}, + new[] {"-a", "-b"}, new CommandOptionSet(new Dictionary { {"a", null}, - {"b", null}, - {"c", null} + {"b", null} }) - ).SetName("Multiple short switches"); + ); yield return new TestCaseData( - new[] {"-abc"}, + new[] {"-ab"}, new CommandOptionSet(new Dictionary { {"a", null}, - {"b", null}, - {"c", null} + {"b", null} }) - ).SetName("Multiple stacked short switches"); + ); yield return new TestCaseData( new[] {"command"}, new CommandOptionSet("command") - ).SetName("No arguments (with command name)"); + ); yield return new TestCaseData( - new[] {"command", "--argument", "value"}, + new[] {"command", "--option", "value"}, new CommandOptionSet("command", new Dictionary { - {"argument", "value"} + {"option", "value"} }) - ).SetName("Single argument (with command name)"); + ); } [Test] @@ -132,8 +123,8 @@ namespace CliFx.Tests var optionSet = parser.ParseOptions(commandLineArguments); // Assert - Assert.That(optionSet.CommandName, Is.EqualTo(expectedCommandOptionSet.CommandName)); - Assert.That(optionSet.Options, Is.EqualTo(expectedCommandOptionSet.Options)); + Assert.That(optionSet.CommandName, Is.EqualTo(expectedCommandOptionSet.CommandName), "Command name"); + Assert.That(optionSet.Options, Is.EqualTo(expectedCommandOptionSet.Options), "Options"); } } } \ No newline at end of file diff --git a/CliFx.Tests/CommandResolverTests.cs b/CliFx.Tests/CommandResolverTests.cs index 8ec5f2c..d50c70f 100644 --- a/CliFx.Tests/CommandResolverTests.cs +++ b/CliFx.Tests/CommandResolverTests.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using CliFx.Exceptions; using CliFx.Models; using CliFx.Services; @@ -20,7 +19,7 @@ namespace CliFx.Tests {"int", "13"} }), new TestCommand {IntOption = 13} - ).SetName("Single option"); + ); yield return new TestCaseData( new CommandOptionSet(new Dictionary @@ -29,7 +28,7 @@ namespace CliFx.Tests {"str", "hello world" } }), new TestCommand { IntOption = 13, StringOption = "hello world"} - ).SetName("Multiple options"); + ); yield return new TestCaseData( new CommandOptionSet(new Dictionary @@ -37,7 +36,7 @@ namespace CliFx.Tests {"i", "13"} }), new TestCommand { IntOption = 13 } - ).SetName("Single short option"); + ); yield return new TestCaseData( new CommandOptionSet("command", new Dictionary @@ -45,7 +44,7 @@ namespace CliFx.Tests {"int", "13"} }), new TestCommand { IntOption = 13 } - ).SetName("Single option (with command name)"); + ); } [Test] @@ -78,16 +77,14 @@ namespace CliFx.Tests private static IEnumerable GetData_ResolveCommand_IsRequired() { - yield return new TestCaseData( - CommandOptionSet.Empty - ).SetName("No options"); + yield return new TestCaseData(CommandOptionSet.Empty); yield return new TestCaseData( new CommandOptionSet(new Dictionary { {"str", "hello world"} }) - ).SetName("Required option is not set"); + ); } [Test] diff --git a/CliFx.Tests/DummyTests.cs b/CliFx.Tests/DummyTests.cs index 0020d01..0a434bc 100644 --- a/CliFx.Tests/DummyTests.cs +++ b/CliFx.Tests/DummyTests.cs @@ -24,9 +24,9 @@ namespace CliFx.Tests var result = await Cli.Wrap(DummyFilePath).SetArguments(arguments).ExecuteAsync(); // Assert - Assert.That(result.ExitCode, Is.Zero); - Assert.That(result.StandardOutput.Trim(), Is.EqualTo(expectedOutput)); - Assert.That(result.StandardError.Trim(), Is.Empty); + Assert.That(result.ExitCode, Is.Zero, "Exit code"); + Assert.That(result.StandardOutput.Trim(), Is.EqualTo(expectedOutput), "Stdout"); + Assert.That(result.StandardError.Trim(), Is.Empty, "Stderr"); } } } \ No newline at end of file diff --git a/CliFx/Models/CommandOptionSet.cs b/CliFx/Models/CommandOptionSet.cs index fdd40ce..cab7b56 100644 --- a/CliFx/Models/CommandOptionSet.cs +++ b/CliFx/Models/CommandOptionSet.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using CliFx.Internal; namespace CliFx.Models @@ -25,9 +26,18 @@ namespace CliFx.Models { } - public override string ToString() => !CommandName.IsNullOrWhiteSpace() - ? $"{CommandName} / {Options.Count} option(s)" - : $"{Options.Count} option(s)"; + public override string ToString() + { + if (Options.Any()) + { + var optionsJoined = Options.Select(o => o.Key).JoinToString(", "); + return !CommandName.IsNullOrWhiteSpace() ? $"{CommandName} / [{optionsJoined}]" : $"[{optionsJoined}]"; + } + else + { + return !CommandName.IsNullOrWhiteSpace() ? $"{CommandName} / no options" : "no options"; + } + } } public partial class CommandOptionSet