From 9680af3685dfb90f256d919336a752f6a0f6d893 Mon Sep 17 00:00:00 2001 From: "Moh.Hassan" Date: Tue, 7 May 2019 03:39:33 +0200 Subject: [PATCH 1/2] Fix issue #418, modify version screen to print a new line at the end --- src/CommandLine/Text/HelpText.cs | 2 +- tests/CommandLine.Tests/Unit/ParserTests.cs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/CommandLine/Text/HelpText.cs b/src/CommandLine/Text/HelpText.cs index cd11a475..dbc84750 100644 --- a/src/CommandLine/Text/HelpText.cs +++ b/src/CommandLine/Text/HelpText.cs @@ -315,7 +315,7 @@ public static HelpText AutoBuild(ParserResult parserResult, int maxDisplay var errors = ((NotParsed)parserResult).Errors; if (errors.Any(e => e.Tag == ErrorType.VersionRequestedError)) - return new HelpText(HeadingInfo.Default){MaximumDisplayWidth = maxDisplayWidth }.AddPreOptionsLine(Environment.NewLine); + return new HelpText($"{HeadingInfo.Default}{Environment.NewLine}"){MaximumDisplayWidth = maxDisplayWidth }.AddPreOptionsLine(Environment.NewLine); if (!errors.Any(e => e.Tag == ErrorType.HelpVerbRequestedError)) return AutoBuild(parserResult, current => DefaultParsingErrorsHandler(parserResult, current), e => e, maxDisplayWidth: maxDisplayWidth); diff --git a/tests/CommandLine.Tests/Unit/ParserTests.cs b/tests/CommandLine.Tests/Unit/ParserTests.cs index c183c47d..cbe61aae 100644 --- a/tests/CommandLine.Tests/Unit/ParserTests.cs +++ b/tests/CommandLine.Tests/Unit/ParserTests.cs @@ -859,6 +859,25 @@ public void Parse_options_with_shuffled_index_values() Assert.Equal("one", args.Arg1); Assert.Equal("two", args.Arg2); }); + } + //issue#418, --version does not print a new line at the end cause trouble in Linux + [Fact] + public void Explicit_version_request_generates_version_info_screen_with_eol() + { + // Fixture setup + var help = new StringWriter(); + var sut = new Parser(config => config.HelpWriter = help); + + // Exercize system + sut.ParseArguments(new[] { "--version" }); + var result = help.ToString(); + // Verify outcome + var lines = result.ToNotEmptyLines(); + result.Length.Should().BeGreaterThan(0); + result.Should().EndWith(Environment.NewLine); + result.ToNotEmptyLines().Length.Should().Be(1); + + // Teardown } } } From 505a3cd28a1e1805cfeda384191bd58d810d76bd Mon Sep 17 00:00:00 2001 From: "Moh.Hassan" Date: Mon, 29 Jul 2019 18:08:56 +0200 Subject: [PATCH 2/2] Move unit test to a separate file --- tests/CommandLine.Tests/Unit/Issue418Tests.cs | 36 +++++++++++++++++++ tests/CommandLine.Tests/Unit/ParserTests.cs | 21 +---------- 2 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 tests/CommandLine.Tests/Unit/Issue418Tests.cs diff --git a/tests/CommandLine.Tests/Unit/Issue418Tests.cs b/tests/CommandLine.Tests/Unit/Issue418Tests.cs new file mode 100644 index 00000000..9c8678bd --- /dev/null +++ b/tests/CommandLine.Tests/Unit/Issue418Tests.cs @@ -0,0 +1,36 @@ +using CommandLine.Text; +using System; +using System.IO; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using CommandLine.Tests.Fakes; +using Xunit; +using FluentAssertions; + +namespace CommandLine.Tests.Unit +{ + //issue#418, --version does not print a new line at the end cause trouble in Linux + public class Issue418Tests + { + + [Fact] + public void Explicit_version_request_generates_version_info_screen_with_eol() + { + // Fixture setup + var help = new StringWriter(); + var sut = new Parser(config => config.HelpWriter = help); + + // Exercize system + sut.ParseArguments(new[] { "--version" }); + var result = help.ToString(); + // Verify outcome + var lines = result.ToNotEmptyLines(); + result.Length.Should().BeGreaterThan(0); + result.Should().EndWith(Environment.NewLine); + result.ToNotEmptyLines().Length.Should().Be(1); + + // Teardown + } + } +} diff --git a/tests/CommandLine.Tests/Unit/ParserTests.cs b/tests/CommandLine.Tests/Unit/ParserTests.cs index cbe61aae..75469867 100644 --- a/tests/CommandLine.Tests/Unit/ParserTests.cs +++ b/tests/CommandLine.Tests/Unit/ParserTests.cs @@ -859,25 +859,6 @@ public void Parse_options_with_shuffled_index_values() Assert.Equal("one", args.Arg1); Assert.Equal("two", args.Arg2); }); - } - //issue#418, --version does not print a new line at the end cause trouble in Linux - [Fact] - public void Explicit_version_request_generates_version_info_screen_with_eol() - { - // Fixture setup - var help = new StringWriter(); - var sut = new Parser(config => config.HelpWriter = help); - - // Exercize system - sut.ParseArguments(new[] { "--version" }); - var result = help.ToString(); - // Verify outcome - var lines = result.ToNotEmptyLines(); - result.Length.Should().BeGreaterThan(0); - result.Should().EndWith(Environment.NewLine); - result.ToNotEmptyLines().Length.Should().Be(1); - - // Teardown - } + } } }