You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ba...@apache.org on 2008/03/22 04:08:35 UTC

svn commit: r639943 [11/17] - in /commons/proper/cli/trunk/src: java/org/apache/commons/cli2/ java/org/apache/commons/cli2/builder/ java/org/apache/commons/cli2/commandline/ java/org/apache/commons/cli2/option/ java/org/apache/commons/cli2/resource/ ja...

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug13935Test.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug13935Test.java?rev=639943&r1=639942&r2=639943&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug13935Test.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug13935Test.java Fri Mar 21 20:08:23 2008
@@ -1 +1,60 @@
-/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.commons.cli2.bug;import junit.framework.TestCase;import org.apache.commons.cli2.CommandLine;import org.apache.commons.cli2.Group;import org.apache.commons.cli2.Option;import org.apach
 e.commons.cli2.builder.ArgumentBuilder;import org.apache.commons.cli2.builder.DefaultOptionBuilder;import org.apache.commons.cli2.builder.GroupBuilder;import org.apache.commons.cli2.commandline.Parser;/** * @author John Keyes */public class Bug13935Test extends TestCase {    public Bug13935Test(final String name) {        super(name);    }    public void testRequiredGroup() throws Exception {        final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();        final ArgumentBuilder abuilder = new ArgumentBuilder();        final GroupBuilder gbuilder = new GroupBuilder();        final Option testOption =            obuilder                .withShortName("a")                .withArgument(abuilder.withName("quoted string").create())                .create();        final Group options = gbuilder.withOption(testOption).create();        final Parser parser = new Parser();        parser.setGroup(options);        final CommandLine cmdLine =            parser.parse(new St
 ring[] { "-a", "\"two tokens\"" });        assertTrue(cmdLine.hasOption("-a"));        assertEquals("two tokens", cmdLine.getValue("-a"));    }}
\ No newline at end of file
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.cli2.bug;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.Group;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.DefaultOptionBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.commandline.Parser;
+
+/**
+ * @author John Keyes
+ */
+public class Bug13935Test extends TestCase {
+
+    public Bug13935Test(final String name) {
+        super(name);
+    }
+
+    public void testRequiredGroup() throws Exception {
+        final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
+        final ArgumentBuilder abuilder = new ArgumentBuilder();
+        final GroupBuilder gbuilder = new GroupBuilder();
+
+        final Option testOption =
+            obuilder
+                .withShortName("a")
+                .withArgument(abuilder.withName("quoted string").create())
+                .create();
+
+        final Group options = gbuilder.withOption(testOption).create();
+
+        final Parser parser = new Parser();
+        parser.setGroup(options);
+
+        final CommandLine cmdLine =
+            parser.parse(new String[] { "-a", "\"two tokens\"" });
+
+        assertTrue(cmdLine.hasOption("-a"));
+        assertEquals("two tokens", cmdLine.getValue("-a"));
+    }
+}

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug15046Test.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug15046Test.java?rev=639943&r1=639942&r2=639943&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug15046Test.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug15046Test.java Fri Mar 21 20:08:23 2008
@@ -1 +1,82 @@
-/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.commons.cli2.bug;import junit.framework.TestCase;import org.apache.commons.cli2.CommandLine;import org.apache.commons.cli2.Group;import org.apache.commons.cli2.Option;import org.apach
 e.commons.cli2.builder.ArgumentBuilder;import org.apache.commons.cli2.builder.DefaultOptionBuilder;import org.apache.commons.cli2.builder.GroupBuilder;import org.apache.commons.cli2.commandline.Parser;/** * @author John Keyes */public class Bug15046Test extends TestCase {    public Bug15046Test(String name) {        super(name);    }    public void testParamNamedAsOption() throws Exception {        final String[] CLI_ARGS = new String[] { "-z", "c" };        DefaultOptionBuilder obuilder = new DefaultOptionBuilder();        ArgumentBuilder abuilder = new ArgumentBuilder();        Option option =            obuilder                .withShortName("z")                .withLongName("timezone")                .withDescription("affected option")                .withArgument(abuilder.withName("timezone").create())                .create();        GroupBuilder gbuilder = new GroupBuilder();        Group options =            gbuilder.withName("bug15046").withOption(option).create(); 
        Parser parser = new Parser();        parser.setGroup(options);        CommandLine line = parser.parse(CLI_ARGS);        assertEquals("c", line.getValue("-z"));        Option c =            obuilder                .withShortName("c")                .withLongName("conflict")                .withDescription("conflicting option")                .withArgument(abuilder.withName("conflict").create())                .create();        options =            gbuilder                .withName("bug15046")                .withOption(option)                .withOption(c)                .create();        parser.setGroup(options);        line = parser.parse(CLI_ARGS);        assertEquals("c", line.getValue("-z"));    }}
