26
26
import org .springframework .core .convert .ConversionService ;
27
27
import org .springframework .core .convert .support .DefaultConversionService ;
28
28
import org .springframework .shell .command .CommandParser .CommandParserResults ;
29
+ import org .springframework .shell .command .CommandParser .MissingOptionException ;
29
30
import org .springframework .shell .command .CommandParser .NotEnoughArgumentsOptionException ;
30
31
import org .springframework .shell .command .CommandParser .TooManyArgumentsOptionException ;
32
+ import org .springframework .shell .command .CommandParser .UnrecognisedOptionException ;
31
33
32
34
import static org .assertj .core .api .Assertions .assertThat ;
33
35
@@ -496,6 +498,11 @@ public void testNotDefinedLongOptionWithoutOptions() {
496
498
CommandParserResults results = parser .parse (options , args );
497
499
assertThat (results .results ()).hasSize (0 );
498
500
assertThat (results .errors ()).hasSize (1 );
501
+ assertThat (results .errors ()).satisfiesExactly (
502
+ e -> {
503
+ assertThat (e ).isInstanceOf (UnrecognisedOptionException .class );
504
+ }
505
+ );
499
506
assertThat (results .positional ()).hasSize (1 );
500
507
}
501
508
@@ -508,6 +515,11 @@ public void testNotDefinedLongOptionWithOptionalOption() {
508
515
CommandParserResults results = parser .parse (options , args );
509
516
assertThat (results .results ()).hasSize (1 );
510
517
assertThat (results .errors ()).hasSize (1 );
518
+ assertThat (results .errors ()).satisfiesExactly (
519
+ e -> {
520
+ assertThat (e ).isInstanceOf (UnrecognisedOptionException .class );
521
+ }
522
+ );
511
523
assertThat (results .positional ()).hasSize (1 );
512
524
}
513
525
@@ -520,9 +532,29 @@ public void testNotDefinedLongOptionWithRequiredOption() {
520
532
CommandParserResults results = parser .parse (options , args );
521
533
assertThat (results .results ()).hasSize (0 );
522
534
assertThat (results .errors ()).hasSize (2 );
535
+ assertThat (results .errors ()).satisfiesExactly (
536
+ e -> {
537
+ assertThat (e ).isInstanceOf (UnrecognisedOptionException .class );
538
+ },
539
+ e -> {
540
+ assertThat (e ).isInstanceOf (MissingOptionException .class );
541
+ }
542
+ );
523
543
assertThat (results .positional ()).hasSize (1 );
524
544
}
525
545
546
+ @ Test
547
+ public void testDashOptionValueDoNotError () {
548
+ // gh-651
549
+ CommandOption option1 = longOption ("arg1" );
550
+ List <CommandOption > options = Arrays .asList (option1 );
551
+ String [] args = new String []{"--arg1" , "-1" };
552
+ CommandParserResults results = parser .parse (options , args );
553
+ assertThat (results .results ()).hasSize (1 );
554
+ assertThat (results .errors ()).hasSize (0 );
555
+ assertThat (results .positional ()).hasSize (0 );
556
+ }
557
+
526
558
@ Test
527
559
public void testPositionDoesNotAffectRequiredErrorWithOtherErrors () {
528
560
// gh-601
0 commit comments