2626import org .springframework .core .convert .ConversionService ;
2727import org .springframework .core .convert .support .DefaultConversionService ;
2828import org .springframework .shell .command .CommandParser .CommandParserResults ;
29+ import org .springframework .shell .command .CommandParser .MissingOptionException ;
2930import org .springframework .shell .command .CommandParser .NotEnoughArgumentsOptionException ;
3031import org .springframework .shell .command .CommandParser .TooManyArgumentsOptionException ;
32+ import org .springframework .shell .command .CommandParser .UnrecognisedOptionException ;
3133
3234import static org .assertj .core .api .Assertions .assertThat ;
3335
@@ -496,6 +498,11 @@ public void testNotDefinedLongOptionWithoutOptions() {
496498 CommandParserResults results = parser .parse (options , args );
497499 assertThat (results .results ()).hasSize (0 );
498500 assertThat (results .errors ()).hasSize (1 );
501+ assertThat (results .errors ()).satisfiesExactly (
502+ e -> {
503+ assertThat (e ).isInstanceOf (UnrecognisedOptionException .class );
504+ }
505+ );
499506 assertThat (results .positional ()).hasSize (1 );
500507 }
501508
@@ -508,6 +515,11 @@ public void testNotDefinedLongOptionWithOptionalOption() {
508515 CommandParserResults results = parser .parse (options , args );
509516 assertThat (results .results ()).hasSize (1 );
510517 assertThat (results .errors ()).hasSize (1 );
518+ assertThat (results .errors ()).satisfiesExactly (
519+ e -> {
520+ assertThat (e ).isInstanceOf (UnrecognisedOptionException .class );
521+ }
522+ );
511523 assertThat (results .positional ()).hasSize (1 );
512524 }
513525
@@ -520,9 +532,29 @@ public void testNotDefinedLongOptionWithRequiredOption() {
520532 CommandParserResults results = parser .parse (options , args );
521533 assertThat (results .results ()).hasSize (0 );
522534 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+ );
523543 assertThat (results .positional ()).hasSize (1 );
524544 }
525545
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+
526558 @ Test
527559 public void testPositionDoesNotAffectRequiredErrorWithOtherErrors () {
528560 // gh-601
0 commit comments