@@ -355,5 +355,79 @@ public void Dash_h_consumed_by_valid_args_with_invalid_args_produces_no_VersionR
355
355
result . As < NotParsed < Simple_Options > > ( ) . Errors . Should ( ) . HaveCountGreaterOrEqualTo ( 1 ) ;
356
356
result . As < NotParsed < Simple_Options > > ( ) . Errors . Should ( ) . NotBeOfType < VersionRequestedError > ( ) ;
357
357
}
358
+
359
+ [ Fact ]
360
+ public void Explicit_version_request_generates_version_requested_error ( )
361
+ {
362
+ // Fixture setup
363
+ var expectedError = new VersionRequestedError ( ) ;
364
+ var sut = new Parser ( ) ;
365
+
366
+ // Exercize system
367
+ var result = sut . ParseArguments < Simple_Options > ( new [ ] { "--version" } ) ;
368
+
369
+ // Verify outcome
370
+ ( ( NotParsed < Simple_Options > ) result ) . Errors . Should ( ) . HaveCount ( x => x == 1 ) ;
371
+ ( ( NotParsed < Simple_Options > ) result ) . Errors . Should ( ) . ContainSingle ( e => e . Equals ( expectedError ) ) ;
372
+ // Teardown
373
+ }
374
+
375
+ [ Fact ]
376
+ public void Explicit_version_request_with_AutoVersion_off_generates_unknown_option_error ( )
377
+ {
378
+ // Fixture setup
379
+ var expectedError = new UnknownOptionError ( "version" ) ;
380
+ var sut = new Parser ( config => { config . AutoVersion = false ; } ) ;
381
+
382
+ // Exercise system
383
+ var result = sut . ParseArguments < Simple_Options > ( new [ ] { "--version" } ) ;
384
+
385
+ // Verify outcome
386
+ ( ( NotParsed < Simple_Options > ) result ) . Errors . Should ( ) . HaveCount ( x => x == 1 ) ;
387
+ ( ( NotParsed < Simple_Options > ) result ) . Errors . Single ( ) . Tag . Should ( ) . Be ( expectedError . Tag ) ;
388
+ ( ( NotParsed < Simple_Options > ) result ) . Errors . First ( ) . As < UnknownOptionError > ( ) . Token . Should ( ) . BeEquivalentTo ( expectedError . Token ) ;
389
+
390
+ // Teardown
391
+ }
392
+
393
+ [ Fact ]
394
+ public void Explicit_version_request_with_AutoVersion_off_displays_unknown_option_error ( )
395
+ {
396
+ // Fixture setup
397
+ var help = new StringWriter ( ) ;
398
+ var sut = new Parser ( config => { config . AutoVersion = false ; config . HelpWriter = help ; } ) ;
399
+
400
+ // Exercise system
401
+ sut . ParseArguments < Simple_Options > ( new [ ] { "--version" } ) ;
402
+ var result = help . ToString ( ) ;
403
+
404
+ // Verify outcome
405
+
406
+ // Verify outcome
407
+ result . Length . Should ( ) . BeGreaterThan ( 0 ) ;
408
+ var lines = result . ToNotEmptyLines ( ) . TrimStringArray ( ) ;
409
+ lines [ 0 ] . Should ( ) . Be ( CommandLine . Text . HeadingInfo . Default . ToString ( ) ) ;
410
+ lines [ 1 ] . Should ( ) . Be ( CommandLine . Text . CopyrightInfo . Default . ToString ( ) ) ;
411
+ lines [ 2 ] . Should ( ) . BeEquivalentTo ( "ERROR(S):" ) ;
412
+ lines [ 3 ] . Should ( ) . BeEquivalentTo ( "Option 'version' is unknown." ) ;
413
+
414
+ // Teardown
415
+ }
416
+
417
+ [ Fact ]
418
+ public void Explicit_version_request_with_AutoVersion_off_and_IgnoreUnknownArguments_on_does_not_generate_version_screen ( )
419
+ {
420
+ // Fixture setup
421
+ var help = new StringWriter ( ) ;
422
+ var sut = new Parser ( config => { config . HelpWriter = help ; config . AutoVersion = false ; config . IgnoreUnknownArguments = true ; } ) ;
423
+
424
+ // Exercize system
425
+ sut . ParseArguments < Simple_Options > ( new [ ] { "--version" } ) ;
426
+ var result = help . ToString ( ) ;
427
+
428
+ // Verify outcome
429
+ result . Should ( ) . BeEquivalentTo ( "" ) ;
430
+ // Teardown
431
+ }
358
432
}
359
433
}
0 commit comments