\ No newline at end of file
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.cli2.bug;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.Group;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.DefaultOptionBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.commandline.Parser;
+
+/**
+ * @author John Keyes
+ */
+public class Bug15046Test extends TestCase {
+
+    public Bug15046Test(String name) {
+        super(name);
+    }
+
+    public void testParamNamedAsOption() throws Exception {
+        final String[] CLI_ARGS = new String[] { "-z", "c" };
+
+        DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
+        ArgumentBuilder abuilder = new ArgumentBuilder();
+
+        Option option =
+            obuilder
+                .withShortName("z")
+                .withLongName("timezone")
+                .withDescription("affected option")
+                .withArgument(abuilder.withName("timezone").create())
+                .create();
+
+        GroupBuilder gbuilder = new GroupBuilder();
+        Group options =
+            gbuilder.withName("bug15046").withOption(option).create();
+
+        Parser parser = new Parser();
+        parser.setGroup(options);
+        CommandLine line = parser.parse(CLI_ARGS);
+
+        assertEquals("c", line.getValue("-z"));
+
+        Option c =
+            obuilder
+                .withShortName("c")
+                .withLongName("conflict")
+                .withDescription("conflicting option")
+                .withArgument(abuilder.withName("conflict").create())
+                .create();
+
+        options =
+            gbuilder
+                .withName("bug15046")
+                .withOption(option)
+                .withOption(c)
+                .create();
+
+        parser.setGroup(options);
+        line = parser.parse(CLI_ARGS);
+
+        assertEquals("c", line.getValue("-z"));
+    }
+}

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug15648Test.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug15648Test.java?rev=639943&r1=639942&r2=639943&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug15648Test.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug15648Test.java Fri Mar 21 20:08:23 2008
@@ -1 +1,60 @@
-/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.commons.cli2.bug;import junit.framework.TestCase;import org.apache.commons.cli2.CommandLine;import org.apache.commons.cli2.Group;import org.apache.commons.cli2.Option;import org.apach
 e.commons.cli2.builder.ArgumentBuilder;import org.apache.commons.cli2.builder.DefaultOptionBuilder;import org.apache.commons.cli2.builder.GroupBuilder;import org.apache.commons.cli2.commandline.Parser;/** * @author John Keyes */public class Bug15648Test extends TestCase {    public Bug15648Test(final String name) {        super(name);    }    public void testQuotedArgumentValue() throws Exception {        final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();        final ArgumentBuilder abuilder = new ArgumentBuilder();        final GroupBuilder gbuilder = new GroupBuilder();        final Option testOption =            obuilder                .withShortName("a")                .withArgument(abuilder.withName("quoted string").create())                .create();        final Group options = gbuilder.withOption(testOption).create();        final Parser parser = new Parser();        parser.setGroup(options);        final CommandLine cmdLine =            parser.parse(
 new String[] { "-a", "\"two tokens\"" });        assertTrue(cmdLine.hasOption("-a"));        assertEquals("two tokens", cmdLine.getValue("-a"));    }}
\ No newline at end of file
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.cli2.bug;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.Group;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.DefaultOptionBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.commandline.Parser;
+
+/**
+ * @author John Keyes
+ */
+public class Bug15648Test extends TestCase {
+
+    public Bug15648Test(final String name) {
+        super(name);
+    }
+
+    public void testQuotedArgumentValue() throws Exception {
+        final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
+        final ArgumentBuilder abuilder = new ArgumentBuilder();
+        final GroupBuilder gbuilder = new GroupBuilder();
+
+        final Option testOption =
+            obuilder
+                .withShortName("a")
+                .withArgument(abuilder.withName("quoted string").create())
+                .create();
+
+        final Group options = gbuilder.withOption(testOption).create();
+
+        final Parser parser = new Parser();
+        parser.setGroup(options);
+
+        final CommandLine cmdLine =
+            parser.parse(new String[] { "-a", "\"two tokens\"" });
+
+        assertTrue(cmdLine.hasOption("-a"));
+        assertEquals("two tokens", cmdLine.getValue("-a"));
+    }
+}

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug27575Test.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug27575Test.java?rev=639943&r1=639942&r2=639943&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug27575Test.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug27575Test.java Fri Mar 21 20:08:23 2008
@@ -1 +1,41 @@
-/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.commons.cli2.bug;import java.util.Iterator;import junit.framework.TestCase;import org.apache.commons.cli2.Option;import org.apache.commons.cli2.builder.PatternBuilder;import org.apach
 e.commons.cli2.option.GroupImpl;public class Bug27575Test extends TestCase {	public void testRequiredOptions(){		PatternBuilder builder = new PatternBuilder();		builder.withPattern("hc!<");		Option option = builder.create();		assertTrue(option instanceof GroupImpl);		GroupImpl group = (GroupImpl)option;		Iterator i = group.getOptions().iterator();		assertEquals("[-h]",i.next().toString());		assertEquals("-c <arg>",i.next().toString());		assertFalse(i.hasNext());	}}
\ No newline at end of file
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.cli2.bug;
+
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.builder.PatternBuilder;
+import org.apache.commons.cli2.option.GroupImpl;
+
+public class Bug27575Test extends TestCase {
+
+	public void testRequiredOptions(){
+		PatternBuilder builder = new PatternBuilder();
+		builder.withPattern("hc!<");
+		Option option = builder.create();
+		assertTrue(option instanceof GroupImpl);
+		
+		GroupImpl group = (GroupImpl)option;
+		Iterator i = group.getOptions().iterator();
+		assertEquals("[-h]",i.next().toString());
+		assertEquals("-c <arg>",i.next().toString());
+		assertFalse(i.hasNext());
+	}
+}
\ No newline at end of file

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug28005Test.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug28005Test.java?rev=639943&r1=639942&r2=639943&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug28005Test.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug28005Test.java Fri Mar 21 20:08:23 2008
@@ -1 +1,79 @@
-/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.commons.cli2.bug;import org.apache.commons.cli2.Argument;import org.apache.commons.cli2.Group;import org.apache.commons.cli2.Option;import org.apache.commons.cli2.OptionException;impo
 rt org.apache.commons.cli2.builder.ArgumentBuilder;import org.apache.commons.cli2.builder.CommandBuilder;import org.apache.commons.cli2.builder.DefaultOptionBuilder;import org.apache.commons.cli2.builder.GroupBuilder;import org.apache.commons.cli2.commandline.Parser;import junit.framework.TestCase;public class Bug28005Test extends TestCase {    public void testInfiniteLoop() {        final DefaultOptionBuilder optionBuilder = new DefaultOptionBuilder();        final ArgumentBuilder argumentBuilder = new ArgumentBuilder();        final GroupBuilder groupBuilder = new GroupBuilder();        final CommandBuilder commandBuilder = new CommandBuilder();        final Option inputFormatOption =            optionBuilder                .withLongName("input-format")                //.withArgument(argumentBuilder.create())                .create();        final Argument argument =            argumentBuilder                .withName("file")                .create();        final Group ch
 ildren =            groupBuilder                .withName("options")                .withOption(inputFormatOption)                .create();        final Option command =            commandBuilder                .withName("convert")                .withChildren(children)                .withArgument(argument)                .create();        final Group root =            groupBuilder                .withName("commands")                .withOption(command)                .create();        final Parser parser = new Parser();        parser.setGroup(root);        final String[] args = new String[]{"convert", "test.txt",                "--input-format", "a"};        try {            parser.parse(args);            fail("a isn't valid!!");        } catch (OptionException e) {            assertEquals("Unexpected a while processing commands",e.getMessage());        }    }}
