File tree Expand file tree Collapse file tree 2 files changed +29
-6
lines changed
tests/CommandLine.Tests/Unit Expand file tree Collapse file tree 2 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -36,18 +36,29 @@ public ParserSettings()
3636 autoHelp = true ;
3737 autoVersion = true ;
3838 parsingCulture = CultureInfo . InvariantCulture ;
39+ maximumDisplayWidth = GetWindowWidth ( ) ;
40+ }
41+
42+ private int GetWindowWidth ( )
43+ {
44+
45+ #if ! NET40
46+ if ( Console . IsOutputRedirected ) return DefaultMaximumLength ;
47+ #endif
48+ var width = 1 ;
3949 try
4050 {
41- maximumDisplayWidth = Console . WindowWidth ;
42- if ( maximumDisplayWidth < 1 )
51+ width = Console . WindowWidth ;
52+ if ( width < 1 )
4353 {
44- maximumDisplayWidth = DefaultMaximumLength ;
54+ width = DefaultMaximumLength ;
4555 }
46- }
47- catch ( IOException )
56+ }
57+ catch ( Exception e ) when ( e is IOException || e is PlatformNotSupportedException || e is ArgumentOutOfRangeException )
4858 {
49- maximumDisplayWidth = DefaultMaximumLength ;
59+ width = DefaultMaximumLength ;
5060 }
61+ return width ;
5162 }
5263
5364 /// <summary>
Original file line number Diff line number Diff line change @@ -892,5 +892,17 @@ public void Parse_default_verb_with_empty_name()
892892 Assert . True ( args . TestValue ) ;
893893 } ) ;
894894 }
895+ //Fix Issue #409 for WPF
896+ [ Fact ]
897+ public void When_HelpWriter_is_null_it_should_not_fire_exception ( )
898+ {
899+ // Arrange
900+
901+ //Act
902+ var sut = new Parser ( config => config . HelpWriter = null ) ;
903+ sut . ParseArguments < Simple_Options > ( new [ ] { "--dummy" } ) ;
904+ //Assert
905+ sut . Settings . MaximumDisplayWidth . Should ( ) . Be ( 80 ) ;
906+ }
895907 }
896908}
You can’t perform that action at this time.
0 commit comments