diff --git a/src/CommandLine/Text/HelpText.cs b/src/CommandLine/Text/HelpText.cs index b287a6e8..b23bb804 100644 --- a/src/CommandLine/Text/HelpText.cs +++ b/src/CommandLine/Text/HelpText.cs @@ -392,7 +392,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/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 23cf0f32..07e9bed3 100644 --- a/tests/CommandLine.Tests/Unit/ParserTests.cs +++ b/tests/CommandLine.Tests/Unit/ParserTests.cs @@ -802,6 +802,7 @@ public void Parse_options_with_shuffled_index_values() Assert.Equal("one", args.Arg1); Assert.Equal("two", args.Arg2); }); + } @@ -823,5 +824,6 @@ public void Blank_lines_are_inserted_between_verbs() lines[10].Should().BeEquivalentTo("version Display version information."); // Teardown } + } }