\ No newline at end of file
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.cli2.bug;
+
+import org.apache.commons.cli2.Argument;
+import org.apache.commons.cli2.Group;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.OptionException;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.CommandBuilder;
+import org.apache.commons.cli2.builder.DefaultOptionBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.commandline.Parser;
+import junit.framework.TestCase;
+
+public class Bug28005Test extends TestCase {
+    public void testInfiniteLoop() {
+        final DefaultOptionBuilder optionBuilder = new DefaultOptionBuilder();
+        final ArgumentBuilder argumentBuilder = new ArgumentBuilder();
+        final GroupBuilder groupBuilder = new GroupBuilder();
+        final CommandBuilder commandBuilder = new CommandBuilder();
+        
+        final Option inputFormatOption = 
+            optionBuilder
+                .withLongName("input-format")
+                //.withArgument(argumentBuilder.create())
+                .create();
+                
+        final Argument argument = 
+            argumentBuilder
+                .withName("file")
+                .create();
+                
+        final Group children = 
+            groupBuilder
+                .withName("options")
+                .withOption(inputFormatOption)
+                .create();
+                
+        final Option command = 
+            commandBuilder
+                .withName("convert")
+                .withChildren(children)
+                .withArgument(argument)
+                .create();
+                
+        final Group root = 
+            groupBuilder
+                .withName("commands")
+                .withOption(command)
+                .create();
+                
+        final Parser parser = new Parser();
+        parser.setGroup(root);
+        final String[] args = new String[]{"convert", "test.txt",
+                "--input-format", "a"};
+                
+        try {
+            parser.parse(args);
+            fail("a isn't valid!!");
+        } catch (OptionException e) {
+            assertEquals("Unexpected a while processing commands",e.getMessage());
+        }
+    }
+}
\ No newline at end of file

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug32533Test.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug32533Test.java?rev=639943&r1=639942&r2=639943&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug32533Test.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/Bug32533Test.java Fri Mar 21 20:08:23 2008
@@ -1 +1,48 @@
-/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.commons.cli2.bug;import org.apache.commons.cli2.Group;import org.apache.commons.cli2.Option;import org.apache.commons.cli2.OptionException;import org.apache.commons.cli2.builder.Defau
 ltOptionBuilder;import org.apache.commons.cli2.builder.GroupBuilder;import org.apache.commons.cli2.commandline.Parser;import junit.framework.TestCase;/** * @author roxspring */public class Bug32533Test extends TestCase {    public void testBlah() throws OptionException {        Option a1 = new DefaultOptionBuilder().withLongName("a1").create();        Option b1 = new DefaultOptionBuilder().withLongName("b1").create();        Option c1 = new DefaultOptionBuilder().withLongName("c1").create();        Group b = new GroupBuilder().withOption(b1).create();        Group c = new GroupBuilder().withOption(c1).create();        Group a = new GroupBuilder().withOption(a1).withOption(b).withOption(c).create();        Parser parser = new Parser();        parser.setGroup(a);        parser.parse(new String[]{"--a1","--b1"});    }}
\ No newline at end of file
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.cli2.bug;
+
+import org.apache.commons.cli2.Group;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.OptionException;
+import org.apache.commons.cli2.builder.DefaultOptionBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.commandline.Parser;
+
+import junit.framework.TestCase;
+
+/**
+ * @author roxspring
+ */
+public class Bug32533Test extends TestCase {
+    
+    public void testBlah() throws OptionException {
+        
+        Option a1 = new DefaultOptionBuilder().withLongName("a1").create();
+        Option b1 = new DefaultOptionBuilder().withLongName("b1").create();
+        Option c1 = new DefaultOptionBuilder().withLongName("c1").create();
+        
+        Group b = new GroupBuilder().withOption(b1).create();
+        Group c = new GroupBuilder().withOption(c1).create();
+        Group a = new GroupBuilder().withOption(a1).withOption(b).withOption(c).create();
+        
+        Parser parser = new Parser();  
+        parser.setGroup(a);
+        parser.parse(new String[]{"--a1","--b1"});
+    }
+
+}

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugCLI122Test.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugCLI122Test.java?rev=639943&r1=639942&r2=639943&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugCLI122Test.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugCLI122Test.java Fri Mar 21 20:08:23 2008
@@ -1 +1,45 @@
-package org.apache.commons.cli2.bug;import junit.framework.TestCase;import org.apache.commons.cli2.*;import org.apache.commons.cli2.builder.ArgumentBuilder;import org.apache.commons.cli2.builder.DefaultOptionBuilder;import org.apache.commons.cli2.builder.GroupBuilder;import org.apache.commons.cli2.commandline.Parser;import org.apache.commons.cli2.validation.FileValidator;/** * @author brianegge */public class BugCLI122Test extends TestCase {    public void testArgumentWhichStartsWithDash() throws OptionException {        Argument wdArg = new ArgumentBuilder()                .withName("anything")                .withMaximum(1)                .withMinimum(1)                .withInitialSeparator('=')                .create();        Option wdOpt = new DefaultOptionBuilder().withArgument(wdArg)                .withDescription("anything, foo or -foo")                .withLongName("argument")                .withShortName("a")                .create();        Group group = new Gro
 upBuilder().withOption(wdOpt).create();        Parser p = new Parser();        p.setGroup(group);        CommandLine normal = p.parse (new String[]{"-a", "foo"});        assertNotNull(normal);        assertEquals(normal.getValue(wdOpt), "foo");        CommandLine withDash = p.parse (new String[]{"--argument", "\"-foo\""});        assertNotNull(withDash);        assertEquals("-foo", withDash.getValue(wdOpt));        CommandLine withDashAndEquals = p.parse (new String[]{"--argument=-foo"});        assertNotNull(withDashAndEquals);        assertEquals("-foo", withDashAndEquals.getValue(wdOpt));    }}
