@@ -19,7 +19,7 @@ namespace CommandLine.Tests.Unit.Core
19
19
{
20
20
public class InstanceBuilderTests
21
21
{
22
- private static ParserResult < T > InvokeBuild < T > ( string [ ] arguments )
22
+ private static ParserResult < T > InvokeBuild < T > ( string [ ] arguments , bool autoHelp = true , bool autoVersion = true )
23
23
where T : new ( )
24
24
{
25
25
return InstanceBuilder . Build (
@@ -29,6 +29,8 @@ private static ParserResult<T> InvokeBuild<T>(string[] arguments)
29
29
StringComparer . Ordinal ,
30
30
false ,
31
31
CultureInfo . InvariantCulture ,
32
+ autoHelp ,
33
+ autoVersion ,
32
34
Enumerable . Empty < ErrorType > ( ) ) ;
33
35
}
34
36
@@ -42,6 +44,8 @@ private static ParserResult<T> InvokeBuildEnumValuesCaseIgnore<T>(string[] argum
42
44
StringComparer . Ordinal ,
43
45
true ,
44
46
CultureInfo . InvariantCulture ,
47
+ true ,
48
+ true ,
45
49
Enumerable . Empty < ErrorType > ( ) ) ;
46
50
}
47
51
@@ -54,6 +58,8 @@ private static ParserResult<T> InvokeBuildImmutable<T>(string[] arguments)
54
58
StringComparer . Ordinal ,
55
59
false ,
56
60
CultureInfo . InvariantCulture ,
61
+ true ,
62
+ true ,
57
63
Enumerable . Empty < ErrorType > ( ) ) ;
58
64
}
59
65
@@ -451,6 +457,8 @@ public void Double_dash_force_subsequent_arguments_as_values()
451
457
StringComparer . Ordinal ,
452
458
false ,
453
459
CultureInfo . InvariantCulture ,
460
+ true ,
461
+ true ,
454
462
Enumerable . Empty < ErrorType > ( ) ) ;
455
463
456
464
// Verify outcome
@@ -1024,6 +1032,76 @@ public void Parse_string_with_dashes_except_in_beginning(string[] arguments, str
1024
1032
// Teardown
1025
1033
}
1026
1034
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
+
1027
1105
[ Theory ]
1028
1106
[ MemberData ( "GuidData" ) ]
1029
1107
public void Parse_Guid ( string [ ] arguments , Options_With_Guid expected )
0 commit comments