You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ba...@apache.org on 2007/05/22 19:47:17 UTC

svn commit: r540661 - in /jakarta/commons/proper/cli/branches/cli-1.0.x/src: java/org/apache/commons/cli/PosixParser.java test/org/apache/commons/cli/bug/BugCLI51Test.java

Author: bayard
Date: Tue May 22 10:47:16 2007
New Revision: 540661

URL: http://svn.apache.org/viewvc?view=rev&rev=540661
Log:
Applying test and fix patch from CLI-51. Thanks to Brian Egge. 

Added:
    jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/bug/BugCLI51Test.java
Modified:
    jakarta/commons/proper/cli/branches/cli-1.0.x/src/java/org/apache/commons/cli/PosixParser.java

Modified: jakarta/commons/proper/cli/branches/cli-1.0.x/src/java/org/apache/commons/cli/PosixParser.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/cli/branches/cli-1.0.x/src/java/org/apache/commons/cli/PosixParser.java?view=diff&rev=540661&r1=540660&r2=540661
==============================================================================
--- jakarta/commons/proper/cli/branches/cli-1.0.x/src/java/org/apache/commons/cli/PosixParser.java (original)
+++ jakarta/commons/proper/cli/branches/cli-1.0.x/src/java/org/apache/commons/cli/PosixParser.java Tue May 22 10:47:16 2007
@@ -99,7 +99,7 @@
 
         // an iterator for the command line tokens
         Iterator iter = Arrays.asList(arguments).iterator();
-        String token = null;
+        String token;
 
         // process each command line token
         while (iter.hasNext())
@@ -302,7 +302,8 @@
             }
             else
             {
-                tokens.add("-" + ch);
+                tokens.add(token);
+                break;
             }
         }
     }

Added: jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/bug/BugCLI51Test.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/bug/BugCLI51Test.java?view=auto&rev=540661
==============================================================================
--- jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/bug/BugCLI51Test.java (added)
+++ jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/bug/BugCLI51Test.java Tue May 22 10:47:16 2007
@@ -0,0 +1,51 @@
+/*
+ * 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.cli.bug;
+
+import junit.framework.TestCase;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Option;
+
+/**
+ * @author brianegge
+ */
+public class BugCLI51Test
+    extends TestCase
+{
+    public void test() throws Exception
+    {
+        Options options = buildCommandLineOptions();
+        CommandLineParser parser = new PosixParser();
+        String[] args = new String[] {"-t", "-something" };
+        CommandLine commandLine;
+        commandLine = parser.parse( options, args );
+        assertEquals("-something", commandLine.getOptionValue( 't'));
+    }
+
+    private Options buildCommandLineOptions()
+    {
+        Option opt = OptionBuilder.withArgName( "t").hasArg().create('t');
+        Options options = new Options();
+        options.addOption( opt);
+        return options;
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org