Skip to content

Commit 7e7e4d8

Browse files
committed
Unit test created by Andrew Shirley (see CLI-12) added to show that the issue does not crop up in the CLI 2 API.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk@421150 13f79535-47bb-0310-9956-ffa450edef68
1 parent 38185db commit 7e7e4d8

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Copyright 2004 The Apache Software Foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.apache.commons.cli2.bug;
17+
18+
import junit.framework.TestCase;
19+
20+
import org.apache.commons.cli2.Argument;
21+
import org.apache.commons.cli2.CommandLine;
22+
import org.apache.commons.cli2.Group;
23+
import org.apache.commons.cli2.Option;
24+
import org.apache.commons.cli2.builder.ArgumentBuilder;
25+
import org.apache.commons.cli2.builder.GroupBuilder;
26+
import org.apache.commons.cli2.commandline.Parser;
27+
import org.apache.commons.cli2.option.PropertyOption;
28+
29+
/**
30+
* http://issues.apache.org/jira/browse/CLI-12
31+
*/
32+
public class BugCLI12Test extends TestCase {
33+
34+
public void testBug() {
35+
Argument arg = new ArgumentBuilder().withName("file").create();
36+
37+
Option option = new PropertyOption();
38+
39+
Group group = new GroupBuilder().withOption(option).withOption(arg).create();
40+
41+
Parser p = new Parser();
42+
p.setGroup(group);
43+
44+
CommandLine cl = p.parseAndHelp( new String[] { "-Dmyprop1=myval1", "-Dmyprop2=myval2", "myfile" } );
45+
if(cl == null) {
46+
assertTrue("Couldn't parse valid commandLine", false);
47+
}
48+
49+
assertEquals( "myval1", cl.getProperty("myprop1"));
50+
assertEquals( "myval2", cl.getProperty("myprop2"));
51+
52+
String extraArgs = (String) cl.getValue(arg);
53+
assertEquals( "myfile", extraArgs);
54+
}
55+
56+
}

0 commit comments

Comments
 (0)