\ No newline at end of file
+package org.apache.commons.cli2.bug;
+
+import junit.framework.TestCase;
+import org.apache.commons.cli2.*;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.DefaultOptionBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.commandline.Parser;
+import org.apache.commons.cli2.validation.FileValidator;
+
+/**
+ * @author brianegge
+ */
+public class BugCLI122Test extends TestCase {
+    public void testArgumentWhichStartsWithDash() throws OptionException {
+        Argument wdArg = new ArgumentBuilder()
+                .withName("anything")
+                .withMaximum(1)
+                .withMinimum(1)
+                .withInitialSeparator('=')
+                .create();
+
+        Option wdOpt = new DefaultOptionBuilder().withArgument(wdArg)
+                .withDescription("anything, foo or -foo")
+                .withLongName("argument")
+                .withShortName("a")
+                .create();
+
+        Group group = new GroupBuilder().withOption(wdOpt).create();
+
+        Parser p = new Parser();
+        p.setGroup(group);
+        CommandLine normal = p.parse (new String[]{"-a", "foo"});
+        assertNotNull(normal);
+        assertEquals(normal.getValue(wdOpt), "foo");
+
+        CommandLine withDash = p.parse (new String[]{"--argument", "\"-foo\""});
+        assertNotNull(withDash);
+        assertEquals("-foo", withDash.getValue(wdOpt));
+
+        CommandLine withDashAndEquals = p.parse (new String[]{"--argument=-foo"});
+        assertNotNull(withDashAndEquals);
+        assertEquals("-foo", withDashAndEquals.getValue(wdOpt));
+    }
+}

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugCLI12Test.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugCLI12Test.java?rev=639943&r1=639942&r2=639943&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugCLI12Test.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugCLI12Test.java Fri Mar 21 20:08:23 2008
@@ -1 +1,57 @@
-/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.commons.cli2.bug;import junit.framework.TestCase;import org.apache.commons.cli2.Argument;import org.apache.commons.cli2.CommandLine;import org.apache.commons.cli2.Group;import org.apa
 che.commons.cli2.Option;import org.apache.commons.cli2.builder.ArgumentBuilder;import org.apache.commons.cli2.builder.GroupBuilder;import org.apache.commons.cli2.commandline.Parser;import org.apache.commons.cli2.option.PropertyOption;/** * http://issues.apache.org/jira/browse/CLI-12 */public class BugCLI12Test extends TestCase {  public void testBug() {    Argument arg = new ArgumentBuilder().withName("file").create();    Option option = new PropertyOption();    Group group = new GroupBuilder().withOption(option).withOption(arg).create();    Parser p = new Parser();    p.setGroup(group);    CommandLine cl = p.parseAndHelp( new String[] { "-Dmyprop1=myval1", "-Dmyprop2=myval2", "myfile" } );    if(cl == null) {      assertTrue("Couldn't parse valid commandLine", false);    }    assertEquals( "myval1", cl.getProperty("myprop1"));    assertEquals( "myval2", cl.getProperty("myprop2"));    String extraArgs = (String) cl.getValue(arg);    assertEquals( "myfile", extraArgs);  }}
\ No newline at end of file
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.cli2.bug;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.cli2.Argument;
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.Group;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.commandline.Parser;
+import org.apache.commons.cli2.option.PropertyOption;
+
+/**
+ * http://issues.apache.org/jira/browse/CLI-12
+ */
+public class BugCLI12Test extends TestCase {
+
+  public void testBug() {
+    Argument arg = new ArgumentBuilder().withName("file").create();
+
+    Option option = new PropertyOption();
+
+    Group group = new GroupBuilder().withOption(option).withOption(arg).create();
+
+    Parser p = new Parser();
+    p.setGroup(group);
+
+    CommandLine cl = p.parseAndHelp( new String[] { "-Dmyprop1=myval1", "-Dmyprop2=myval2", "myfile" } );
+    if(cl == null) {
+      assertTrue("Couldn't parse valid commandLine", false);
+    }
+
+    assertEquals( "myval1", cl.getProperty("myprop1"));
+    assertEquals( "myval2", cl.getProperty("myprop2"));
+
+    String extraArgs = (String) cl.getValue(arg);
+    assertEquals( "myfile", extraArgs);
+  }
+
+}

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugCLI18Test.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugCLI18Test.java?rev=639943&r1=639942&r2=639943&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugCLI18Test.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugCLI18Test.java Fri Mar 21 20:08:23 2008
@@ -1 +1,60 @@
-/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.commons.cli2.bug;import java.io.PrintWriter;import java.io.StringWriter;import org.apache.commons.cli2.Group;import org.apache.commons.cli2.Option;import org.apache.commons.cli2.build
 er.DefaultOptionBuilder;import org.apache.commons.cli2.builder.GroupBuilder;import org.apache.commons.cli2.util.HelpFormatter;import junit.framework.TestCase;/** * http://issues.apache.org/jira/browse/CLI-18 */public class BugCLI18Test extends TestCase {  public BugCLI18Test() {    super();  }  public void testBug() {    Option a = new DefaultOptionBuilder().withLongName("aaa").withShortName("a").withDescription("aaaaaaa").create();    Option b = new DefaultOptionBuilder().withLongName("bbb").withDescription("bbbbbbbb dksh fkshd fkhs dkfhsdk fhskd hksdks dhfowehfsdhfkjshf skfhkshf sf jkshfk sfh skfh skf f").create();    Option c = new DefaultOptionBuilder().withLongName("ccc").withShortName("c").withDescription("ccccccc").create();    Group g = new GroupBuilder().withOption(a).withOption(b).withOption(c).create();    HelpFormatter formatter = new HelpFormatter();    StringWriter out = new StringWriter();    formatter.setPrintWriter(new PrintWriter(out));    formatter.setHead
 er("dsfkfsh kdh hsd hsdh fkshdf ksdh fskdh fsdh fkshfk sfdkjhskjh fkjh fkjsh khsdkj hfskdhf skjdfh ksf khf s");    formatter.setFooter("blort j jgj j jg jhghjghjgjhgjhg jgjhgj jhg jhg hjg jgjhghjg jhg hjg jhgjg jgjhghjg jg jgjhgjgjg jhg jhgjh" + '\r' + '\n' + "rarrr");    formatter.setGroup(g);    formatter.setShellCommand("foobar");    formatter.print();  }}
