@@ -19,7 +19,7 @@ namespace CommandLine.Tests.Unit.Core
1919{
2020 public class InstanceBuilderTests
2121 {
22- private static ParserResult < T > InvokeBuild < T > ( string [ ] arguments )
22+ private static ParserResult < T > InvokeBuild < T > ( string [ ] arguments , bool autoHelp = true , bool autoVersion = true )
2323 where T : new ( )
2424 {
2525 return InstanceBuilder . Build (
@@ -29,6 +29,8 @@ private static ParserResult<T> InvokeBuild<T>(string[] arguments)
2929 StringComparer . Ordinal ,
3030 false ,
3131 CultureInfo . InvariantCulture ,
32+ autoHelp ,
33+ autoVersion ,
3234 Enumerable . Empty < ErrorType > ( ) ) ;
3335 }
3436
@@ -42,6 +44,8 @@ private static ParserResult<T> InvokeBuildEnumValuesCaseIgnore<T>(string[] argum
4244 StringComparer . Ordinal ,
4345 true ,
4446 CultureInfo . InvariantCulture ,
47+ true ,
48+ true ,
4549 Enumerable . Empty < ErrorType > ( ) ) ;
4650 }
4751
@@ -54,6 +58,8 @@ private static ParserResult<T> InvokeBuildImmutable<T>(string[] arguments)
5458 StringComparer . Ordinal ,
5559 false ,
5660 CultureInfo . InvariantCulture ,
61+ true ,
62+ true ,
5763 Enumerable . Empty < ErrorType > ( ) ) ;
5864 }
5965
@@ -451,6 +457,8 @@ public void Double_dash_force_subsequent_arguments_as_values()
451457 StringComparer . Ordinal ,
452458 false ,
453459 CultureInfo . InvariantCulture ,
460+ true ,
461+ true ,
454462 Enumerable . Empty < ErrorType > ( ) ) ;
455463
456464 // Verify outcome
@@ -1024,6 +1032,76 @@ public void Parse_string_with_dashes_except_in_beginning(string[] arguments, str
10241032 // Teardown
10251033 }
10261034
1035+ [ Theory ]
1036+ [ InlineData ( new [ ] { "--help" } , ErrorType . UnknownOptionError ) ]
1037+ public void Parse_without_auto_help_should_not_recognize_help_option ( string [ ] arguments , ErrorType errorType )
1038+ {
1039+ // Fixture setup in attributes
1040+
1041+ // Exercize system
1042+ var result = InvokeBuild < Simple_Options > ( arguments , autoHelp : false ) ;
1043+
1044+ // Verify outcome
1045+ result . Should ( ) . BeOfType < NotParsed < Simple_Options > > ( )
1046+ . Which . Errors . Should ( ) . ContainSingle ( )
1047+ . Which . Tag . Should ( ) . Be ( errorType ) ;
1048+
1049+ // Teardown
1050+ }
1051+
1052+ [ Theory ]
1053+ [ InlineData ( new [ ] { "--help" } , true ) ]
1054+ [ InlineData ( new [ ] { "-h" } , true ) ]
1055+ [ InlineData ( new [ ] { "-x" } , false ) ]
1056+ public void Parse_with_custom_help_option ( string [ ] arguments , bool isHelp )
1057+ {
1058+ // Fixture setup in attributes
1059+
1060+ // Exercize system
1061+ var result = InvokeBuild < Options_With_Custom_Help_Option > ( arguments , autoHelp : false ) ;
1062+
1063+ // Verify outcome
1064+ result . Should ( ) . BeOfType < Parsed < Options_With_Custom_Help_Option > > ( )
1065+ . Which . Value . Help . Should ( ) . Be ( isHelp ) ;
1066+
1067+ // Teardown
1068+ }
1069+
1070+ [ Theory ]
1071+ [ InlineData ( new [ ] { "--version" } , ErrorType . UnknownOptionError ) ]
1072+ public void Parse_without_auto_version_should_not_recognize_version_option ( string [ ] arguments , ErrorType errorType )
1073+ {
1074+ // Fixture setup in attributes
1075+
1076+ // Exercize system
1077+ var result = InvokeBuild < Simple_Options > ( arguments , autoVersion : false ) ;
1078+
1079+ // Verify outcome
1080+ result . Should ( ) . BeOfType < NotParsed < Simple_Options > > ( )
1081+ . Which . Errors . Should ( ) . ContainSingle ( )
1082+ . Which . Tag . Should ( ) . Be ( errorType ) ;
1083+
1084+ // Teardown
1085+ }
1086+
1087+ [ Theory ]
1088+ [ InlineData ( new [ ] { "--version" } , true ) ]
1089+ [ InlineData ( new [ ] { "-v" } , true ) ]
1090+ [ InlineData ( new [ ] { "-s" , "s" } , false ) ]
1091+ public void Parse_with_custom_version_option ( string [ ] arguments , bool isVersion )
1092+ {
1093+ // Fixture setup in attributes
1094+
1095+ // Exercize system
1096+ var result = InvokeBuild < Options_With_Custom_Version_Option > ( arguments , autoVersion : false ) ;
1097+
1098+ // Verify outcome
1099+ result . Should ( ) . BeOfType < Parsed < Options_With_Custom_Version_Option > > ( )
1100+ . Which . Value . MyVersion . Should ( ) . Be ( isVersion ) ;
1101+
1102+ // Teardown
1103+ }
1104+
10271105 [ Theory ]
10281106 [ MemberData ( "GuidData" ) ]
10291107 public void Parse_Guid ( string [ ] arguments , Options_With_Guid expected )
0 commit comments