Skip to content

Commit 469e717

Browse files
author
John Keyes
committed
bug no 11458: added test
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk@129802 13f79535-47bb-0310-9956-ffa450edef68
1 parent 4fbf597 commit 469e717

1 file changed

Lines changed: 53 additions & 1 deletion

File tree

src/test/org/apache/commons/cli/BugsTest.java

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* version 1.1, a copy of which has been included with this distribution in
66
* the LICENSE file.
77
*
8-
* $Id: BugsTest.java,v 1.2 2002/08/15 22:05:19 jkeyes Exp $
8+
* $Id: BugsTest.java,v 1.3 2002/08/18 15:52:23 jkeyes Exp $
99
*/
1010

1111
package org.apache.commons.cli;
@@ -37,6 +37,58 @@ public void tearDown()
3737
{
3838
}
3939

40+
public void test11458()
41+
{
42+
Options options = new Options();
43+
options.addOption( OptionBuilder.withValueSeparator( '=' )
44+
.hasArgs()
45+
.create( 'D' ) );
46+
options.addOption( OptionBuilder.withValueSeparator( ':' )
47+
.hasArgs()
48+
.create( 'p' ) );
49+
String[] args = new String[] { "-DJAVA_HOME=/opt/java" ,
50+
"-pfile1:file2:file3" };
51+
52+
CommandLineParser parser = CommandLineParserFactory.newParser();
53+
54+
try {
55+
CommandLine cmd = parser.parse( options, args );
56+
57+
String[] values = cmd.getOptionValues( 'D' );
58+
59+
assertEquals( values[0], "JAVA_HOME" );
60+
assertEquals( values[1], "/opt/java" );
61+
62+
values = cmd.getOptionValues( 'p' );
63+
64+
assertEquals( values[0], "file1" );
65+
assertEquals( values[1], "file2" );
66+
assertEquals( values[2], "file3" );
67+
68+
java.util.Iterator iter = cmd.iterator();
69+
while( iter.hasNext() ) {
70+
Option opt = (Option)iter.next();
71+
switch( opt.getId() ) {
72+
case 'D':
73+
assertEquals( opt.getValue( 0 ), "JAVA_HOME" );
74+
assertEquals( opt.getValue( 1 ), "/opt/java" );
75+
break;
76+
case 'p':
77+
assertEquals( opt.getValue( 0 ), "file1" );
78+
assertEquals( opt.getValue( 1 ), "file2" );
79+
assertEquals( opt.getValue( 2 ), "file3" );
80+
break;
81+
default:
82+
fail( "-D option not found" );
83+
}
84+
}
85+
}
86+
catch( ParseException exp ) {
87+
fail( "Unexpected Exception:\nMessage:" + exp.getMessage()
88+
+ "Type: " + exp.getClass().getName() );
89+
}
90+
}
91+
4092
public void test11680()
4193
{
4294
Options options = new Options();

0 commit comments

Comments
 (0)