\ No newline at end of file
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.cli2.bug;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.commons.cli2.Group;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.builder.DefaultOptionBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.util.HelpFormatter;
+
+import junit.framework.TestCase;
+
+/**
+ * http://issues.apache.org/jira/browse/CLI-18
+ */
+public class BugCLI18Test extends TestCase {
+
+  public BugCLI18Test() {
+    super();
+  }
+
+
+  public void testBug() {
+    Option a = new DefaultOptionBuilder().withLongName("aaa").withShortName("a").withDescription("aaaaaaa").create();
+    Option b = new DefaultOptionBuilder().withLongName("bbb").withDescription("bbbbbbbb dksh fkshd fkhs dkfhsdk fhskd hksdks dhfowehfsdhfkjshf skfhkshf sf jkshfk sfh skfh skf f").create();
+    Option c = new DefaultOptionBuilder().withLongName("ccc").withShortName("c").withDescription("ccccccc").create();
+
+    Group g = new GroupBuilder().withOption(a).withOption(b).withOption(c).create();
+
+    HelpFormatter formatter = new HelpFormatter();
+    StringWriter out = new StringWriter();
+
+    formatter.setPrintWriter(new PrintWriter(out));
+    formatter.setHeader("dsfkfsh kdh hsd hsdh fkshdf ksdh fskdh fsdh fkshfk sfdkjhskjh fkjh fkjsh khsdkj hfskdhf skjdfh ksf khf s");
+    formatter.setFooter("blort j jgj j jg jhghjghjgjhgjhg jgjhgj jhg jhg hjg jgjhghjg jhg hjg jhgjg jgjhghjg jg jgjhgjgjg jhg jhgjh" + '\r' + '\n' + "rarrr");
+    formatter.setGroup(g);
+    formatter.setShellCommand("foobar");
+
+    formatter.print();
+
+  }
+}
+

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugCLI80Test.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugCLI80Test.java?rev=639943&r1=639942&r2=639943&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugCLI80Test.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugCLI80Test.java Fri Mar 21 20:08:23 2008
@@ -1 +1,67 @@
-/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.commons.cli2.bug;import org.apache.commons.cli2.Argument;import org.apache.commons.cli2.CommandLine;import org.apache.commons.cli2.Group;import org.apache.commons.cli2.Option;import o
 rg.apache.commons.cli2.OptionException;import org.apache.commons.cli2.builder.ArgumentBuilder;import org.apache.commons.cli2.builder.DefaultOptionBuilder;import org.apache.commons.cli2.builder.GroupBuilder;import org.apache.commons.cli2.commandline.Parser;import junit.framework.TestCase;/** * http://issues.apache.org/jira/browse/CLI-80 */public class BugCLI80Test extends TestCase {    public void testBug() {        final String optName = "option";        Argument arg = new ArgumentBuilder().withName(optName)                                            .withMaximum(1)                                            .create();        Option option = new DefaultOptionBuilder().withArgument(arg)                                                  .withDescription("singular option")                                                  .withLongName(optName)                                                  .withShortName("o")                                                  .create();        G
 roup group = new GroupBuilder().withOption(option).create();        Parser p = new Parser();        p.setGroup(group);        CommandLine cl = p.parseAndHelp( new String[] { "-o", "yes" } );        assertNotNull("Couldn't parse valid commandLine", cl);        assertEquals("Couldn't look up value by short name", "yes", cl.getValue("-o") );        try {            cl = p.parse( new String[] { "-o", "yes", "-o", "jam" } );            fail("Parsed invalid commandLine");        } catch(OptionException e) {          // ok        }    }}
\ No newline at end of file
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.cli2.bug;
+
+import org.apache.commons.cli2.Argument;
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.Group;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.OptionException;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.DefaultOptionBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.commandline.Parser;
+
+import junit.framework.TestCase;
+
+/**
+ * http://issues.apache.org/jira/browse/CLI-80
+ */
+public class BugCLI80Test extends TestCase {
+
+    public void testBug() {
+        final String optName = "option";
+
+        Argument arg = new ArgumentBuilder().withName(optName)
+                                            .withMaximum(1)
+                                            .create();
+
+        Option option = new DefaultOptionBuilder().withArgument(arg)
+                                                  .withDescription("singular option")
+                                                  .withLongName(optName)
+                                                  .withShortName("o")
+                                                  .create();
+
+        Group group = new GroupBuilder().withOption(option).create();
+
+        Parser p = new Parser();
+        p.setGroup(group);
+
+        CommandLine cl = p.parseAndHelp( new String[] { "-o", "yes" } );
+        assertNotNull("Couldn't parse valid commandLine", cl);
+
+        assertEquals("Couldn't look up value by short name", "yes", cl.getValue("-o") );
+
+        try {
+            cl = p.parse( new String[] { "-o", "yes", "-o", "jam" } );
+            fail("Parsed invalid commandLine");
+        } catch(OptionException e) {
+          // ok
+        }
+    }
+
+}

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugLoopingOptionLookAlikeTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugLoopingOptionLookAlikeTest.java?rev=639943&r1=639942&r2=639943&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugLoopingOptionLookAlikeTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/bug/BugLoopingOptionLookAlikeTest.java Fri Mar 21 20:08:23 2008
@@ -1 +1,79 @@
-/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements.  See the NOTICE file * distributed with this work for additional information * regarding copyright ownership.  The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License.  You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied.  See the License for the * specific language governing permissions and limitations * under the License. */package org.apache.commons.cli2.bug;import junit.framework.TestCase;import org.apache.commons.cli2.Argument;import org.apache.commons.cli2.Group;import org.apache.commons.cli2.OptionException;import or
 g.apache.commons.cli2.builder.ArgumentBuilder;import org.apache.commons.cli2.builder.DefaultOptionBuilder;import org.apache.commons.cli2.builder.GroupBuilder;import org.apache.commons.cli2.commandline.Parser;import org.apache.commons.cli2.option.SourceDestArgument;/** * The first is a loop in Parser.parse() if I set a non-declared option. This * code goes into a loop in Parser.java method parse this “while” loop runs * endless * * @author Steve Alberty */public class BugLoopingOptionLookAlikeTest extends TestCase {    public void testLoopingOptionLookAlike() {        final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();        final ArgumentBuilder abuilder = new ArgumentBuilder();        final GroupBuilder gbuilder = new GroupBuilder();        final Group options = gbuilder            .withName("ant")            .withOption(obuilder.withShortName("help").withDescription("print this message").create())            .withOption(obuilder.withShortName("projecthelp"
 ).withDescription("print project help information").create())            .withOption(abuilder.withName("target").create())            .create();        final Parser parser = new Parser();        parser.setGroup(options);        try {            parser.parse(new String[] { "-abcdef",                    "testfile.txt ", });            fail("OptionException");        } catch (OptionException e) {            assertEquals("Unexpected -abcdef while processing ant",e.getMessage());        }    }    public void testLoopingOptionLookAlike2() {        final ArgumentBuilder abuilder = new ArgumentBuilder();        final GroupBuilder gbuilder = new GroupBuilder();        final Argument inputfile_opt = abuilder.withName("input").withMinimum(1).withMaximum(1).create();        final Argument outputfile_opt = abuilder.withName("output").withMinimum(1).withMaximum(1).create();        final Argument targets = new SourceDestArgument(inputfile_opt, outputfile_opt);        final Group options = 
 gbuilder.withOption(targets).create();        final Parser parser = new Parser();        parser.setGroup(options);        try {            parser.parse(new String[] { "testfile.txt", "testfile.txt", "testfile.txt", "testfile.txt" });            fail("OptionException");        } catch (OptionException e) {            assertEquals("Unexpected testfile.txt while processing ", e.getMessage());        }    }}
\ No newline at end of file
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.cli2.bug;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.cli2.Argument;
+import org.apache.commons.cli2.Group;
+import org.apache.commons.cli2.OptionException;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.DefaultOptionBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.commandline.Parser;
+import org.apache.commons.cli2.option.SourceDestArgument;
+
+/**
+ * The first is a loop in Parser.parse() if I set a non-declared option. This 
+ * code goes into a loop in Parser.java method parse this “while” loop runs 
+ * endless
+ * 
+ * @author Steve Alberty
+ */
+public class BugLoopingOptionLookAlikeTest extends TestCase {
+
+    public void testLoopingOptionLookAlike() {
+        final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
+        final ArgumentBuilder abuilder = new ArgumentBuilder();
+        final GroupBuilder gbuilder = new GroupBuilder();
+        final Group options = gbuilder
+            .withName("ant")
+            .withOption(obuilder.withShortName("help").withDescription("print this message").create())
+            .withOption(obuilder.withShortName("projecthelp").withDescription("print project help information").create())
+            .withOption(abuilder.withName("target").create())
+            .create();
+        
+        final Parser parser = new Parser();
+        parser.setGroup(options);
+        try {
+            parser.parse(new String[] { "-abcdef",
+                    "testfile.txt ", });
+            fail("OptionException");
+        } catch (OptionException e) {
+            assertEquals("Unexpected -abcdef while processing ant",e.getMessage());
+        }
+    }
+    
+    public void testLoopingOptionLookAlike2() {
+        final ArgumentBuilder abuilder = new ArgumentBuilder();
+        final GroupBuilder gbuilder = new GroupBuilder();
+        final Argument inputfile_opt = abuilder.withName("input").withMinimum(1).withMaximum(1).create();
+        final Argument outputfile_opt = abuilder.withName("output").withMinimum(1).withMaximum(1).create();
+        final Argument targets = new SourceDestArgument(inputfile_opt, outputfile_opt);
+        final Group options = gbuilder.withOption(targets).create();
+        final Parser parser = new Parser();
+        parser.setGroup(options);
+        try {
+            parser.parse(new String[] { "testfile.txt", "testfile.txt", "testfile.txt", "testfile.txt" });
+            fail("OptionException");
+        } catch (OptionException e) {
+            assertEquals("Unexpected testfile.txt while processing ", e.getMessage());
+        }
+    }    
+}

Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli2/builder/ArgumentBuilderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/builder/ArgumentBuilderTest.java?rev=639943&r1=639942&r2=639943&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli2/builder/ArgumentBuilderTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli2/builder/ArgumentBuilderTest.java Fri Mar 21 20:08:23 2008
@@ -1 +1,254 @@
-/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements.  See the NOTICE file * distributed with this work for additional information * regarding copyright ownership.  The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License.  You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied.  See the License for the * specific language governing permissions and limitations * under the License. */package org.apache.commons.cli2.builder;import java.util.ArrayList;import java.util.List;import junit.framework.TestCase;import org.apache.commons.cli2.option.ArgumentImpl;import org.apache.commons.cli
 2.resource.ResourceConstants;import org.apache.commons.cli2.resource.ResourceHelper;import org.apache.commons.cli2.validation.DateValidator;import org.apache.commons.cli2.validation.Validator;public class ArgumentBuilderTest    extends TestCase {    private static final ResourceHelper resources = ResourceHelper.getResourceHelper();    private ArgumentBuilder argumentBuilder;    /*     * @see TestCase#setUp()     */    protected void setUp()        throws Exception {        this.argumentBuilder = new ArgumentBuilder();    }    public void testConsumeRemaining() {        this.argumentBuilder.withConsumeRemaining("--");        this.argumentBuilder.withName("arg");        ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();        assertEquals("incorrect consume remaining token", "--", arg.getConsumeRemaining());    }    public void testNullConsumeRemaining() {        try {            this.argumentBuilder.withConsumeRemaining(null);            fail("cannot use null c
 onsume remaining token");        } catch (IllegalArgumentException exp) {            assertEquals("wrong exception message",                         resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NULL_CONSUME_REMAINING),                         exp.getMessage());        }    }    public void testEmptyConsumeRemaining() {        try {            this.argumentBuilder.withConsumeRemaining("");            fail("cannot use empty string consume remaining token");        } catch (IllegalArgumentException exp) {            assertEquals("wrong exception message",                         resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_EMPTY_CONSUME_REMAINING),                         exp.getMessage());        }    }    public void testDefault() {        this.argumentBuilder.withDefault("defaultString");        this.argumentBuilder.withName("arg");        ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();        assertEquals("incorrect number of default v
 alues", 1, arg.getDefaultValues().size());        assertEquals("incorrect default value", "defaultString", arg.getDefaultValues().get(0));    }    public void testDefaultX2() {        this.argumentBuilder.withDefault("defaultString1");        this.argumentBuilder.withDefault("defaultString2");        this.argumentBuilder.withName("arg");        ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();        assertEquals("incorrect number of default values", 2, arg.getDefaultValues().size());        assertEquals("incorrect default value-1", "defaultString1", arg.getDefaultValues().get(0));        assertEquals("incorrect default value-2", "defaultString2", arg.getDefaultValues().get(1));    }    public void testNullDefault() {        try {            this.argumentBuilder.withDefault(null);            fail("cannot use null default");        } catch (IllegalArgumentException exp) {            assertEquals("wrong exception message",                         resources.getMe
 ssage(ResourceConstants.ARGUMENT_BUILDER_NULL_DEFAULT),                         exp.getMessage());        }    }    public void testDefaults() {        final List defaults = new ArrayList();        defaults.add("one");        defaults.add("two");        this.argumentBuilder.withDefaults(defaults);        this.argumentBuilder.withName("arg");        ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();        assertEquals("incorrect number of default values", 2, arg.getDefaultValues().size());        assertEquals("incorrect default value-1", "one", arg.getDefaultValues().get(0));        assertEquals("incorrect default value-2", "two", arg.getDefaultValues().get(1));        assertEquals("incorrect default values list", defaults, arg.getDefaultValues());    }    public void testNullDefaults() {        try {            this.argumentBuilder.withDefaults(null);            fail("cannot use null defaults");        } catch (IllegalArgumentException exp) {            assert
 Equals("wrong exception message",                         resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NULL_DEFAULTS),                         exp.getMessage());        }    }    public void testId() {        this.argumentBuilder.withId(1);        this.argumentBuilder.withName("arg");        ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();        assertEquals("incorrect id", 1, arg.getId());    }    public void testInitialSeparator() {        this.argumentBuilder.withInitialSeparator(',');        this.argumentBuilder.withName("arg");        ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();        assertEquals("incorrect initial separator", ',', arg.getInitialSeparator());    }    public void testMaximum() {        this.argumentBuilder.withMaximum(1);        this.argumentBuilder.withName("arg");        ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();        assertEquals("incorrect maximum", 1, arg.getMaximum());    }  
   public void testNegativeMaximum() {        try {            this.argumentBuilder.withMaximum(-1);            fail("cannot use negative maximum");        } catch (IllegalArgumentException exp) {            assertEquals("wrong exception message",                         resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NEGATIVE_MAXIMUM),                         exp.getMessage());        }    }    public void testMinimum() {        this.argumentBuilder.withMinimum(1);        this.argumentBuilder.withName("arg");        ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();        assertEquals("incorrect maximum", 1, arg.getMinimum());    }    public void testNegativeMinimum() {        try {            this.argumentBuilder.withMinimum(-1);            fail("cannot use negative minimum");        } catch (IllegalArgumentException exp) {            assertEquals("wrong exception message",                         resources.getMessage(ResourceConstants.ARGUMENT_BUILDE
 R_NEGATIVE_MINIMUM),                         exp.getMessage());        }    }    public void testName() {        this.argumentBuilder.withName("arg");        ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();        assertEquals("incorrect preferred name", "arg", arg.getPreferredName());    }    public void testNullName() {        try {            this.argumentBuilder.withName(null);            fail("cannot use null name");        } catch (IllegalArgumentException exp) {            assertEquals("wrong exception message",                         resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NULL_NAME),                         exp.getMessage());        }    }    public void testEmptyName() {        try {            this.argumentBuilder.withName("");            fail("cannot use empty name");        } catch (IllegalArgumentException exp) {            assertEquals("wrong exception message",                         resources.getMessage(ResourceConstants.ARG
 UMENT_BUILDER_EMPTY_NAME),                         exp.getMessage());        }    }    public void testSubsequentSeparator() {        this.argumentBuilder.withSubsequentSeparator(':');        this.argumentBuilder.withName("arg");        ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();        assertEquals("incorrect subsequent separator", ':', arg.getSubsequentSeparator());    }    public void testValidator() {        Validator validator = DateValidator.getDateInstance();        this.argumentBuilder.withValidator(validator);        this.argumentBuilder.withName("arg");        ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();        assertEquals("incorrect validator", validator, arg.getValidator());    }    public void testNullValidator() {        try {            this.argumentBuilder.withValidator(null);            fail("cannot use null validator");        } catch (IllegalArgumentException exp) {            assertEquals("wrong exception message"
 ,                         resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NULL_VALIDATOR),                         exp.getMessage());        }    }}
