You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2017/06/08 17:37:57 UTC
[08/40] commons-cli git commit: An Avalon implementation of a commons
vargs codebase - split onto its own branch so we can start focusing on the
CLI parts individually
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli2/validation/NumberValidator.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/cli2/validation/NumberValidator.java b/src/java/org/apache/commons/cli2/validation/NumberValidator.java
deleted file mode 100644
index 2b3f940..0000000
--- a/src/java/org/apache/commons/cli2/validation/NumberValidator.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Copyright 2003-2005 The Apache Software Foundation
- *
- * Licensed 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.validation;
-
-import java.text.NumberFormat;
-import java.text.ParsePosition;
-
-import java.util.List;
-import java.util.ListIterator;
-
-import org.apache.commons.cli2.resource.ResourceConstants;
-import org.apache.commons.cli2.resource.ResourceHelper;
-
-/**
- * The <code>NumberValidator</code> validates the string argument
- * values are numbers. If the value is a number, the string value in
- * the {@link java.util.List} of values is replaced with the
- * {@link java.lang.Number} instance.
- *
- * A maximum and minimum value can also be specified using
- * the {@link #setMaximum setMaximum}, and the
- * {@link #setMinimum setMinimum} methods.
- *
- * The following example shows how to limit the valid values
- * for the age attribute to integers less than 100.
- *
- * <pre>
- * ...
- * ArgumentBuilder builder = new ArgumentBuilder();
- * NumberValidator validator = NumberValidator.getIntegerInstance();
- * validator.setMaximum(new Integer(100));
- *
- * Argument age =
- * builder.withName("age");
- * .withValidator(validator);
- * </pre>
- *
- * @author Rob Oxspring
- * @author John Keyes
- */
-public class NumberValidator implements Validator {
- /** the <code>NumberFormat</code> being used. */
- private NumberFormat format;
-
- /** the lower bound for argument values. */
- private Number minimum = null;
-
- /** the upper bound for argument values */
- private Number maximum = null;
-
- /**
- * Creates a new NumberValidator based on the specified NumberFormat
- * @param format the format of numbers to accept
- */
- public NumberValidator(final NumberFormat format) {
- setFormat(format);
- }
-
- /**
- * Returns a <code>NumberValidator</code> for a currency format
- * for the current default locale.
- * @return a <code>NumberValidator</code> for a currency format
- * for the current default locale.
- */
- public static NumberValidator getCurrencyInstance() {
- return new NumberValidator(NumberFormat.getCurrencyInstance());
- }
-
- /**
- * Returns a <code>NumberValidator</code> for an integer number format
- * for the current default locale.
- * @return a <code>NumberValidator</code> for an integer number format
- * for the current default locale.
- */
- public static NumberValidator getIntegerInstance() {
- final NumberFormat format = NumberFormat.getNumberInstance();
- format.setParseIntegerOnly(true);
-
- return new NumberValidator(format);
- }
-
- /**
- * Returns a <code>NumberValidator</code> for a percentage format
- * for the current default locale.
- * @return a <code>NumberValidator</code> for a percentage format
- * for the current default locale.
- */
- public static NumberValidator getPercentInstance() {
- return new NumberValidator(NumberFormat.getPercentInstance());
- }
-
- /**
- * Returns a <code>NumberValidator</code> for a general-purpose
- * number format for the current default locale.
- * @return a <code>NumberValidator</code> for a general-purpose
- * number format for the current default locale.
- */
- public static NumberValidator getNumberInstance() {
- return new NumberValidator(NumberFormat.getNumberInstance());
- }
-
- /**
- * Validate the list of values against the list of permitted values.
- * If a value is valid, replace the string in the <code>values</code>
- * {@link java.util.List} with the {@link java.lang.Number} instance.
- *
- * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
- */
- public void validate(final List values)
- throws InvalidArgumentException {
- for (final ListIterator i = values.listIterator(); i.hasNext();) {
- final String value = (String) i.next();
-
- final ParsePosition pp = new ParsePosition(0);
- final Number number = format.parse(value, pp);
-
- if (pp.getIndex() < value.length()) {
- throw new InvalidArgumentException(value);
- }
-
- if (((minimum != null) && (number.doubleValue() < minimum.doubleValue())) ||
- ((maximum != null) && (number.doubleValue() > maximum.doubleValue()))) {
- throw new InvalidArgumentException(ResourceHelper.getResourceHelper().getMessage(ResourceConstants.NUMBERVALIDATOR_NUMBER_OUTOFRANGE,
- new Object[] {
- value
- }));
- }
-
- i.set(number);
- }
- }
-
- /**
- * Return the format being used to validate argument values against.
- *
- * @return the format being used to validate argument values against.
- */
- public NumberFormat getFormat() {
- return format;
- }
-
- /**
- * Specify the format being used to validate argument values against.
- *
- * @param format the format being used to validate argument values against.
- */
- protected void setFormat(NumberFormat format) {
- this.format = format;
- }
-
- /**
- * Return the maximum value allowed for an argument value.
- *
- * @return the maximum value allowed for an argument value.
- */
- public Number getMaximum() {
- return maximum;
- }
-
- /**
- * Specify the maximum value allowed for an argument value.
- *
- * @param maximum the maximum value allowed for an argument value.
- */
- public void setMaximum(Number maximum) {
- this.maximum = maximum;
- }
-
- /**
- * Return the minimum value allowed for an argument value.
- *
- * @return the minimum value allowed for an argument value.
- */
- public Number getMinimum() {
- return minimum;
- }
-
- /**
- * Specify the minimum value allowed for an argument value.
- *
- * @param minimum the minimum value allowed for an argument value.
- */
- public void setMinimum(Number minimum) {
- this.minimum = minimum;
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli2/validation/UrlValidator.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/cli2/validation/UrlValidator.java b/src/java/org/apache/commons/cli2/validation/UrlValidator.java
deleted file mode 100644
index e73855b..0000000
--- a/src/java/org/apache/commons/cli2/validation/UrlValidator.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright 2003-2005 The Apache Software Foundation
- *
- * Licensed 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.validation;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import java.util.List;
-import java.util.ListIterator;
-
-import org.apache.commons.cli2.resource.ResourceConstants;
-import org.apache.commons.cli2.resource.ResourceHelper;
-
-/**
- * The <code>UrlValidator</code> validates the string argument
- * values are URLs. If the value is a URL, the string value in
- * the {@link java.util.List} of values is replaced with the
- * {@link java.net.URL} instance.
- *
- * URLs can also be validated based on their scheme by using
- * the {@link #setProtocol setProtocol} method, or by using the specified
- * {@link #UrlValidator(java.lang.String) constructor}.
- *
- * The following example shows how to limit the valid values
- * for the site argument to 'https' URLs.
- *
- * <pre>
- * ...
- * ArgumentBuilder builder = new ArgumentBuilder();
- * Argument site =
- * builder.withName("site");
- * .withValidator(new URLValidator("https"));
- * </pre>
- *
- * @author Rob Oxspring
- * @author John Keyes
- */
-public class UrlValidator implements Validator {
- /** allowed protocol */
- private String protocol = null;
-
- /**
- * Creates a UrlValidator.
- */
- public UrlValidator() {
- }
-
- /**
- * Creates a UrlValidator for the specified protocol.
- */
- public UrlValidator(final String protocol) {
- setProtocol(protocol);
- }
-
- /**
- * Validate the list of values against the list of permitted values.
- * If a value is valid, replace the string in the <code>values</code>
- * {@link java.util.List} with the { java.net.URL} instance.
- *
- * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
- */
- public void validate(final List values)
- throws InvalidArgumentException {
- for (final ListIterator i = values.listIterator(); i.hasNext();) {
- final String name = (String) i.next();
-
- try {
- final URL url = new URL(name);
-
- if ((protocol != null) && !protocol.equals(url.getProtocol())) {
- throw new InvalidArgumentException(name);
- }
-
- i.set(url);
- } catch (final MalformedURLException mue) {
- throw new InvalidArgumentException(ResourceHelper.getResourceHelper().getMessage(ResourceConstants.URLVALIDATOR_MALFORMED_URL,
- new Object[] {
- name
- }));
- }
- }
- }
-
- /**
- * Returns the protocol that must be used by a valid URL.
- *
- * @return the protocol that must be used by a valid URL.
- */
- public String getProtocol() {
- return protocol;
- }
-
- /**
- * Specifies the protocol that a URL must have to be valid.
- *
- * @param protocol the protocol that a URL must have to be valid.
- */
- public void setProtocol(String protocol) {
- this.protocol = protocol;
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli2/validation/Validator.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/cli2/validation/Validator.java b/src/java/org/apache/commons/cli2/validation/Validator.java
deleted file mode 100644
index 9d5778a..0000000
--- a/src/java/org/apache/commons/cli2/validation/Validator.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2003-2005 The Apache Software Foundation
- *
- * Licensed 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.validation;
-
-import java.util.List;
-
-/**
- * The validation interface for validating argument values(s).
- *
- * A validator can replace the argument string value with a
- * specific class instance e.g. the {@link UrlValidator} replaces
- * the string value with a {@link java.net.URL} instance.
- *
- * @author Rob Oxspring
- * @author John Keyes
- */
-public interface Validator {
-
- /**
- * Validate the specified values (List of Strings).
- *
- * @param values The values to validate.
- *
- * @throws InvalidArgumentException If any of the
- * specified values are not valid.
- */
- void validate(final List values) throws InvalidArgumentException;
-
-}
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/java/org/apache/commons/cli2/validation/package.html
----------------------------------------------------------------------
diff --git a/src/java/org/apache/commons/cli2/validation/package.html b/src/java/org/apache/commons/cli2/validation/package.html
deleted file mode 100644
index 63bc28b..0000000
--- a/src/java/org/apache/commons/cli2/validation/package.html
+++ /dev/null
@@ -1,16 +0,0 @@
-<html>
-<body>
-Provides classes and interfaces for validating argument values.
-
-These classes are capable of validating argument values of the following type:
-
-<ul>
- <li>file/directory</li>
- <li>number</li>
- <li>date/time</li>
- <li>URL</li>
- <li>enumeration</li>
- <li>class</li>
-</ul>
-</body>
-</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli/ApplicationTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/cli/ApplicationTest.java b/src/test/org/apache/commons/cli/ApplicationTest.java
deleted file mode 100644
index 99013b2..0000000
--- a/src/test/org/apache/commons/cli/ApplicationTest.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/**
- * Copyright 2001-2004 The Apache Software Foundation
- *
- * Licensed 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;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * <p>
- * This is a collection of tests that test real world
- * applications command lines.
- * </p>
- *
- * <p>
- * The following are the applications that are tested:
- * <ul>
- * <li>Ant</li>
- * </ul>
- * </p>
- *
- * @author John Keyes (john at integralsource.com)
- */
-public class ApplicationTest extends TestCase {
-
- public static Test suite() {
- return new TestSuite(ApplicationTest.class);
- }
-
- public ApplicationTest(String name)
- {
- super(name);
- }
-
- /**
- *
- */
- public void testLs() {
- // create the command line parser
- CommandLineParser parser = new PosixParser();
- Options options = new Options();
- options.addOption( "a", "all", false, "do not hide entries starting with ." );
- options.addOption( "A", "almost-all", false, "do not list implied . and .." );
- options.addOption( "b", "escape", false, "print octal escapes for nongraphic characters" );
- options.addOption( OptionBuilder.withLongOpt( "block-size" )
- .withDescription( "use SIZE-byte blocks" )
- .withValueSeparator( '=' )
- .hasArg()
- .create() );
- options.addOption( "B", "ignore-backups", false, "do not list implied entried ending with ~");
- options.addOption( "c", false, "with -lt: sort by, and show, ctime (time of last modification of file status information) with -l:show ctime and sort by name otherwise: sort by ctime" );
- options.addOption( "C", false, "list entries by columns" );
-
- String[] args = new String[]{ "--block-size=10" };
-
- try {
- CommandLine line = parser.parse( options, args );
- assertTrue( line.hasOption( "block-size" ) );
- assertEquals( line.getOptionValue( "block-size" ), "10" );
- }
- catch( ParseException exp ) {
- fail( "Unexpected exception:" + exp.getMessage() );
- }
- }
-
- /**
- * Ant test
- */
- public void testAnt() {
- // use the GNU parser
- CommandLineParser parser = new GnuParser( );
- Options options = new Options();
- options.addOption( "help", false, "print this message" );
- options.addOption( "projecthelp", false, "print project help information" );
- options.addOption( "version", false, "print the version information and exit" );
- options.addOption( "quiet", false, "be extra quiet" );
- options.addOption( "verbose", false, "be extra verbose" );
- options.addOption( "debug", false, "print debug information" );
- options.addOption( "version", false, "produce logging information without adornments" );
- options.addOption( "logfile", true, "use given file for log" );
- options.addOption( "logger", true, "the class which is to perform the logging" );
- options.addOption( "listener", true, "add an instance of a class as a project listener" );
- options.addOption( "buildfile", true, "use given buildfile" );
- options.addOption( OptionBuilder.withDescription( "use value for given property" )
- .hasArgs()
- .withValueSeparator()
- .create( 'D' ) );
- //, null, true, , false, true );
- options.addOption( "find", true, "search for buildfile towards the root of the filesystem and use it" );
-
- String[] args = new String[]{ "-buildfile", "mybuild.xml",
- "-Dproperty=value", "-Dproperty1=value1",
- "-projecthelp" };
-
- try {
- CommandLine line = parser.parse( options, args );
-
- // check multiple values
- String[] opts = line.getOptionValues( "D" );
- assertEquals( "property", opts[0] );
- assertEquals( "value", opts[1] );
- assertEquals( "property1", opts[2] );
- assertEquals( "value1", opts[3] );
-
- // check single value
- assertEquals( line.getOptionValue( "buildfile"), "mybuild.xml" );
-
- // check option
- assertTrue( line.hasOption( "projecthelp") );
- }
- catch( ParseException exp ) {
- fail( "Unexpected exception:" + exp.getMessage() );
- }
-
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli/ArgumentIsOptionTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/cli/ArgumentIsOptionTest.java b/src/test/org/apache/commons/cli/ArgumentIsOptionTest.java
deleted file mode 100644
index 58c4a6b..0000000
--- a/src/test/org/apache/commons/cli/ArgumentIsOptionTest.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * Copyright 2001-2004 The Apache Software Foundation
- *
- * Licensed 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;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-
-public class ArgumentIsOptionTest extends TestCase {
- private Options options = null;
- private CommandLineParser parser = null;
-
- public ArgumentIsOptionTest(String name) {
- super(name);
- }
-
- public static Test suite() {
- return new TestSuite(ArgumentIsOptionTest.class);
- }
-
- public void setUp() {
- options = new Options().addOption("p", false, "Option p").addOption("attr",
- true, "Option accepts argument");
-
- parser = new PosixParser();
- }
-
- public void tearDown() {
- }
-
- public void testOptionAndOptionWithArgument() {
- String[] args = new String[] {
- "-p",
- "-attr",
- "p"
- };
-
- try {
- CommandLine cl = parser.parse(options, args);
- assertTrue("Confirm -p is set", cl.hasOption("p"));
- assertTrue("Confirm -attr is set", cl.hasOption("attr"));
- assertTrue("Confirm arg of -attr",
- cl.getOptionValue("attr").equals("p"));
- assertTrue("Confirm all arguments recognized", cl.getArgs().length == 0);
- }
- catch (ParseException e) {
- fail(e.toString());
- }
- }
-
- public void testOptionWithArgument() {
- String[] args = new String[] {
- "-attr",
- "p"
- };
-
- try {
- CommandLine cl = parser.parse(options, args);
- assertFalse("Confirm -p is set", cl.hasOption("p"));
- assertTrue("Confirm -attr is set", cl.hasOption("attr"));
- assertTrue("Confirm arg of -attr",
- cl.getOptionValue("attr").equals("p"));
- assertTrue("Confirm all arguments recognized", cl.getArgs().length == 0);
- }
- catch (ParseException e) {
- fail(e.toString());
- }
- }
-
- public void testOption() {
- String[] args = new String[] {
- "-p"
- };
-
- try {
- CommandLine cl = parser.parse(options, args);
- assertTrue("Confirm -p is set", cl.hasOption("p"));
- assertFalse("Confirm -attr is not set", cl.hasOption("attr"));
- assertTrue("Confirm all arguments recognized", cl.getArgs().length == 0);
- }
- catch (ParseException e) {
- fail(e.toString());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli/BugsTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/cli/BugsTest.java b/src/test/org/apache/commons/cli/BugsTest.java
deleted file mode 100644
index 17f7ca0..0000000
--- a/src/test/org/apache/commons/cli/BugsTest.java
+++ /dev/null
@@ -1,536 +0,0 @@
-/**
- * Copyright 2001-2004 The Apache Software Foundation
- *
- * Licensed 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;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.Properties;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-public class BugsTest extends TestCase
-{
- /** CommandLine instance */
- private CommandLine _cmdline = null;
- private Option _option = null;
-
- public static Test suite() {
- return new TestSuite( BugsTest.class );
- }
-
- public BugsTest( String name )
- {
- super( name );
- }
-
- public void setUp()
- {
- }
-
- public void tearDown()
- {
- }
-
- public void test11457() {
- Options options = new Options();
- options.addOption( OptionBuilder.withLongOpt( "verbose" )
- .create() );
- String[] args = new String[] { "--verbose" };
-
- CommandLineParser parser = new PosixParser();
-
- try {
- CommandLine cmd = parser.parse( options, args );
- assertTrue( cmd.hasOption( "verbose" ) );
- }
- catch( ParseException exp ) {
- exp.printStackTrace();
- fail( "Unexpected Exception: " + exp.getMessage() );
- }
- }
-
- public void test11458()
- {
- Options options = new Options();
- options.addOption( OptionBuilder.withValueSeparator( '=' )
- .hasArgs()
- .create( 'D' ) );
- options.addOption( OptionBuilder.withValueSeparator( ':' )
- .hasArgs()
- .create( 'p' ) );
- String[] args = new String[] { "-DJAVA_HOME=/opt/java" ,
- "-pfile1:file2:file3" };
-
- CommandLineParser parser = new PosixParser();
-
- try {
- CommandLine cmd = parser.parse( options, args );
-
- String[] values = cmd.getOptionValues( 'D' );
-
- assertEquals( values[0], "JAVA_HOME" );
- assertEquals( values[1], "/opt/java" );
-
- values = cmd.getOptionValues( 'p' );
-
- assertEquals( values[0], "file1" );
- assertEquals( values[1], "file2" );
- assertEquals( values[2], "file3" );
-
- java.util.Iterator iter = cmd.iterator();
- while( iter.hasNext() ) {
- Option opt = (Option)iter.next();
- switch( opt.getId() ) {
- case 'D':
- assertEquals( opt.getValue( 0 ), "JAVA_HOME" );
- assertEquals( opt.getValue( 1 ), "/opt/java" );
- break;
- case 'p':
- assertEquals( opt.getValue( 0 ), "file1" );
- assertEquals( opt.getValue( 1 ), "file2" );
- assertEquals( opt.getValue( 2 ), "file3" );
- break;
- default:
- fail( "-D option not found" );
- }
- }
- }
- catch( ParseException exp ) {
- fail( "Unexpected Exception:\nMessage:" + exp.getMessage()
- + "Type: " + exp.getClass().getName() );
- }
- }
-
- public void test11680()
- {
- Options options = new Options();
- options.addOption("f", true, "foobar");
- options.addOption("m", true, "missing");
- String[] args = new String[] { "-f" , "foo" };
-
- CommandLineParser parser = new PosixParser();
-
- try {
- CommandLine cmd = parser.parse( options, args );
-
- try {
- cmd.getOptionValue( "f", "default f");
- cmd.getOptionValue( "m", "default m");
- }
- catch( NullPointerException exp ) {
- fail( "NullPointer caught: " + exp.getMessage() );
- }
- }
- catch( ParseException exp ) {
- fail( "Unexpected Exception: " + exp.getMessage() );
- }
- }
-
- public void test11456()
- {
- // Posix
- Options options = new Options();
- options.addOption( OptionBuilder.hasOptionalArg()
- .create( 'a' ) );
- options.addOption( OptionBuilder.hasArg()
- .create( 'b' ) );
- String[] args = new String[] { "-a", "-bvalue" };
-
- CommandLineParser parser = new PosixParser();
-
- try {
- CommandLine cmd = parser.parse( options, args );
- assertEquals( cmd.getOptionValue( 'b' ), "value" );
- }
- catch( ParseException exp ) {
- fail( "Unexpected Exception: " + exp.getMessage() );
- }
-
- // GNU
- options = new Options();
- options.addOption( OptionBuilder.hasOptionalArg()
- .create( 'a' ) );
- options.addOption( OptionBuilder.hasArg()
- .create( 'b' ) );
- args = new String[] { "-a", "-b", "value" };
-
- parser = new GnuParser();
-
- try {
- CommandLine cmd = parser.parse( options, args );
- assertEquals( cmd.getOptionValue( 'b' ), "value" );
- }
- catch( ParseException exp ) {
- fail( "Unexpected Exception: " + exp.getMessage() );
- }
-
- }
-
- public void test12210() {
- // create the main options object which will handle the first parameter
- Options mainOptions = new Options();
- // There can be 2 main exclusive options: -exec|-rep
-
- // Therefore, place them in an option group
-
- String[] argv = new String[] { "-exec", "-exec_opt1", "-exec_opt2" };
- OptionGroup grp = new OptionGroup();
-
- grp.addOption(new Option("exec",false,"description for this option"));
-
- grp.addOption(new Option("rep",false,"description for this option"));
-
- mainOptions.addOptionGroup(grp);
-
- // for the exec option, there are 2 options...
- Options execOptions = new Options();
- execOptions.addOption("exec_opt1",false," desc");
- execOptions.addOption("exec_opt2",false," desc");
-
- // similarly, for rep there are 2 options...
- Options repOptions = new Options();
- repOptions.addOption("repopto",false,"desc");
- repOptions.addOption("repoptt",false,"desc");
-
- // create the parser
- GnuParser parser = new GnuParser();
-
- // finally, parse the arguments:
-
- // first parse the main options to see what the user has specified
- // We set stopAtNonOption to true so it does not touch the remaining
- // options
- try {
- CommandLine cmd = parser.parse(mainOptions,argv,true);
- // get the remaining options...
- argv = cmd.getArgs();
-
- if(cmd.hasOption("exec")){
- cmd = parser.parse(execOptions,argv,false);
- // process the exec_op1 and exec_opt2...
- assertTrue( cmd.hasOption("exec_opt1") );
- assertTrue( cmd.hasOption("exec_opt2") );
- }
- else if(cmd.hasOption("rep")){
- cmd = parser.parse(repOptions,argv,false);
- // process the rep_op1 and rep_opt2...
- }
- else {
- fail( "exec option not found" );
- }
- }
- catch( ParseException exp ) {
- fail( "Unexpected exception: " + exp.getMessage() );
- }
- }
-
- public void test13425() {
- Options options = new Options();
- Option oldpass = OptionBuilder.withLongOpt( "old-password" )
- .withDescription( "Use this option to specify the old password" )
- .hasArg()
- .create( 'o' );
- Option newpass = OptionBuilder.withLongOpt( "new-password" )
- .withDescription( "Use this option to specify the new password" )
- .hasArg()
- .create( 'n' );
-
- String[] args = {
- "-o",
- "-n",
- "newpassword"
- };
-
- options.addOption( oldpass );
- options.addOption( newpass );
-
- Parser parser = new PosixParser();
-
- try {
- CommandLine line = parser.parse( options, args );
- }
- // catch the exception and leave the method
- catch( Exception exp ) {
- assertTrue( exp != null );
- return;
- }
- fail( "MissingArgumentException not caught." );
- }
-
- public void test13666() {
- Options options = new Options();
- Option dir = OptionBuilder.withDescription( "dir" )
- .hasArg()
- .create( 'd' );
- options.addOption( dir );
-
-
- final PrintStream oldSystemOut = System.out;
- try{
- final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
- final PrintStream print = new PrintStream(bytes);
-
- // capture this platform's eol symbol
- print.println();
- final String eol = bytes.toString();
- bytes.reset();
-
- System.setOut(new PrintStream(bytes));
- try {
- HelpFormatter formatter = new HelpFormatter();
- formatter.printHelp( "dir", options );
- }
- catch( Exception exp ) {
- fail( "Unexpected Exception: " + exp.getMessage() );
- }
- assertEquals("usage: dir"+eol+" -d <arg> dir"+eol,bytes.toString());
- }
- finally {
- System.setOut(oldSystemOut);
- }
- }
-
- public void test13935() {
- OptionGroup directions = new OptionGroup();
-
- Option left = new Option( "l", "left", false, "go left" );
- Option right = new Option( "r", "right", false, "go right" );
- Option straight = new Option( "s", "straight", false, "go straight" );
- Option forward = new Option( "f", "forward", false, "go forward" );
- forward.setRequired( true );
-
- directions.addOption( left );
- directions.addOption( right );
- directions.setRequired( true );
-
- Options opts = new Options();
- opts.addOptionGroup( directions );
- opts.addOption( straight );
-
- CommandLineParser parser = new PosixParser();
- boolean exception = false;
-
- String[] args = new String[] { };
- try {
- CommandLine line = parser.parse( opts, args );
- }
- catch( ParseException exp ) {
- exception = true;
- }
-
- if( !exception ) {
- fail( "Expected exception not caught.");
- }
-
- exception = false;
-
- args = new String[] { "-s" };
- try {
- CommandLine line = parser.parse( opts, args );
- }
- catch( ParseException exp ) {
- exception = true;
- }
-
- if( !exception ) {
- fail( "Expected exception not caught.");
- }
-
- exception = false;
-
- args = new String[] { "-s", "-l" };
- try {
- CommandLine line = parser.parse( opts, args );
- }
- catch( ParseException exp ) {
- fail( "Unexpected exception: " + exp.getClass().getName() + ":" + exp.getMessage() );
- }
-
- opts.addOption( forward );
- args = new String[] { "-s", "-l", "-f" };
- try {
- CommandLine line = parser.parse( opts, args );
- }
- catch( ParseException exp ) {
- fail( "Unexpected exception: " + exp.getClass().getName() + ":" + exp.getMessage() );
- }
- }
-
- public void test14786() throws Exception {
- Option o = OptionBuilder.isRequired().withDescription("test").create("test");
- Options opts = new Options();
- opts.addOption(o);
- opts.addOption(o);
-
- CommandLineParser parser = new GnuParser();
-
- String[] args = new String[] { "-test" };
-
- CommandLine line = parser.parse( opts, args );
- assertTrue( line.hasOption( "test" ) );
- }
-
- public void test15046() throws Exception {
- CommandLineParser parser = new PosixParser();
- final String[] CLI_ARGS = new String[] {"-z", "c"};
- Option option = new Option("z", "timezone", true,
- "affected option");
- Options cliOptions = new Options();
- cliOptions.addOption(option);
- parser.parse(cliOptions, CLI_ARGS);
-
- //now add conflicting option
- cliOptions.addOption("c", "conflict", true, "conflict option");
- CommandLine line = parser.parse(cliOptions, CLI_ARGS);
- assertEquals( option.getValue(), "c" );
- assertTrue( !line.hasOption("c") );
- }
-
- public void test15648() throws Exception {
- CommandLineParser parser = new PosixParser();
- final String[] args = new String[] { "-m", "\"Two Words\"" };
- Option m = OptionBuilder.hasArgs().create("m");
- Options options = new Options();
- options.addOption( m );
- CommandLine line = parser.parse( options, args );
- assertEquals( "Two Words", line.getOptionValue( "m" ) );
- }
-
- public void test27635() {
- Option help = new Option("h", "help", false, "print this message");
- Option version = new Option("v", "version", false, "print version information");
- Option newRun = new Option("n", "new", false, "Create NLT cache entries only for new items");
- Option trackerRun = new Option("t", "tracker", false, "Create NLT cache entries only for tracker items");
-
- Option timeLimit = OptionBuilder.withLongOpt("limit")
- .hasArg()
- .withValueSeparator()
- .withDescription("Set time limit for execution, in mintues")
- .create("l");
-
- Option age = OptionBuilder.withLongOpt("age")
- .hasArg()
- .withValueSeparator()
- .withDescription("Age (in days) of cache item before being recomputed")
- .create("a");
-
- Option server = OptionBuilder.withLongOpt("server")
- .hasArg()
- .withValueSeparator()
- .withDescription("The NLT server address")
- .create("s");
-
- Option numResults = OptionBuilder.withLongOpt("results")
- .hasArg()
- .withValueSeparator()
- .withDescription("Number of results per item")
- .create("r");
-
- Option configFile = OptionBuilder.withLongOpt("config")
- .hasArg()
- .withValueSeparator()
- .withDescription("Use the specified configuration file")
- .create();
-
- Options mOptions = new Options();
- mOptions.addOption(help);
- mOptions.addOption(version);
- mOptions.addOption(newRun);
- mOptions.addOption(trackerRun);
- mOptions.addOption(timeLimit);
- mOptions.addOption(age);
- mOptions.addOption(server);
- mOptions.addOption(numResults);
- mOptions.addOption(configFile);
-
- HelpFormatter formatter = new HelpFormatter();
- final String EOL = System.getProperty("line.separator");
- StringWriter out = new StringWriter();
- formatter.printHelp(new PrintWriter(out),80,"commandline","header",mOptions,2,2,"footer",true);
- assertEquals(
- "usage: commandline [--config <arg>] [-r <arg>] [-a <arg>] [-h] [-t] [-n] [-l"+EOL+
- " <arg>] [-s <arg>] [-v]"+EOL+
- "header"+EOL+
- " -a,--age <arg> Age (in days) of cache item before being recomputed"+EOL+
- " --config <arg> Use the specified configuration file"+EOL+
- " -h,--help print this message"+EOL+
- " -l,--limit <arg> Set time limit for execution, in mintues"+EOL+
- " -n,--new Create NLT cache entries only for new items"+EOL+
- " -r,--results <arg> Number of results per item"+EOL+
- " -s,--server <arg> The NLT server address"+EOL+
- " -t,--tracker Create NLT cache entries only for tracker items"+EOL+
- " -v,--version print version information"+EOL+
- "footer"+EOL
- ,out.toString());
- }
-
- public void test31148() throws ParseException {
- Option multiArgOption = new Option("o","option with multiple args");
- multiArgOption.setArgs(1);
-
- Options options = new Options();
- options.addOption(multiArgOption);
-
- Parser parser = new PosixParser();
- String[] args = new String[]{};
- Properties props = new Properties();
- props.setProperty("o","ovalue");
- CommandLine cl = parser.parse(options,args,props);
-
- assertTrue(cl.hasOption('o'));
- assertEquals("ovalue",cl.getOptionValue('o'));
- }
-
- public void test21215() {
- Options options = new Options();
- HelpFormatter formatter = new HelpFormatter();
- String SEP = System.getProperty("line.separator");
- String header = SEP+"Header";
- String footer = "Footer";
- StringWriter out = new StringWriter();
- formatter.printHelp(new PrintWriter(out),80, "foobar", header, options, 2, 2, footer, true);
- assertEquals(
- "usage: foobar"+SEP+
- ""+SEP+
- "Header"+SEP+
- ""+SEP+
- "Footer"+SEP
- ,out.toString());
- }
-
- public void test19383() {
- Options options = new Options();
- options.addOption(new Option("a","aaa",false,"aaaaaaa"));
- options.addOption(new Option(null,"bbb",false,"bbbbbbb"));
- options.addOption(new Option("c",null,false,"ccccccc"));
-
- HelpFormatter formatter = new HelpFormatter();
- String SEP = System.getProperty("line.separator");
- StringWriter out = new StringWriter();
- formatter.printHelp(new PrintWriter(out),80, "foobar", "", options, 2, 2, "", true);
- assertEquals(
- "usage: foobar [-a] [-c] [--bbb]"+SEP+
- " -a,--aaa aaaaaaa"+SEP+
- " --bbb bbbbbbb"+SEP+
- " -c ccccccc"+SEP
- ,out.toString());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli/BuildTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/cli/BuildTest.java b/src/test/org/apache/commons/cli/BuildTest.java
deleted file mode 100644
index 7e72897..0000000
--- a/src/test/org/apache/commons/cli/BuildTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/**
- * Copyright 2001-2004 The Apache Software Foundation
- *
- * Licensed 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;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-public class BuildTest extends TestCase
-{
-
- public static Test suite() {
- return new TestSuite(BuildTest.class);
- }
-
- public BuildTest(String name)
- {
- super(name);
- }
-
- public void setUp()
- {
-
- }
-
- public void tearDown()
- {
-
- }
-
- public void testSimple()
- {
- Options opts = new Options();
-
- opts.addOption("a",
- false,
- "toggle -a");
-
- opts.addOption("b",
- true,
- "toggle -b");
- }
-
- public void testDuplicateSimple()
- {
- Options opts = new Options();
- opts.addOption("a",
- false,
- "toggle -a");
-
- opts.addOption("a",
- true,
- "toggle -a*");
-
- assertEquals( "last one in wins", "toggle -a*", opts.getOption("a").getDescription() );
- }
-
- public void testLong()
- {
- Options opts = new Options();
-
- opts.addOption("a",
- "--a",
- false,
- "toggle -a");
-
- opts.addOption("b",
- "--b",
- true,
- "set -b");
-
- }
-
- public void testDuplicateLong()
- {
- Options opts = new Options();
- opts.addOption("a",
- "--a",
- false,
- "toggle -a");
-
- opts.addOption("a",
- "--a",
- false,
- "toggle -a*");
- assertEquals( "last one in wins", "toggle -a*", opts.getOption("a").getDescription() );
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli/CLI2ConverterTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/cli/CLI2ConverterTest.java b/src/test/org/apache/commons/cli/CLI2ConverterTest.java
deleted file mode 100644
index 038023f..0000000
--- a/src/test/org/apache/commons/cli/CLI2ConverterTest.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/**
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed 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;
-
-import org.apache.commons.cli2.Group;
-import org.apache.commons.cli2.builder.PatternBuilder;
-import org.apache.commons.cli2.option.GroupImpl;
-
-import junit.framework.TestCase;
-
-public class CLI2ConverterTest extends TestCase {
-
- private Options aceOptions;
- private OptionGroup aceOptionGroup;
- private Options abcdeOptions;
- private Options pattern;
-
- private Option a;
- private Option bbb;
- private Option c;
- private Option ddd;
- private Option e;
- private Option f;
- private Option g;
- private Option h;
- private Option i;
-
- public void setUp(){
- a = OptionBuilder.withDescription("A description").create('a');
- bbb = OptionBuilder.create("bbb");
- c = OptionBuilder.withLongOpt("ccc").create('c');
- ddd = OptionBuilder.withLongOpt("ddd").create();
- e = OptionBuilder.isRequired(true).create("e");
- f = OptionBuilder.hasArg().withArgName("argument").create('f');
- g = OptionBuilder.hasArgs(5).create('g');
- h = OptionBuilder.hasOptionalArg().create('h');
- i = OptionBuilder.hasOptionalArgs(5).create('i');
-
- aceOptions = new Options();
- aceOptions.addOption(OptionBuilder.create('a'));
- aceOptions.addOption(OptionBuilder.create('c'));
- aceOptions.addOption(OptionBuilder.create('e'));
-
- aceOptionGroup = new OptionGroup();
- aceOptionGroup.addOption(OptionBuilder.create('a'));
- aceOptionGroup.addOption(OptionBuilder.create('c'));
- aceOptionGroup.addOption(OptionBuilder.create('e'));
-
- abcdeOptions = new Options();
- abcdeOptions.addOption(OptionBuilder.create('d'));
- OptionGroup og = new OptionGroup();
- og.addOption(OptionBuilder.create('a'));
- og.addOption(OptionBuilder.create('c'));
- og.addOption(OptionBuilder.create('e'));
- abcdeOptions.addOptionGroup(og);
- abcdeOptions.addOption(OptionBuilder.create('b'));
-
- pattern = PatternOptionBuilder.parsePattern("a%ce:");
- }
-
- /*
- * Class to test for Option option(Option)
- */
- public void testOption() {
- assertTrue(e.isRequired());
-
- assertEquals("A description",a.getDescription());
- assertEquals('a',a.getId());
- assertEquals("[-a]",CLI2Converter.option(a).toString());
- assertEquals("[-bbb]",CLI2Converter.option(bbb).toString());
- assertEquals("[-c (--ccc)]",CLI2Converter.option(c).toString());
- assertEquals("[--ddd]",CLI2Converter.option(ddd).toString());
- assertEquals("-e",CLI2Converter.option(e).toString());
- assertEquals("[-f <argument>]",CLI2Converter.option(f).toString());
- assertEquals("[-g <arg1> <arg2> <arg3> <arg4> <arg5>]",CLI2Converter.option(g).toString());
- assertEquals("[-h [<arg>]]",CLI2Converter.option(h).toString());
- assertEquals("[-i [<arg1> [<arg2> [<arg3> [<arg4> [<arg5>]]]]]]",CLI2Converter.option(i).toString());
- }
- /*
- * Class to test for Group group(OptionGroup)
- */
- public void testGroupOptionGroup() {
- GroupImpl group;
-
- group = (GroupImpl)CLI2Converter.group(aceOptionGroup);
- assertEquals("[-a|-c|-e]",group.toString());
- assertEquals(0,group.getMinimum());
- assertEquals(1,group.getMaximum());
-
- aceOptionGroup.setRequired(true);
- group = (GroupImpl)CLI2Converter.group(aceOptionGroup);
- assertEquals("-a|-c|-e",group.toString());
- assertEquals(1,group.getMinimum());
- assertEquals(1,group.getMaximum());
- }
- /*
- * Class to test for Group group(Options)
- */
- public void testGroupOptions() {
-
- GroupImpl group;
-
- group = (GroupImpl)CLI2Converter.group(aceOptions);
- assertEquals("[-a|-c|-e]",group.toString());
- assertEquals(0,group.getMinimum());
- assertEquals(Integer.MAX_VALUE,group.getMaximum());
-
- group = (GroupImpl)CLI2Converter.group(abcdeOptions);
-
- assertEquals("[-a|-c|-e|-d|-b]",group.toString());
- assertEquals(0,group.getMinimum());
- assertEquals(Integer.MAX_VALUE,group.getMaximum());
-
- group = (GroupImpl)CLI2Converter.group(pattern);
- assertEquals("[-a <arg>|-c|-e <arg>]",group.toString());
- assertEquals(0,group.getMinimum());
- assertEquals(Integer.MAX_VALUE,group.getMaximum());
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli/GnuParseTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/cli/GnuParseTest.java b/src/test/org/apache/commons/cli/GnuParseTest.java
deleted file mode 100644
index 3a460d1..0000000
--- a/src/test/org/apache/commons/cli/GnuParseTest.java
+++ /dev/null
@@ -1,269 +0,0 @@
-/**
- * Copyright 2001-2004 The Apache Software Foundation
- *
- * Licensed 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;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-public class GnuParseTest extends TestCase
-{
- private Options _options = null;
- private CommandLineParser _parser = null;
-
- public static Test suite() {
- return new TestSuite( GnuParseTest.class );
- }
-
- public GnuParseTest( String name )
- {
- super( name );
- }
-
- public void setUp()
- {
- _options = new Options()
- .addOption("a",
- "enable-a",
- false,
- "turn [a] on or off")
- .addOption("b",
- "bfile",
- true,
- "set the value of [b]")
- .addOption("c",
- "copt",
- false,
- "turn [c] on or off");
-
- _parser = new GnuParser( );
- }
-
- public void tearDown()
- {
-
- }
-
- public void testSimpleShort()
- {
- String[] args = new String[] { "-a",
- "-b", "toast",
- "foo", "bar" };
-
- try
- {
- CommandLine cl = _parser.parse(_options, args);
-
- assertTrue( "Confirm -a is set", cl.hasOption("a") );
- assertTrue( "Confirm -b is set", cl.hasOption("b") );
- assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
- assertTrue( "Confirm size of extra args", cl.getArgList().size() == 2);
- }
- catch (ParseException e)
- {
- fail( e.toString() );
- }
- }
-
- public void testSimpleLong()
- {
- String[] args = new String[] { "--enable-a",
- "--bfile", "toast",
- "foo", "bar" };
-
- try
- {
- CommandLine cl = _parser.parse(_options, args);
-
- assertTrue( "Confirm -a is set", cl.hasOption("a") );
- assertTrue( "Confirm -b is set", cl.hasOption("b") );
- assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
- assertTrue( "Confirm size of extra args", cl.getArgList().size() == 2);
- }
- catch (ParseException e)
- {
- fail( e.toString() );
- }
- }
-
- public void testExtraOption()
- {
- String[] args = new String[] { "-a", "-d", "-b", "toast",
- "foo", "bar" };
-
- boolean caught = false;
-
- try
- {
- CommandLine cl = _parser.parse(_options, args);
-
- assertTrue( "Confirm -a is set", cl.hasOption("a") );
- assertTrue( "Confirm -b is set", cl.hasOption("b") );
- assertTrue( "confirm arg of -b", cl.getOptionValue("b").equals("toast") );
- assertTrue( "Confirm size of extra args", cl.getArgList().size() == 3);
- }
- catch (UnrecognizedOptionException e)
- {
- caught = true;
- }
- catch (ParseException e)
- {
- fail( e.toString() );
- }
- assertTrue( "Confirm UnrecognizedOptionException caught", caught );
- }
-
- public void testMissingArg()
- {
-
- String[] args = new String[] { "-b" };
-
- boolean caught = false;
-
- try
- {
- CommandLine cl = _parser.parse(_options, args);
- }
- catch (MissingArgumentException e)
- {
- caught = true;
- }
- catch (ParseException e)
- {
- fail( e.toString() );
- }
-
- assertTrue( "Confirm MissingArgumentException caught", caught );
- }
-
- public void testStop()
- {
- String[] args = new String[] { "-c",
- "foober",
- "-b",
- "toast" };
-
- try
- {
- CommandLine cl = _parser.parse(_options, args, true);
- assertTrue( "Confirm -c is set", cl.hasOption("c") );
- assertTrue( "Confirm 3 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 3);
- }
- catch (ParseException e)
- {
- fail( e.toString() );
- }
- }
-
- public void testMultiple()
- {
- String[] args = new String[] { "-c",
- "foobar",
- "-b",
- "toast" };
-
- try
- {
- CommandLine cl = _parser.parse(_options, args, true);
- assertTrue( "Confirm -c is set", cl.hasOption("c") );
- assertTrue( "Confirm 3 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 3);
-
- cl = _parser.parse(_options, cl.getArgs() );
-
- assertTrue( "Confirm -c is not set", ! cl.hasOption("c") );
- assertTrue( "Confirm -b is set", cl.hasOption("b") );
- assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
- assertTrue( "Confirm 1 extra arg: " + cl.getArgList().size(), cl.getArgList().size() == 1);
- assertTrue( "Confirm value of extra arg: " + cl.getArgList().get(0), cl.getArgList().get(0).equals("foobar") );
- }
- catch (ParseException e)
- {
- fail( e.toString() );
- }
- }
-
- public void testMultipleWithLong()
- {
- String[] args = new String[] { "--copt",
- "foobar",
- "--bfile", "toast" };
-
- try
- {
- CommandLine cl = _parser.parse(_options,args,
- true);
- assertTrue( "Confirm -c is set", cl.hasOption("c") );
- assertTrue( "Confirm 3 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 3);
-
- cl = _parser.parse(_options, cl.getArgs() );
-
- assertTrue( "Confirm -c is not set", ! cl.hasOption("c") );
- assertTrue( "Confirm -b is set", cl.hasOption("b") );
- assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("toast") );
- assertTrue( "Confirm 1 extra arg: " + cl.getArgList().size(), cl.getArgList().size() == 1);
- assertTrue( "Confirm value of extra arg: " + cl.getArgList().get(0), cl.getArgList().get(0).equals("foobar") );
- }
- catch (ParseException e)
- {
- fail( e.toString() );
- }
- }
-
- public void testDoubleDash()
- {
- String[] args = new String[] { "--copt",
- "--",
- "-b", "toast" };
-
- try
- {
- CommandLine cl = _parser.parse(_options, args);
-
- assertTrue( "Confirm -c is set", cl.hasOption("c") );
- assertTrue( "Confirm -b is not set", ! cl.hasOption("b") );
- assertTrue( "Confirm 2 extra args: " + cl.getArgList().size(), cl.getArgList().size() == 2);
-
- }
- catch (ParseException e)
- {
- fail( e.toString() );
- }
- }
-
- public void testSingleDash()
- {
- String[] args = new String[] { "--copt",
- "-b", "-",
- "-a",
- "-" };
-
- try
- {
- CommandLine cl = _parser.parse(_options, args);
-
- assertTrue( "Confirm -a is set", cl.hasOption("a") );
- assertTrue( "Confirm -b is set", cl.hasOption("b") );
- assertTrue( "Confirm arg of -b", cl.getOptionValue("b").equals("-") );
- assertTrue( "Confirm 1 extra arg: " + cl.getArgList().size(), cl.getArgList().size() == 1);
- assertTrue( "Confirm value of extra arg: " + cl.getArgList().get(0), cl.getArgList().get(0).equals("-") );
- }
- catch (ParseException e)
- {
- fail( e.toString() );
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli/HelpFormatterExamples.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/cli/HelpFormatterExamples.java b/src/test/org/apache/commons/cli/HelpFormatterExamples.java
deleted file mode 100644
index 722e474..0000000
--- a/src/test/org/apache/commons/cli/HelpFormatterExamples.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/**
- * Copyright 2001-2004 The Apache Software Foundation
- *
- * Licensed 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;
-
-/**
- * A sample program shpwing the use of Options and the HelpFormatter class
- *
- * @author Slawek Zachcial
- **/
-public class HelpFormatterExamples
-{
- // --------------------------------------------------------------- Constants
-
- // ------------------------------------------------------------------ Static
-
- public static void main( String[] args )
- {
- System.out.println("\n#\n# 'man' example\n#");
- manExample();
-/*
- System.out.println("\n#\n# 'bzip2' example\n#");
- bzip2Example();
- System.out.println("\n#\n# 'ls' example\n#");
- lsExample();
-*/
- }
-
- static void manExample()
- {
- String cmdLine =
- "man [-c|-f|-k|-w|-tZT device] [-adlhu7V] [-Mpath] [-Ppager] [-Slist] " +
- "[-msystem] [-pstring] [-Llocale] [-eextension] [section] page ...";
- Options opts =
- new Options().
- addOption("a", "all", false, "find all matching manual pages.").
- addOption("d", "debug", false, "emit debugging messages.").
- addOption("e", "extension", false, "limit search to extension type 'extension'.").
- addOption("f", "whatis", false, "equivalent to whatis.").
- addOption("k", "apropos", false, "equivalent to apropos.").
- addOption("w", "location", false, "print physical location of man page(s).").
- addOption("l", "local-file", false, "interpret 'page' argument(s) as local filename(s)").
- addOption("u", "update", false, "force a cache consistency check.").
- //FIXME - should generate -r,--prompt string
- addOption("r", "prompt", true, "provide 'less' pager with prompt.").
- addOption("c", "catman", false, "used by catman to reformat out of date cat pages.").
- addOption("7", "ascii", false, "display ASCII translation or certain latin1 chars.").
- addOption("t", "troff", false, "use troff format pages.").
- //FIXME - should generate -T,--troff-device device
- addOption("T", "troff-device", true, "use groff with selected device.").
- addOption("Z", "ditroff", false, "use groff with selected device.").
- addOption("D", "default", false, "reset all options to their default values.").
- //FIXME - should generate -M,--manpath path
- addOption("M", "manpath", true, "set search path for manual pages to 'path'.").
- //FIXME - should generate -P,--pager pager
- addOption("P", "pager", true, "use program 'pager' to display output.").
- //FIXME - should generate -S,--sections list
- addOption("S", "sections", true, "use colon separated section list.").
- //FIXME - should generate -m,--systems system
- addOption("m", "systems", true, "search for man pages from other unix system(s).").
- //FIXME - should generate -L,--locale locale
- addOption("L", "locale", true, "defaine the locale for this particular man search.").
- //FIXME - should generate -p,--preprocessor string
- addOption("p", "preprocessor", true, "string indicates which preprocessor to run.\n" +
- " e - [n]eqn p - pic t - tbl\n" +
- " g - grap r - refer v - vgrind").
- addOption("V", "version", false, "show version.").
- addOption("h", "help", false, "show this usage message.");
-
- HelpFormatter hf = new HelpFormatter();
- //hf.printHelp(cmdLine, opts);
- hf.printHelp(60, cmdLine, null, opts, null);
- }
-
- static void bzip2Example()
- {
- System.out.println( "Coming soon" );
- }
-
- static void lsExample()
- {
- System.out.println( "Coming soon" );
- }
-
-
- // -------------------------------------------------------------- Attributes
-
- // ------------------------------------------------------------ Constructors
-
- // ------------------------------------------------------------------ Public
-
- // --------------------------------------------------------------- Protected
-
- // ------------------------------------------------------- Package protected
-
- // ----------------------------------------------------------------- Private
-
- // ----------------------------------------------------------- Inner classes
-
-}
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli/LongOptionWithShort.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/cli/LongOptionWithShort.java b/src/test/org/apache/commons/cli/LongOptionWithShort.java
deleted file mode 100644
index c947f4b..0000000
--- a/src/test/org/apache/commons/cli/LongOptionWithShort.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/**
- * Copyright 2001-2004 The Apache Software Foundation
- *
- * Licensed 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;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-
-/**
- * <p>
- * This is a collection of tests that test real world
- * applications command lines focusing on options with
- * long and short names.
- * </p>
- */
-public class LongOptionWithShort extends TestCase {
- public LongOptionWithShort(String name) {
- super(name);
- }
-
- public static Test suite() {
- return new TestSuite(LongOptionWithShort.class);
- }
-
- /**
- *
- */
- public void testLongOptionWithShort() {
- Option help = new Option("h", "help", false, "print this message");
- Option version = new Option("v", "version", false,
- "print version information");
- Option newRun = new Option("n", "new", false,
- "Create NLT cache entries only for new items");
- Option trackerRun = new Option("t", "tracker", false,
- "Create NLT cache entries only for tracker items");
-
- Option timeLimit = OptionBuilder.withLongOpt("limit").hasArg()
- .withValueSeparator()
- .withDescription("Set time limit for execution, in mintues")
- .create("l");
-
- Option age = OptionBuilder.withLongOpt("age").hasArg()
- .withValueSeparator()
- .withDescription("Age (in days) of cache item before being recomputed")
- .create("a");
-
- Option server = OptionBuilder.withLongOpt("server").hasArg()
- .withValueSeparator()
- .withDescription("The NLT server address")
- .create("s");
-
- Option numResults = OptionBuilder.withLongOpt("results").hasArg()
- .withValueSeparator()
- .withDescription("Number of results per item")
- .create("r");
-
- Option configFile = OptionBuilder.withLongOpt("file").hasArg()
- .withValueSeparator()
- .withDescription("Use the specified configuration file")
- .create();
-
- Options options = new Options();
- options.addOption(help);
- options.addOption(version);
- options.addOption(newRun);
- options.addOption(trackerRun);
- options.addOption(timeLimit);
- options.addOption(age);
- options.addOption(server);
- options.addOption(numResults);
- options.addOption(configFile);
-
- // create the command line parser
- CommandLineParser parser = new PosixParser();
-
- String[] args = new String[] {
- "-v",
- "-l",
- "10",
- "-age",
- "5",
- "-file",
- "filename"
- };
-
- try {
- CommandLine line = parser.parse(options, args);
- assertTrue(line.hasOption("v"));
- assertEquals(line.getOptionValue("l"), "10");
- assertEquals(line.getOptionValue("limit"), "10");
- assertEquals(line.getOptionValue("a"), "5");
- assertEquals(line.getOptionValue("age"), "5");
- assertEquals(line.getOptionValue("file"), "filename");
- }
- catch (ParseException exp) {
- fail("Unexpected exception:" + exp.getMessage());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli/OptionBuilderTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/cli/OptionBuilderTest.java b/src/test/org/apache/commons/cli/OptionBuilderTest.java
deleted file mode 100644
index e1f3083..0000000
--- a/src/test/org/apache/commons/cli/OptionBuilderTest.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/**
- * Copyright 2001-2004 The Apache Software Foundation
- *
- * Licensed 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;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import junit.textui.TestRunner;
-
-public class OptionBuilderTest extends TestCase {
-
- public OptionBuilderTest( String name ) {
- super( name );
- }
-
- public static Test suite() {
- return new TestSuite( OptionBuilderTest.class );
- }
-
- public static void main( String args[] ) {
- TestRunner.run( suite() );
- }
-
- public void testCompleteOption( ) {
- Option simple = OptionBuilder.withLongOpt( "simple option")
- .hasArg( )
- .isRequired( )
- .hasArgs( )
- .withType( new Float( 10 ) )
- .withDescription( "this is a simple option" )
- .create( 's' );
-
- assertEquals( "s", simple.getOpt() );
- assertEquals( "simple option", simple.getLongOpt() );
- assertEquals( "this is a simple option", simple.getDescription() );
- assertEquals( simple.getType().getClass(), Float.class );
- assertTrue( simple.hasArg() );
- assertTrue( simple.isRequired() );
- assertTrue( simple.hasArgs() );
- }
-
- public void testTwoCompleteOptions( ) {
- Option simple = OptionBuilder.withLongOpt( "simple option")
- .hasArg( )
- .isRequired( )
- .hasArgs( )
- .withType( new Float( 10 ) )
- .withDescription( "this is a simple option" )
- .create( 's' );
-
- assertEquals( "s", simple.getOpt() );
- assertEquals( "simple option", simple.getLongOpt() );
- assertEquals( "this is a simple option", simple.getDescription() );
- assertEquals( simple.getType().getClass(), Float.class );
- assertTrue( simple.hasArg() );
- assertTrue( simple.isRequired() );
- assertTrue( simple.hasArgs() );
-
- simple = OptionBuilder.withLongOpt( "dimple option")
- .hasArg( )
- .withDescription( "this is a dimple option" )
- .create( 'd' );
-
- assertEquals( "d", simple.getOpt() );
- assertEquals( "dimple option", simple.getLongOpt() );
- assertEquals( "this is a dimple option", simple.getDescription() );
- assertNull( simple.getType() );
- assertTrue( simple.hasArg() );
- assertTrue( !simple.isRequired() );
- assertTrue( !simple.hasArgs() );
- }
-
- public void testBaseOptionCharOpt() {
- Option base = OptionBuilder.withDescription( "option description")
- .create( 'o' );
-
- assertEquals( "o", base.getOpt() );
- assertEquals( "option description", base.getDescription() );
- assertTrue( !base.hasArg() );
- }
-
- public void testBaseOptionStringOpt() {
- Option base = OptionBuilder.withDescription( "option description")
- .create( "o" );
-
- assertEquals( "o", base.getOpt() );
- assertEquals( "option description", base.getDescription() );
- assertTrue( !base.hasArg() );
- }
-
- public void testSpecialOptChars() {
-
- // '?'
- try {
- Option opt = OptionBuilder.withDescription( "help options" )
- .create( '?' );
- assertEquals( "?", opt.getOpt() );
- }
- catch( IllegalArgumentException arg ) {
- fail( "IllegalArgumentException caught" );
- }
-
- // '@'
- try {
- Option opt = OptionBuilder.withDescription( "read from stdin" )
- .create( '@' );
- assertEquals( "@", opt.getOpt() );
- }
- catch( IllegalArgumentException arg ) {
- fail( "IllegalArgumentException caught" );
- }
- }
-
- public void testOptionArgNumbers() {
- Option opt = OptionBuilder.withDescription( "option description" )
- .hasArgs( 2 )
- .create( 'o' );
- assertEquals( 2, opt.getArgs() );
- }
-
- public void testIllegalOptions() {
- // bad single character option
- try {
- Option opt = OptionBuilder.withDescription( "option description" )
- .create( '"' );
- fail( "IllegalArgumentException not caught" );
- }
- catch( IllegalArgumentException exp ) {
- // success
- }
-
- // bad character in option string
- try {
- Option opt = OptionBuilder.create( "opt`" );
- fail( "IllegalArgumentException not caught" );
- }
- catch( IllegalArgumentException exp ) {
- // success
- }
-
- // valid option
- try {
- Option opt = OptionBuilder.create( "opt" );
- // success
- }
- catch( IllegalArgumentException exp ) {
- fail( "IllegalArgumentException caught" );
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli/OptionGroupTest.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/cli/OptionGroupTest.java b/src/test/org/apache/commons/cli/OptionGroupTest.java
deleted file mode 100644
index 8d66b1d..0000000
--- a/src/test/org/apache/commons/cli/OptionGroupTest.java
+++ /dev/null
@@ -1,280 +0,0 @@
-/**
- * Copyright 2001-2004 The Apache Software Foundation
- *
- * Licensed 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;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * @author John Keyes (john at integralsource.com)
- * @version $Revision$
- */
-public class OptionGroupTest extends TestCase
-{
-
- private Options _options = null;
- private CommandLineParser parser = new PosixParser();
-
-
- public static Test suite()
- {
- return new TestSuite ( OptionGroupTest.class );
- }
-
- public OptionGroupTest( String name )
- {
- super( name );
- }
-
- public void setUp()
- {
- Option file = new Option( "f", "file", false, "file to process" );
- Option dir = new Option( "d", "directory", false, "directory to process" );
- OptionGroup group = new OptionGroup();
- group.addOption( file );
- group.addOption( dir );
- _options = new Options().addOptionGroup( group );
-
- Option section = new Option( "s", "section", false, "section to process" );
- Option chapter = new Option( "c", "chapter", false, "chapter to process" );
- OptionGroup group2 = new OptionGroup();
- group2.addOption( section );
- group2.addOption( chapter );
-
- _options.addOptionGroup( group2 );
-
- Option importOpt = new Option( null, "import", false, "section to process" );
- Option exportOpt = new Option( null, "export", false, "chapter to process" );
- OptionGroup group3 = new OptionGroup();
- group3.addOption( importOpt );
- group3.addOption( exportOpt );
- _options.addOptionGroup( group3 );
-
- _options.addOption( "r", "revision", false, "revision number" );
- }
-
- public void tearDown()
- {
- }
-
- public void testSingleOptionFromGroup()
- {
- String[] args = new String[] { "-f" };
-
- try
- {
- CommandLine cl = parser.parse( _options, args);
-
- assertTrue( "Confirm -r is NOT set", !cl.hasOption("r") );
- assertTrue( "Confirm -f is set", cl.hasOption("f") );
- assertTrue( "Confirm -d is NOT set", !cl.hasOption("d") );
- assertTrue( "Confirm -s is NOT set", !cl.hasOption("s") );
- assertTrue( "Confirm -c is NOT set", !cl.hasOption("c") );
- assertTrue( "Confirm no extra args", cl.getArgList().size() == 0);
- }
- catch (ParseException e)
- {
- fail( e.toString() );
- }
- }
-
- public void testSingleOption()
- {
- String[] args = new String[] { "-r" };
-
- try
- {
- CommandLine cl = parser.parse( _options, args);
-
- assertTrue( "Confirm -r is set", cl.hasOption("r") );
- assertTrue( "Confirm -f is NOT set", !cl.hasOption("f") );
- assertTrue( "Confirm -d is NOT set", !cl.hasOption("d") );
- assertTrue( "Confirm -s is NOT set", !cl.hasOption("s") );
- assertTrue( "Confirm -c is NOT set", !cl.hasOption("c") );
- assertTrue( "Confirm no extra args", cl.getArgList().size() == 0);
- }
- catch (ParseException e)
- {
- fail( e.toString() );
- }
- }
-
- public void testTwoValidOptions()
- {
- String[] args = new String[] { "-r", "-f" };
-
- try
- {
- CommandLine cl = parser.parse( _options, args);
-
- assertTrue( "Confirm -r is set", cl.hasOption("r") );
- assertTrue( "Confirm -f is set", cl.hasOption("f") );
- assertTrue( "Confirm -d is NOT set", !cl.hasOption("d") );
- assertTrue( "Confirm -s is NOT set", !cl.hasOption("s") );
- assertTrue( "Confirm -c is NOT set", !cl.hasOption("c") );
- assertTrue( "Confirm no extra args", cl.getArgList().size() == 0);
- }
- catch (ParseException e)
- {
- fail( e.toString() );
- }
- }
-
- public void testSingleLongOption()
- {
- String[] args = new String[] { "--file" };
-
- try
- {
- CommandLine cl = parser.parse( _options, args);
-
- assertTrue( "Confirm -r is NOT set", !cl.hasOption("r") );
- assertTrue( "Confirm -f is set", cl.hasOption("f") );
- assertTrue( "Confirm -d is NOT set", !cl.hasOption("d") );
- assertTrue( "Confirm -s is NOT set", !cl.hasOption("s") );
- assertTrue( "Confirm -c is NOT set", !cl.hasOption("c") );
- assertTrue( "Confirm no extra args", cl.getArgList().size() == 0);
- }
- catch (ParseException e)
- {
- fail( e.toString() );
- }
- }
-
- public void testTwoValidLongOptions()
- {
- String[] args = new String[] { "--revision", "--file" };
-
- try
- {
- CommandLine cl = parser.parse( _options, args);
-
- assertTrue( "Confirm -r is set", cl.hasOption("r") );
- assertTrue( "Confirm -f is set", cl.hasOption("f") );
- assertTrue( "Confirm -d is NOT set", !cl.hasOption("d") );
- assertTrue( "Confirm -s is NOT set", !cl.hasOption("s") );
- assertTrue( "Confirm -c is NOT set", !cl.hasOption("c") );
- assertTrue( "Confirm no extra args", cl.getArgList().size() == 0);
- }
- catch (ParseException e)
- {
- fail( e.toString() );
- }
- }
-
- public void testNoOptionsExtraArgs()
- {
- String[] args = new String[] { "arg1", "arg2" };
-
- try
- {
- CommandLine cl = parser.parse( _options, args);
-
- assertTrue( "Confirm -r is NOT set", !cl.hasOption("r") );
- assertTrue( "Confirm -f is NOT set", !cl.hasOption("f") );
- assertTrue( "Confirm -d is NOT set", !cl.hasOption("d") );
- assertTrue( "Confirm -s is NOT set", !cl.hasOption("s") );
- assertTrue( "Confirm -c is NOT set", !cl.hasOption("c") );
- assertTrue( "Confirm TWO extra args", cl.getArgList().size() == 2);
- }
- catch (ParseException e)
- {
- fail( e.toString() );
- }
- }
-
- public void testTwoOptionsFromGroup()
- {
- String[] args = new String[] { "-f", "-d" };
-
- try
- {
- CommandLine cl = parser.parse( _options, args);
- fail( "two arguments from group not allowed" );
- }
- catch (ParseException e)
- {
- if( !( e instanceof AlreadySelectedException ) )
- {
- fail( "incorrect exception caught:" + e.getMessage() );
- }
- }
- }
-
- public void testTwoLongOptionsFromGroup()
- {
- String[] args = new String[] { "--file", "--directory" };
-
- try
- {
- CommandLine cl = parser.parse( _options, args);
- fail( "two arguments from group not allowed" );
- }
- catch (ParseException e)
- {
- if( !( e instanceof AlreadySelectedException ) )
- {
- fail( "incorrect exception caught:" + e.getMessage() );
- }
- }
- }
-
- public void testTwoOptionsFromDifferentGroup()
- {
- String[] args = new String[] { "-f", "-s" };
-
- try
- {
- CommandLine cl = parser.parse( _options, args);
- assertTrue( "Confirm -r is NOT set", !cl.hasOption("r") );
- assertTrue( "Confirm -f is set", cl.hasOption("f") );
- assertTrue( "Confirm -d is NOT set", !cl.hasOption("d") );
- assertTrue( "Confirm -s is set", cl.hasOption("s") );
- assertTrue( "Confirm -c is NOT set", !cl.hasOption("c") );
- assertTrue( "Confirm NO extra args", cl.getArgList().size() == 0);
- }
- catch (ParseException e)
- {
- fail( e.toString() );
- }
- }
-
- public void testValidLongOnlyOptions()
- {
- try
- {
- CommandLine cl = parser.parse( _options, new String[]{"--export"});
- assertTrue( "Confirm --export is set", cl.hasOption("export") );
- }
- catch (ParseException e)
- {
- fail( e.toString() );
- }
-
- try
- {
- CommandLine cl = parser.parse( _options, new String[]{"--import"});
- assertTrue( "Confirm --import is set", cl.hasOption("import") );
- }
- catch (ParseException e)
- {
- fail( e.toString() );
- }
- }
-
-
-}