You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by eb...@apache.org on 2009/05/28 17:07:51 UTC
svn commit: r779616 - in
/commons/proper/cli/trunk/src/test/org/apache/commons/cli:
ApplicationTest.java PosixParserTest.java
Author: ebourg
Date: Thu May 28 15:07:51 2009
New Revision: 779616
URL: http://svn.apache.org/viewvc?rev=779616&view=rev
Log:
Moved the real world test from PosixParserTest to ApplicationTest
Modified:
commons/proper/cli/trunk/src/test/org/apache/commons/cli/ApplicationTest.java
commons/proper/cli/trunk/src/test/org/apache/commons/cli/PosixParserTest.java
Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli/ApplicationTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli/ApplicationTest.java?rev=779616&r1=779615&r2=779616&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli/ApplicationTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli/ApplicationTest.java Thu May 28 15:07:51 2009
@@ -218,4 +218,71 @@
hf.printHelp(60, cmdLine, null, options, null);
}
+
+ /**
+ * Real world test with long and short options.
+ */
+ public void testNLT() throws Exception {
+ 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 minutes")
+ .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"
+ };
+
+ 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");
+ }
}
Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli/PosixParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli/PosixParserTest.java?rev=779616&r1=779615&r2=779616&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli/PosixParserTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli/PosixParserTest.java Thu May 28 15:07:51 2009
@@ -30,73 +30,6 @@
parser = new PosixParser();
}
- /**
- * Real world test with long and short options.
- */
- public void testLongOptionWithShort() throws Exception {
- 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 minutes")
- .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"
- };
-
- 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");
- }
-
public void testLongWithEqualSingleDash() throws Exception
{
// not supported by the PosixParser