\ No newline at end of file
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.cli2.builder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.cli2.option.ArgumentImpl;
+import org.apache.commons.cli2.resource.ResourceConstants;
+import org.apache.commons.cli2.resource.ResourceHelper;
+import org.apache.commons.cli2.validation.DateValidator;
+import org.apache.commons.cli2.validation.Validator;
+
+public class ArgumentBuilderTest
+    extends TestCase {
+    private static final ResourceHelper resources = ResourceHelper.getResourceHelper();
+    private ArgumentBuilder argumentBuilder;
+
+    /*
+     * @see TestCase#setUp()
+     */
+    protected void setUp()
+        throws Exception {
+        this.argumentBuilder = new ArgumentBuilder();
+    }
+
+    public void testConsumeRemaining() {
+        this.argumentBuilder.withConsumeRemaining("--");
+        this.argumentBuilder.withName("arg");
+
+        ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();
+
+        assertEquals("incorrect consume remaining token", "--", arg.getConsumeRemaining());
+    }
+
+    public void testNullConsumeRemaining() {
+        try {
+            this.argumentBuilder.withConsumeRemaining(null);
+            fail("cannot use null consume remaining token");
+        } catch (IllegalArgumentException exp) {
+            assertEquals("wrong exception message",
+                         resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NULL_CONSUME_REMAINING),
+                         exp.getMessage());
+        }
+    }
+
+    public void testEmptyConsumeRemaining() {
+        try {
+            this.argumentBuilder.withConsumeRemaining("");
+            fail("cannot use empty string consume remaining token");
+        } catch (IllegalArgumentException exp) {
+            assertEquals("wrong exception message",
+                         resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_EMPTY_CONSUME_REMAINING),
+                         exp.getMessage());
+        }
+    }
+
+    public void testDefault() {
+        this.argumentBuilder.withDefault("defaultString");
+        this.argumentBuilder.withName("arg");
+
+        ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();
+
+        assertEquals("incorrect number of default values", 1, arg.getDefaultValues().size());
+        assertEquals("incorrect default value", "defaultString", arg.getDefaultValues().get(0));
+    }
+
+    public void testDefaultX2() {
+        this.argumentBuilder.withDefault("defaultString1");
+        this.argumentBuilder.withDefault("defaultString2");
+        this.argumentBuilder.withName("arg");
+
+        ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();
+
+        assertEquals("incorrect number of default values", 2, arg.getDefaultValues().size());
+        assertEquals("incorrect default value-1", "defaultString1", arg.getDefaultValues().get(0));
+        assertEquals("incorrect default value-2", "defaultString2", arg.getDefaultValues().get(1));
+    }
+
+    public void testNullDefault() {
+        try {
+            this.argumentBuilder.withDefault(null);
+            fail("cannot use null default");
+        } catch (IllegalArgumentException exp) {
+            assertEquals("wrong exception message",
+                         resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NULL_DEFAULT),
+                         exp.getMessage());
+        }
+    }
+
+    public void testDefaults() {
+        final List defaults = new ArrayList();
+        defaults.add("one");
+        defaults.add("two");
+
+        this.argumentBuilder.withDefaults(defaults);
+        this.argumentBuilder.withName("arg");
+
+        ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();
+
+        assertEquals("incorrect number of default values", 2, arg.getDefaultValues().size());
+        assertEquals("incorrect default value-1", "one", arg.getDefaultValues().get(0));
+        assertEquals("incorrect default value-2", "two", arg.getDefaultValues().get(1));
+        assertEquals("incorrect default values list", defaults, arg.getDefaultValues());
+
+    }
+
+    public void testNullDefaults() {
+        try {
+            this.argumentBuilder.withDefaults(null);
+            fail("cannot use null defaults");
+        } catch (IllegalArgumentException exp) {
+            assertEquals("wrong exception message",
+                         resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NULL_DEFAULTS),
+                         exp.getMessage());
+        }
+    }
+
+    public void testId() {
+        this.argumentBuilder.withId(1);
+        this.argumentBuilder.withName("arg");
+
+        ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();
+
+        assertEquals("incorrect id", 1, arg.getId());
+    }
+
+    public void testInitialSeparator() {
+        this.argumentBuilder.withInitialSeparator(',');
+        this.argumentBuilder.withName("arg");
+
+        ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();
+
+        assertEquals("incorrect initial separator", ',', arg.getInitialSeparator());
+    }
+
+    public void testMaximum() {
+        this.argumentBuilder.withMaximum(1);
+        this.argumentBuilder.withName("arg");
+
+        ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();
+
+        assertEquals("incorrect maximum", 1, arg.getMaximum());
+    }
+
+    public void testNegativeMaximum() {
+        try {
+            this.argumentBuilder.withMaximum(-1);
+            fail("cannot use negative maximum");
+        } catch (IllegalArgumentException exp) {
+            assertEquals("wrong exception message",
+                         resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NEGATIVE_MAXIMUM),
+                         exp.getMessage());
+        }
+    }
+
+    public void testMinimum() {
+        this.argumentBuilder.withMinimum(1);
+        this.argumentBuilder.withName("arg");
+
+        ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();
+
+        assertEquals("incorrect maximum", 1, arg.getMinimum());
+    }
+
+    public void testNegativeMinimum() {
+        try {
+            this.argumentBuilder.withMinimum(-1);
+            fail("cannot use negative minimum");
+        } catch (IllegalArgumentException exp) {
+            assertEquals("wrong exception message",
+                         resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NEGATIVE_MINIMUM),
+                         exp.getMessage());
+        }
+    }
+
+    public void testName() {
+        this.argumentBuilder.withName("arg");
+
+        ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();
+
+        assertEquals("incorrect preferred name", "arg", arg.getPreferredName());
+    }
+
+    public void testNullName() {
+        try {
+            this.argumentBuilder.withName(null);
+            fail("cannot use null name");
+        } catch (IllegalArgumentException exp) {
+            assertEquals("wrong exception message",
+                         resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NULL_NAME),
+                         exp.getMessage());
+        }
+    }
+
+    public void testEmptyName() {
+        try {
+            this.argumentBuilder.withName("");
+            fail("cannot use empty name");
+        } catch (IllegalArgumentException exp) {
+            assertEquals("wrong exception message",
+                         resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_EMPTY_NAME),
+                         exp.getMessage());
+        }
+    }
+
+    public void testSubsequentSeparator() {
+        this.argumentBuilder.withSubsequentSeparator(':');
+        this.argumentBuilder.withName("arg");
+
+        ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();
+
+        assertEquals("incorrect subsequent separator", ':', arg.getSubsequentSeparator());
+    }
+
+    public void testValidator() {
+        Validator validator = DateValidator.getDateInstance();
+        this.argumentBuilder.withValidator(validator);
+        this.argumentBuilder.withName("arg");
+
+        ArgumentImpl arg = (ArgumentImpl) this.argumentBuilder.create();
+
+        assertEquals("incorrect validator", validator, arg.getValidator());
+    }
+
+    public void testNullValidator() {
+        try {
+            this.argumentBuilder.withValidator(null);
+            fail("cannot use null validator");
+        } catch (IllegalArgumentException exp) {
+            assertEquals("wrong exception message",
+                         resources.getMessage(ResourceConstants.ARGUMENT_BUILDER_NULL_VALIDATOR),
+                         exp.getMessage());
+        }
+    }
+}