[ 
https://issues.apache.org/jira/browse/CLI-137?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12601980#action_12601980
 ] 

Russel Winder commented on CLI-137:
-----------------------------------

I have been trying to create a TestNG test program to try and determine what I 
think should work and what shouldn't.  Currently the single biggest problem I 
have with 1.2-SNAPSHOT (r662829) is exemplified by the test:
{code}
@Test public void multipleOptionsWithResidue_Posix ( ) throws ParseException {
    final Options options = new Options ( ) ;
    options.addOption (
                       OptionBuilder.withArgName ( "property=value" )
                       .hasArg ( )
                       .create ( "D" ) ) ;
    final CommandLine line = posixParser.parse ( options , new String[] { "-D" 
, "x=2" , "-Dz=1" , "blah" , "Flobadob" } ) ;
    final String[] strings = line.getOptionValues ( 'D' ) ;
    assertEquals ( strings.length , 2 ) ;
    assertEquals ( strings[0] , "x=2" ) ;
    assertEquals ( strings[1] , "z=1" ) ;
   final List<String> excess = line.getArgList ( ) ;
    assertEquals ( excess.size ( ) , 2 ) ;
    assertEquals ( excess.get ( 0 ) , "blah" ) ;
    assertEquals ( excess.get ( 1 ) , "Flobadob" ) ;
  }
}
{code}
This test fails:
{code}
java.lang.AssertionError: expected:<2> but was:<4>
        at org.testng.Assert.fail(Assert.java:84)
        at org.testng.Assert.failNotEquals(Assert.java:438)
        at org.testng.Assert.assertEquals(Assert.java:108)
        at org.testng.Assert.assertEquals(Assert.java:323)
        at org.testng.Assert.assertEquals(Assert.java:333)
        at 
CommonsCLI_1_1_Test.multipleOptionsWithResidue_Gnu(CommonsCLI_1_1_Test.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:580)
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:478)
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:617)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:885)
        at 
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:110)
        at org.testng.TestRunner.runWorkers(TestRunner.java:712)
        at org.testng.TestRunner.privateRun(TestRunner.java:582)
        at org.testng.TestRunner.run(TestRunner.java:477)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:324)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:319)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:292)
        at org.testng.SuiteRunner.run(SuiteRunner.java:198)
        at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:821)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:788)
        at org.testng.TestNG.run(TestNG.java:708)
        at org.testng.TestNG.privateMain(TestNG.java:858)
        at org.testng.TestNG.main(TestNG.java:831)
{code}
The -D option processing is collecting all parameters not just the ones with a 
-D.  The same result obtains with the GnuParser.

> Change of behaviour 1.0 -> 1.1
> ------------------------------
>
>                 Key: CLI-137
>                 URL: https://issues.apache.org/jira/browse/CLI-137
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: CLI-1.x
>    Affects Versions: 1.1
>         Environment: Ubuntu 7.04 Feisty Fawn (JDK 1.6.0) + Commons CLI 1.0 
> and 1.1
>            Reporter: Russel Winder
>            Priority: Blocker
>             Fix For: 1.2
>
>         Attachments: repeated-options.patch
>
>
> The code:
> {code}
> import org.apache.commons.cli.*;
> public class Trial {
>   private void execute (String[] commandLine) throws ParseException {
>     Options options = new Options();
>     options.addOption ( 
> OptionBuilder.withLongOpt("flob").hasArg().create('F') );
>     CommandLine line = new GnuParser().parse(options, commandLine);
>     String[] results = line.getOptionValues('F');
>     if ( results != null ) { 
>       for ( String s : results ) { 
>         System.out.println( "-F " + s );
>       } 
>     }
>     results = line.getOptionValues("flob") ;
>     if ( results != null ) { 
>       for ( String s : results ) { 
>         System.out.println( "--blah " + s ); 
>       }
>     }
>     String[] theRest = line.getArgs() ;
>     for ( String s : theRest ) { 
>       System.out.print( s + " " ); 
>     }
>     System.out.println();
>   }
>   public static void main (String[] args) throws ParseException {
>     Trial trial = new Trial() ;
>     trial.execute ( new String[] { "-F1" , "-F3" , "-Fbla" , "-F 76" , 
> "--flob" , "54" } ) ;
>   }
> }
> {code}
> when compiled and executed under 1.0 produces:
> trial:
>      [java] -F 1
>      [java] -F 3
>      [java] -F bla
>      [java] -F  76
>      [java] -F 54
>      [java] 
> However, when compiled and executed under 1.1 produces:
> trial:
>      [java] -F 1
>      [java] --blah 1
>      [java] 3 bla  76 54 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to