Skip to content

Commit 07eaee2

Browse files
authored
Fix issue #418, modify version screen to print a new line at the end (#443)
* Fix issue #418, modify version screen to print a new line at the end * Move unit test to a separate file
1 parent dd25e30 commit 07eaee2

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

src/CommandLine/Text/HelpText.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ public static HelpText AutoBuild<T>(ParserResult<T> parserResult, int maxDisplay
392392
var errors = ((NotParsed<T>)parserResult).Errors;
393393

394394
if (errors.Any(e => e.Tag == ErrorType.VersionRequestedError))
395-
return new HelpText(HeadingInfo.Default){MaximumDisplayWidth = maxDisplayWidth }.AddPreOptionsLine(Environment.NewLine);
395+
return new HelpText($"{HeadingInfo.Default}{Environment.NewLine}"){MaximumDisplayWidth = maxDisplayWidth }.AddPreOptionsLine(Environment.NewLine);
396396

397397
if (!errors.Any(e => e.Tag == ErrorType.HelpVerbRequestedError))
398398
return AutoBuild(parserResult, current => DefaultParsingErrorsHandler(parserResult, current), e => e, maxDisplayWidth: maxDisplayWidth);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using CommandLine.Text;
2+
using System;
3+
using System.IO;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using CommandLine.Tests.Fakes;
8+
using Xunit;
9+
using FluentAssertions;
10+
11+
namespace CommandLine.Tests.Unit
12+
{
13+
//issue#418, --version does not print a new line at the end cause trouble in Linux
14+
public class Issue418Tests
15+
{
16+
17+
[Fact]
18+
public void Explicit_version_request_generates_version_info_screen_with_eol()
19+
{
20+
// Fixture setup
21+
var help = new StringWriter();
22+
var sut = new Parser(config => config.HelpWriter = help);
23+
24+
// Exercize system
25+
sut.ParseArguments<Simple_Options>(new[] { "--version" });
26+
var result = help.ToString();
27+
// Verify outcome
28+
var lines = result.ToNotEmptyLines();
29+
result.Length.Should().BeGreaterThan(0);
30+
result.Should().EndWith(Environment.NewLine);
31+
result.ToNotEmptyLines().Length.Should().Be(1);
32+
33+
// Teardown
34+
}
35+
}
36+
}

tests/CommandLine.Tests/Unit/ParserTests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,7 @@ public void Parse_options_with_shuffled_index_values()
802802
Assert.Equal("one", args.Arg1);
803803
Assert.Equal("two", args.Arg2);
804804
});
805+
805806
}
806807

807808

@@ -823,5 +824,6 @@ public void Blank_lines_are_inserted_between_verbs()
823824
lines[10].Should().BeEquivalentTo("version Display version information.");
824825
// Teardown
825826
}
827+
826828
}
827829
}

0 commit comments

Comments
 (0)