File tree 2 files changed +29
-6
lines changed
tests/CommandLine.Tests/Unit
2 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -36,18 +36,29 @@ public ParserSettings()
36
36
autoHelp = true ;
37
37
autoVersion = true ;
38
38
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 ;
39
49
try
40
50
{
41
- maximumDisplayWidth = Console . WindowWidth ;
42
- if ( maximumDisplayWidth < 1 )
51
+ width = Console . WindowWidth ;
52
+ if ( width < 1 )
43
53
{
44
- maximumDisplayWidth = DefaultMaximumLength ;
54
+ width = DefaultMaximumLength ;
45
55
}
46
- }
47
- catch ( IOException )
56
+ }
57
+ catch ( Exception e ) when ( e is IOException || e is PlatformNotSupportedException || e is ArgumentOutOfRangeException )
48
58
{
49
- maximumDisplayWidth = DefaultMaximumLength ;
59
+ width = DefaultMaximumLength ;
50
60
}
61
+ return width ;
51
62
}
52
63
53
64
/// <summary>
Original file line number Diff line number Diff line change @@ -892,5 +892,17 @@ public void Parse_default_verb_with_empty_name()
892
892
Assert . True ( args . TestValue ) ;
893
893
} ) ;
894
894
}
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
+ }
895
907
}
896
908
}
You can’t perform that action at this time.
0 commit comments