http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/DocumentationTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/DocumentationTest.java b/src/test/org/apache/commons/cli2/DocumentationTest.java deleted file mode 100644 index 634f036..0000000 --- a/src/test/org/apache/commons/cli2/DocumentationTest.java +++ /dev/null @@ -1,444 +0,0 @@ -/** - * Copyright 2003-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.cli2; - -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import junit.framework.TestCase; - -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.commandline.WriteableCommandLineImpl; -import org.apache.commons.cli2.option.DefaultOption; -import org.apache.commons.cli2.option.PropertyOption; -import org.apache.commons.cli2.util.HelpFormatter; - -/** - * @author Rob - */ -public class DocumentationTest extends TestCase { - - public void testBasicUsage() throws IOException, OptionException { - HelpFormatter helpFormatter = new HelpFormatter(); - //ignore all printed - helpFormatter.setPrintWriter(new PrintWriter(new StringWriter())); - - /* - * --version -? -h --help -log file -s|-q|-v|-d Bursting File/Num/Date - * validation Switches Commands Auto help Auto exception help - * - */ - DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); - Option version = - obuilder - .withLongName("version") - .withDescription("Displays version information and then exits") - .create(); - - Option help = - obuilder - .withShortName("h") - .withShortName("?") - .withLongName("help") - .withDescription("Displays help on usage and then exits") - .create(); - - ArgumentBuilder abuilder = new ArgumentBuilder(); - Argument logFile = - abuilder - .withDescription("The log file to write to") - .withName("file") - .withMinimum(1) - .withMaximum(1) - .create(); - Option log = - obuilder - .withArgument(logFile) - .withShortName("log") - .withDescription("Log progress information to a file") - .create(); - - GroupBuilder gbuilder = new GroupBuilder(); - Group outputQuality = - gbuilder - .withName("quality") - .withDescription("Controls the quality of console output") - .withMaximum(1) - .withOption( - obuilder - .withShortName("s") - .withDescription("Silent") - .create()) - .withOption( - obuilder - .withShortName("q") - .withDescription("Quiet") - .create()) - .withOption( - obuilder - .withShortName("n") - .withDescription("Normal") - .create()) - .withOption( - obuilder - .withShortName("v") - .withDescription("Verbose") - .create()) - .withOption( - obuilder - .withShortName("d") - .withDescription("Debug") - .create()) - .create(); - - Group options = - new GroupBuilder() - .withName("options") - .withOption(version) - .withOption(help) - .withOption(log) - .withOption(outputQuality) - .create(); - - final String[] args = new String[] { "--bad-option" }; - - Parser parser = new Parser(); - parser.setHelpFormatter(helpFormatter); - parser.setGroup(options); - parser.setHelpOption(help); - CommandLine commandLine = parser.parseAndHelp(args); - if (commandLine != null) { - if (commandLine.hasOption(version)) { - System.out.println("MyApp ver 1.0"); - return; - } - if (commandLine.hasOption("-log")) { - String filename = (String)commandLine.getValue("-log"); - //... - } - } - - try { - commandLine = parser.parse(args); - fail("Unexpected Option!"); - } - catch (OptionException uoe) { - assertEquals( - "Unexpected --bad-option while processing options", - uoe.getMessage()); - } - } - - public void testManualIntroduction() { - - DefaultOptionBuilder oBuilder = new DefaultOptionBuilder(); - ArgumentBuilder aBuilder = new ArgumentBuilder(); - GroupBuilder gBuilder = new GroupBuilder(); - - DefaultOption xmlOption = - oBuilder - .withLongName("xml") - .withDescription("Output using xml format") - .create(); - - Argument pathArgument = - aBuilder - .withName("path") - .withMinimum(1) - .withMaximum(1) - .create(); - - Group outputChildren = - gBuilder - .withOption(xmlOption) - .create(); - - Option outputOption = - oBuilder - .withLongName("output") - .withDescription("Outputs to a file") - .withArgument(pathArgument) - .withChildren(outputChildren) - .create(); - - /////////////////////////////////////////////////// - - Group options = outputChildren; - HelpFormatter hf = new HelpFormatter(); - - Parser p = new Parser(); - p.setGroup(options); - p.setHelpFormatter(hf); - p.setHelpTrigger("--help"); - CommandLine cl = p.parseAndHelp(new String[]{}); - if(cl==null) { - System.exit(-1); - } - - ////////////////////////////////////////////////// - - cl = new WriteableCommandLineImpl(outputChildren,new ArrayList()); - - // if we have --output option - if(cl.hasOption("--output")) { - // grab the path - String path = (String)cl.getValue("--output"); - // grab the format - boolean xml = cl.hasOption("--xml"); - // configure the application's output - configureOutput(path,xml); - } - - - - - } - - private void configureOutput(String path, boolean xml) { - // TODO Auto-generated method stub - - } - - public void testExampleAnt() throws IOException, OptionException { - // Apache Ant version 1.6.1 compiled on February 12 2004 - - final DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); - final ArgumentBuilder abuilder = new ArgumentBuilder(); - final GroupBuilder gbuilder = new GroupBuilder(); - - Option help = - obuilder - .withShortName("help") - .withShortName("h") - .withDescription("print this message") - .create(); - Option projecthelp = - obuilder - .withShortName("projecthelp") - .withShortName("p") - .withDescription("print project help information") - .create(); - Option version = - obuilder - .withShortName("version") - .withDescription("print the version information and exit") - .create(); - Option diagnostics = - obuilder - .withShortName("diagnostics") - .withDescription("print information that might be helpful to diagnose or report problems.") - .create(); - Option quiet = - obuilder - .withShortName("quiet") - .withShortName("q") - .withDescription("be extra quiet") - .create(); - Option verbose = - obuilder - .withShortName("verbose") - .withShortName("v") - .withDescription("be extra verbose") - .create(); - Option debug = - obuilder - .withShortName("debug") - .withShortName("d") - .withDescription("print debugging information") - .create(); - Option emacs = - obuilder - .withShortName("emacs") - .withShortName("e") - .withDescription("produce logging information without adornments") - .create(); - Option lib = - obuilder - .withShortName("lib") - .withDescription("specifies a path to search for jars and classes") - .withArgument( - abuilder - .withName("path") - .withMinimum(1) - .withMaximum(1) - .create()) - .create(); - Option logfile = - obuilder - .withShortName("logfile") - .withShortName("l") - .withDescription("use given file for log") - .withArgument( - abuilder - .withName("file") - .withMinimum(1) - .withMaximum(1) - .create()) - .create(); - Option logger = - obuilder - .withShortName("logger") - .withDescription("the class which is to perform logging") - .withArgument( - abuilder - .withName("classname") - .withMinimum(1) - .withMaximum(1) - .create()) - .create(); - Option listener = - obuilder - .withShortName("listener") - .withDescription("add an instance of class as a project listener") - .withArgument( - abuilder - .withName("classname") - .withMinimum(1) - .withMaximum(1) - .create()) - .create(); - Option noinput = - obuilder - .withShortName("noinput") - .withDescription("do not allow interactive input") - .create(); - Option buildfile = - obuilder - .withShortName("buildfile") - .withShortName("file") - .withShortName("f") - .withDescription("use given buildfile") - .withArgument( - abuilder - .withName("file") - .withMinimum(1) - .withMaximum(1) - .create()) - .create(); - Option property = new PropertyOption(); - Option propertyfile = - obuilder - .withShortName("propertyfile") - .withDescription("load all properties from file with -D properties taking precedence") - .withArgument( - abuilder - .withName("name") - .withMinimum(1) - .withMaximum(1) - .create()) - .create(); - Option inputhandler = - obuilder - .withShortName("inputhandler") - .withDescription("the class which will handle input requests") - .withArgument( - abuilder - .withName("class") - .withMinimum(1) - .withMaximum(1) - .create()) - .create(); - Option find = - obuilder - .withShortName("find") - .withShortName("s") - .withDescription("search for buildfile towards the root of the filesystem and use it") - .withArgument( - abuilder - .withName("file") - .withMinimum(1) - .withMaximum(1) - .create()) - .create(); - Option targets = abuilder.withName("target").create(); - - Group options = - gbuilder - .withName("options") - .withOption(help) - .withOption(projecthelp) - .withOption(version) - .withOption(diagnostics) - .withOption(quiet) - .withOption(verbose) - .withOption(debug) - .withOption(emacs) - .withOption(lib) - .withOption(logfile) - .withOption(logger) - .withOption(listener) - .withOption(noinput) - .withOption(buildfile) - .withOption(property) - .withOption(propertyfile) - .withOption(inputhandler) - .withOption(find) - .withOption(targets) - .create(); - - ///////////////////////////////////// - String[] args = new String[]{}; - - Parser parser = new Parser(); - parser.setGroup(options); - CommandLine cl = parser.parse(args); - - if(cl.hasOption(help)) { - //displayHelp(); - return; - } - if(cl.hasOption("-version")) { - //displayVersion(); - return; - } - if(cl.hasOption(logfile)) { - String file = (String)cl.getValue(logfile); - //setLogFile(); - } - List targetList = cl.getValues(targets); - for (Iterator i = targetList.iterator(); i.hasNext();) { - String target = (String) i.next(); - //doTarget(target); - } - - ///////////////////////////////////// - - HelpFormatter hf = new HelpFormatter(); - hf.setShellCommand("ant"); - hf.getFullUsageSettings().add(DisplaySetting.DISPLAY_GROUP_NAME); - hf.getFullUsageSettings().add(DisplaySetting.DISPLAY_GROUP_ARGUMENT); - hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_EXPANDED); - - hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PROPERTY_OPTION); - hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PARENT_ARGUMENT); - hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_ARGUMENT_BRACKETED); - - hf.getDisplaySettings().remove(DisplaySetting.DISPLAY_GROUP_ARGUMENT); - - hf.setGroup(options); - // redirect printed stuff to a string - hf.setPrintWriter(new PrintWriter(new StringWriter())); - hf.print(); - - } -}
http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/PrecedenceTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/PrecedenceTest.java b/src/test/org/apache/commons/cli2/PrecedenceTest.java deleted file mode 100644 index 6af7142..0000000 --- a/src/test/org/apache/commons/cli2/PrecedenceTest.java +++ /dev/null @@ -1,412 +0,0 @@ -/** - * Copyright 2003-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.cli2; - -import java.util.Arrays; -import java.util.List; -import java.util.Set; - -import junit.framework.TestCase; - -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 Rob Oxspring - */ -public class PrecedenceTest extends TestCase { - private final String[] args = new String[] { "-file" }; - - public void testSimple() throws OptionException { - final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder(); - - final Group options = - new GroupBuilder() - .withOption(oBuilder.withShortName("file").create()) - .create(); - - final CommandLine cl = buildCommandLine(options, args); - assertEquals(new String[] { "-file" }, cl); - } - - public void testArgument() throws OptionException { - final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder(); - final ArgumentBuilder aBuilder = new ArgumentBuilder(); - - final Group options = - new GroupBuilder() - .withOption( - oBuilder - .withShortName("f") - .withArgument(aBuilder.create()) - .create()) - .create(); - - final CommandLine cl = buildCommandLine(options, args); - assertEquals(new String[] { "-f" }, cl); - } - - public void testBurst() throws OptionException { - final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder(); - final GroupBuilder gBuilder = new GroupBuilder(); - final Group options = - gBuilder - .withOption(oBuilder.withShortName("f").create()) - .withOption(oBuilder.withShortName("i").create()) - .withOption(oBuilder.withShortName("l").create()) - .withOption(oBuilder.withShortName("e").create()) - .create(); - - final CommandLine cl = buildCommandLine(options, args); - assertEquals(new String[] { "-f", "-i", "-l", "-e" }, cl); - } - - public void testChildren() throws OptionException { - final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder(); - final GroupBuilder gBuilder = new GroupBuilder(); - - final Group children = - gBuilder - .withOption(oBuilder.withShortName("i").create()) - .withOption(oBuilder.withShortName("l").create()) - .withOption(oBuilder.withShortName("e").create()) - .create(); - final Group options = - gBuilder - .withOption( - oBuilder - .withShortName("f") - .withChildren(children) - .create()) - .create(); - - final CommandLine cl = buildCommandLine(options, args); - assertEquals(new String[] { "-f", "-i", "-l", "-e" }, cl); - } - - public void XtestSimpleVsArgument() throws OptionException { - final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder(); - final GroupBuilder gBuilder = new GroupBuilder(); - final ArgumentBuilder aBuilder = new ArgumentBuilder(); - - final Group options = - gBuilder - .withOption(oBuilder.withShortName("file").create()) - .withOption( - oBuilder - .withShortName("f") - .withArgument(aBuilder.create()) - .create()) - .create(); - - final CommandLine cl = buildCommandLine(options, args); - assertEquals(new String[] { "-f" }, cl); - } - - public void XtestSimpleVsBurst() throws OptionException { - final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder(); - final GroupBuilder gBuilder = new GroupBuilder(); - final Group options = - gBuilder - .withOption(oBuilder.withShortName("file").create()) - .withOption(oBuilder.withShortName("f").create()) - .withOption(oBuilder.withShortName("i").create()) - .withOption(oBuilder.withShortName("l").create()) - .withOption(oBuilder.withShortName("e").create()) - .create(); - - final CommandLine cl = buildCommandLine(options, args); - assertEquals(new String[] { "-f", "-i", "-l", "-e" }, cl); - } - - public void XtestSimpleVsChildren() throws OptionException { - final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder(); - final GroupBuilder gBuilder = new GroupBuilder(); - - final Group children = - gBuilder - .withOption( - oBuilder.withShortName("i").withLongName("ci").create()) - .withOption( - oBuilder.withShortName("l").withLongName("cl").create()) - .withOption( - oBuilder.withShortName("e").withLongName("ce").create()) - .create(); - - final Group options = - gBuilder - .withOption(oBuilder.withShortName("file").create()) - .withOption( - oBuilder - .withShortName("f") - .withChildren(children) - .create()) - .create(); - - final CommandLine cl = buildCommandLine(options, args); - assertEquals( - new String[] { "-f", "-i", "--ci", "-l", "--cl", "-e", "--ce" }, - cl); - } - - public void testArgumentVsBurst() throws OptionException { - final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder(); - final GroupBuilder gBuilder = new GroupBuilder(); - final ArgumentBuilder aBuilder = new ArgumentBuilder(); - - final Group options = - gBuilder - .withOption( - oBuilder - .withShortName("f") - .withArgument(aBuilder.create()) - .create()) - .withOption(oBuilder.withShortName("i").create()) - .withOption(oBuilder.withShortName("l").create()) - .withOption(oBuilder.withShortName("e").create()) - .create(); - - final CommandLine cl = buildCommandLine(options, args); - assertEquals(new String[] { "-f" }, cl); - } - - public void testArgumentVsChildren() throws OptionException { - final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder(); - final GroupBuilder gBuilder = new GroupBuilder(); - final ArgumentBuilder aBuilder = new ArgumentBuilder(); - - final Group children = - gBuilder - .withOption(oBuilder.withShortName("i").create()) - .withOption(oBuilder.withShortName("l").create()) - .withOption(oBuilder.withShortName("e").create()) - .create(); - final Group options = - gBuilder - .withOption( - oBuilder - .withShortName("f") - .withChildren(children) - .withArgument(aBuilder.create()) - .create()) - .create(); - - final CommandLine cl = buildCommandLine(options, args); - assertEquals(new String[] { "-f" }, cl); - } - - public void testBurstVsChildren() throws OptionException { - final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder(); - final GroupBuilder gBuilder = new GroupBuilder(); - - final Group children = - gBuilder - .withOption( - oBuilder.withShortName("i").withLongName("ci").create()) - .withOption( - oBuilder.withShortName("l").withLongName("cl").create()) - .withOption( - oBuilder.withShortName("e").withLongName("ce").create()) - .create(); - - final Group options = - gBuilder - .withOption( - oBuilder - .withShortName("f") - .withChildren(children) - .create()) - .withOption( - oBuilder.withShortName("i").withLongName("bi").create()) - .withOption( - oBuilder.withShortName("l").withLongName("bl").create()) - .withOption( - oBuilder.withShortName("e").withLongName("be").create()) - .create(); - - final CommandLine cl = buildCommandLine(options, args); - assertEquals( - new String[] { "-f", "-i", "--ci", "-l", "--cl", "-e", "--ce" }, - cl); - } - - public void XtestSimpleVsArgumentVsBurst() throws OptionException { - final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder(); - final GroupBuilder gBuilder = new GroupBuilder(); - final ArgumentBuilder aBuilder = new ArgumentBuilder(); - - final Group options = - gBuilder - .withOption(oBuilder.withShortName("file").create()) - .withOption( - oBuilder - .withShortName("f") - .withArgument(aBuilder.create()) - .create()) - .withOption(oBuilder.withShortName("i").create()) - .withOption(oBuilder.withShortName("l").create()) - .withOption(oBuilder.withShortName("e").create()) - .create(); - - final CommandLine cl = buildCommandLine(options, args); - assertEquals(new String[] { "-f" }, cl); - } - - public void XtestSimpleVsArgumentVsChildren() throws OptionException { - final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder(); - final GroupBuilder gBuilder = new GroupBuilder(); - final ArgumentBuilder aBuilder = new ArgumentBuilder(); - - final Group children = - gBuilder - .withOption( - oBuilder.withShortName("i").withLongName("ci").create()) - .withOption( - oBuilder.withShortName("l").withLongName("cl").create()) - .withOption( - oBuilder.withShortName("e").withLongName("ce").create()) - .create(); - - final Group options = - gBuilder - .withOption(oBuilder.withShortName("file").create()) - .withOption( - oBuilder - .withShortName("f") - .withChildren(children) - .withArgument(aBuilder.create()) - .create()) - .create(); - - final CommandLine cl = buildCommandLine(options, args); - assertEquals(new String[] { "-f" }, cl); - } - - public void XtestSimpleVsBurstVsChildren() throws OptionException { - final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder(); - final GroupBuilder gBuilder = new GroupBuilder(); - - final Group children = - gBuilder - .withOption( - oBuilder.withShortName("i").withLongName("ci").create()) - .withOption( - oBuilder.withShortName("l").withLongName("cl").create()) - .withOption( - oBuilder.withShortName("e").withLongName("ce").create()) - .create(); - - final Group options = - gBuilder - .withOption(oBuilder.withShortName("file").create()) - .withOption( - oBuilder - .withShortName("f") - .withChildren(children) - .create()) - .withOption(oBuilder.withShortName("i").create()) - .withOption(oBuilder.withShortName("l").create()) - .withOption(oBuilder.withShortName("e").create()) - .create(); - - final CommandLine cl = buildCommandLine(options, args); - assertEquals(new String[] { "-f", "-i", "-l", "-e" }, cl); - } - - public void testArgumentVsBurstVsChildren() throws OptionException { - final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder(); - final GroupBuilder gBuilder = new GroupBuilder(); - final ArgumentBuilder aBuilder = new ArgumentBuilder(); - - final Group children = - gBuilder - .withOption( - oBuilder.withShortName("i").withLongName("ci").create()) - .withOption( - oBuilder.withShortName("l").withLongName("cl").create()) - .withOption( - oBuilder.withShortName("e").withLongName("ce").create()) - .create(); - - final Group options = - gBuilder - .withOption( - oBuilder - .withShortName("f") - .withChildren(children) - .withArgument(aBuilder.create()) - .create()) - .withOption(oBuilder.withShortName("i").create()) - .withOption(oBuilder.withShortName("l").create()) - .withOption(oBuilder.withShortName("e").create()) - .create(); - - final CommandLine cl = buildCommandLine(options, args); - assertEquals(new String[] { "-f" }, cl); - } - - public void XtestSimpleVsArgumentVsBurstVsChildren() - throws OptionException { - final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder(); - final GroupBuilder gBuilder = new GroupBuilder(); - final ArgumentBuilder aBuilder = new ArgumentBuilder(); - - final Group children = - gBuilder - .withOption( - oBuilder.withShortName("i").withLongName("ci").create()) - .withOption( - oBuilder.withShortName("l").withLongName("cl").create()) - .withOption( - oBuilder.withShortName("e").withLongName("ce").create()) - .create(); - - final Group options = - gBuilder - .withOption(oBuilder.withShortName("file").create()) - .withOption( - oBuilder - .withShortName("f") - .withChildren(children) - .withArgument(aBuilder.create()) - .create()) - .withOption(oBuilder.withShortName("i").create()) - .withOption(oBuilder.withShortName("l").create()) - .withOption(oBuilder.withShortName("e").create()) - .create(); - - final CommandLine cl = buildCommandLine(options, args); - assertEquals(new String[] { "-f" }, cl); - } - - public CommandLine buildCommandLine(final Group group, final String[] arguments) - throws OptionException { - Parser p = new Parser(); - p.setGroup(group); - return p.parse(arguments); - } - - public void assertEquals(final String options[], final CommandLine line) { - final List expected = Arrays.asList(options); - final Set actual = line.getOptionTriggers(); - - assertTrue(expected.containsAll(actual)); - assertTrue(actual.containsAll(expected)); - } - -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/WriteableCommandLineTestCase.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/WriteableCommandLineTestCase.java b/src/test/org/apache/commons/cli2/WriteableCommandLineTestCase.java deleted file mode 100644 index 3fe3e5a..0000000 --- a/src/test/org/apache/commons/cli2/WriteableCommandLineTestCase.java +++ /dev/null @@ -1,91 +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.cli2; - -import org.apache.commons.cli2.option.ArgumentTest; - -/** - * @author Rob Oxspring - */ -public abstract class WriteableCommandLineTestCase extends CommandLineTestCase { - - private WriteableCommandLine writeable; - - protected abstract WriteableCommandLine createWriteableCommandLine(); - - /* (non-Javadoc) - * @see org.apache.commons.cli2.CommandLineTest#createCommandLine() - */ - protected final CommandLine createCommandLine() { - final WriteableCommandLine cl = createWriteableCommandLine(); - cl.addOption(present); - cl.addProperty("present","present property"); - cl.addSwitch(bool,true); - cl.addValue(present,"present value"); - cl.addOption(multiple); - cl.addValue(multiple,"value 1"); - cl.addValue(multiple,"value 2"); - cl.addValue(multiple,"value 3"); - return cl; - } - - /* - * @see CommandLineTest#setUp() - */ - public void setUp() throws Exception { - super.setUp(); - writeable = createWriteableCommandLine(); - } - public final void testAddOption() { - assertFalse(writeable.hasOption(present)); - writeable.addOption(present); - assertTrue(writeable.hasOption(present)); - } - public final void testAddValue() { - assertFalse(writeable.hasOption(present)); - assertTrue(writeable.getValues(present).isEmpty()); - writeable.addValue(present,"value"); - assertContentsEqual(list("value"),writeable.getValues(present)); - - // most options shouldn't appear due to adding values - assertFalse(writeable.hasOption(present)); - - final Argument arg = ArgumentTest.buildHostArgument(); - - assertFalse(writeable.hasOption(arg)); - assertTrue(writeable.getValues(arg).isEmpty()); - writeable.addValue(arg,"value"); - assertContentsEqual(list("value"),writeable.getValues(arg)); - - // Arguments should force the option present - assertTrue(writeable.hasOption(arg)); - } - public final void testAddSwitch() { - assertFalse(writeable.hasOption(present)); - assertNull(writeable.getSwitch(present)); - writeable.addSwitch(present,true); - assertEquals(Boolean.TRUE,writeable.getSwitch(present)); - assertTrue(writeable.hasOption(present)); - } - public final void testAddProperty() { - assertNull(writeable.getProperty("present")); - writeable.addProperty("present","present value"); - assertEquals("present value",writeable.getProperty("present")); - } - public final void testLooksLikeOption() { - //TODO Implement looksLikeOption(). - } -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/application/AntTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/application/AntTest.java b/src/test/org/apache/commons/cli2/application/AntTest.java deleted file mode 100644 index 0a0cbe0..0000000 --- a/src/test/org/apache/commons/cli2/application/AntTest.java +++ /dev/null @@ -1,197 +0,0 @@ -/** - * Copyright 2003-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.cli2.application; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; - -import org.apache.commons.cli2.CommandLine; -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.PropertyOption; - -//TODO Build up AntTest like CpTest -public class AntTest extends TestCase { - public void testAnt() throws OptionException { - 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( - obuilder - .withShortName("version") - .withDescription("print the version information and exit") - .create()) - .withOption( - obuilder - .withShortName("diagnostics") - .withDescription("print information that might be helpful to diagnose or report problems.") - .create()) - .withOption( - obuilder - .withShortName("quiet") - .withShortName("q") - .withDescription("be extra quiet") - .create()) - .withOption( - obuilder - .withShortName("verbose") - .withShortName("v") - .withDescription("be extra verbose") - .create()) - .withOption( - obuilder - .withShortName("debug") - .withDescription("print debugging information") - .create()) - .withOption( - obuilder - .withShortName("emacs") - .withDescription("produce logging information without adornments") - .create()) - .withOption( - obuilder - .withShortName("logfile") - .withShortName("l") - .withDescription("use given file for log") - .withArgument( - abuilder - .withName("file") - .withMinimum(1) - .withMaximum(1) - .create()) - .create()) - .withOption( - obuilder - .withShortName("logger") - .withDescription("the class which is to perform logging") - .withArgument( - abuilder - .withName("classname") - .withMinimum(1) - .withMaximum(1) - .create()) - .create()) - .withOption( - obuilder - .withShortName("listener") - .withDescription("add an instance of class as a project listener") - .withArgument( - abuilder - .withName("classname") - .withMinimum(1) - .withMaximum(1) - .create()) - .create()) - .withOption( - obuilder - .withShortName("buildfile") - .withShortName("file") - .withShortName("f") - .withDescription("use given buildfile") - .withArgument( - abuilder - .withName("file") - .withMinimum(1) - .withMaximum(1) - .create()) - .create()) - .withOption(PropertyOption.INSTANCE) - .withOption( - obuilder - .withShortName("propertyfile") - .withDescription("load all properties from file with -D properties taking precedence") - .withArgument( - abuilder - .withName("name") - .withMinimum(1) - .withMaximum(1) - .create()) - .create()) - .withOption( - obuilder - .withShortName("inputhandler") - .withDescription("the class which will handle input requests") - .withArgument( - abuilder - .withName("class") - .withMinimum(1) - .withMaximum(1) - .create()) - .create()) - .withOption( - obuilder - .withShortName("find") - .withDescription("search for buildfile towards the root of the filesystem and use it") - .withArgument( - abuilder - .withName("file") - .withMinimum(1) - .withMaximum(1) - .create()) - .create()) - .withOption(abuilder.withName("target").create()) - .create(); - - Parser parser = new Parser(); - parser.setGroup(options); - CommandLine line = - parser.parse( - new String[] { - "-buildfile", - "mybuild.xml", - "-Dproperty=value", - "-Dproperty1=value1", - "-projecthelp", - "compile", - "docs" }); - - // check properties - assertEquals(2, line.getProperties().size()); - assertEquals("value", line.getProperty("property")); - assertEquals("value1", line.getProperty("property1")); - - // check single values - assertEquals("mybuild.xml", line.getValue("-buildfile")); - assertTrue(line.hasOption("-projecthelp")); - assertFalse(line.hasOption("-help")); - - assertTrue(line.hasOption("target")); - final List targets = new ArrayList(); - targets.add("compile"); - targets.add("docs"); - assertEquals(targets, line.getValues("target")); - } -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/application/CpTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/application/CpTest.java b/src/test/org/apache/commons/cli2/application/CpTest.java deleted file mode 100644 index 08e13c0..0000000 --- a/src/test/org/apache/commons/cli2/application/CpTest.java +++ /dev/null @@ -1,470 +0,0 @@ -/** - * Copyright 2003-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.cli2.application; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringReader; -import java.io.StringWriter; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -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 org.apache.commons.cli2.option.ArgumentImpl; -import org.apache.commons.cli2.option.SourceDestArgument; -import org.apache.commons.cli2.util.HelpFormatter; - -/** - * <p>Test the <code>cp</code> command. Duplicated Option types are not - * tested e.g. -a and -d are the same Option type.</p> - * - * <p>The following is the man output for 'cp'. See - * http://www.rt.com/man/cp.1.html.</p> - * - * <pre> - * CP(1) FSF CP(1) - * - * NAME cp - copy files and directories - * - * SYNOPSIS cp [OPTION]... SOURCE DEST cp [OPTION]... SOURCE... DIRECTORY - * - * DESCRIPTION Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY. - * - * -a, --archive same as -dpR - * - * -b, --backup make backup before removal - * - * -d, --no-dereference preserve links - * - * -f, --force remove existing destinations, never prompt - * - * -i, --interactive prompt before overwrite - * - * -l, --link link files instead of copying - * - * -p, --preserve preserve file attributes if possible - * - * -P, --parents append source path to DIRECTORY - * -r copy recursively, non-directories as files - * - * --sparse=WHEN control creation of sparse files - * - * -R, --recursive copy directories recursively - * - * -s, --symbolic-link make symbolic links instead of copying - * - * -S, --suffix=SUFFIX override the usual backup suffix - * - * -u, --update copy only when the SOURCE file is newer than the destination file or when the destination file is missing - * - * -v, --verbose explain what is being done - * - * -V, --version-control=WORD override the usual version control - * - * -x, --one-file-system stay on this file system - * - * --help display this help and exit - * - * --version output version information and exit - * - * By default, sparse SOURCE files are detected by a crude heuristic and the corresponding DEST file is made sparse as well. That is the behavior selected by --sparse=auto. Specify --sparse=always to create a sparse DEST file when- ever the SOURCE file contains a long enough sequence of zero bytes. Use --sparse=never to inhibit creation of sparse files. - * - * The backup suffix is ~, unless set with SIMPLE_BACKUP_SUF- FIX. The version control may be set with VERSION_CONTROL, values are: - * t, numbered make numbered backups - * - * nil, existing numbered if numbered backups exist, simple other- wise - * - * never, simple always make simple backups - * - * As a special case, cp makes a backup of SOURCE when the force and backup options are given and SOURCE and DEST are the same name for an existing, regular file. * </pre> - * </pre> - * - * @author Rob Oxspring - * @author John Keyes - */ -public class CpTest extends TestCase { - - /** Option Builder */ - private static final DefaultOptionBuilder oBuilder = - new DefaultOptionBuilder(); - - /** Argument Builder */ - private static final ArgumentBuilder aBuilder = new ArgumentBuilder(); - - /** Group Builder */ - private static final GroupBuilder gBuilder = new GroupBuilder(); - - private Group options; - - public static Test suite() { - return new TestSuite(CpTest.class); - } - - private ArgumentImpl source; - private ArgumentImpl dest; - private Argument targets; - - private Option archive; - private Option backup; - private Option noDereference; - private Option force; - private Option interactive; - private Option link; - private Option preserve; - private Option parents; - private Option recursive1; - private Option sparse; - private Option recursive2; - private Option symbolicLink; - private Option suffix; - private Option update; - private Option verbose; - private Option versionControl; - private Option oneFileSystem; - private Option help; - private Option version; - - public void setUp() { - source = - (ArgumentImpl)aBuilder.withName("SOURCE").withMinimum(1).create(); - dest = - (ArgumentImpl)aBuilder - .withName("DEST") - .withMinimum(1) - .withMaximum(1) - .create(); - targets = new SourceDestArgument(source, dest); - - archive = - oBuilder - .withShortName("a") - .withLongName("archive") - .withDescription("same as -dpR") - .create(); - - backup = - oBuilder - .withShortName("b") - .withLongName("backup") - .withDescription("make backup before removal") - .create(); - - noDereference = - oBuilder - .withShortName("d") - .withLongName("no-dereference") - .withDescription("preserve links") - .create(); - - force = - oBuilder - .withShortName("f") - .withLongName("force") - .withDescription("remove existing destinations, never prompt") - .create(); - - interactive = - oBuilder - .withShortName("i") - .withLongName("interactive") - .withDescription("prompt before overwrite") - .create(); - - link = - oBuilder - .withShortName("l") - .withLongName("link") - .withDescription("link files instead of copying") - .create(); - - preserve = - oBuilder - .withShortName("p") - .withLongName("preserve") - .withDescription("preserve file attributes if possible") - .create(); - - parents = - oBuilder - .withShortName("P") - .withLongName("parents") - .withDescription("append source path to DIRECTORY") - .create(); - - recursive1 = - oBuilder - .withShortName("r") - .withDescription("copy recursively, non-directories as files") - .create(); - - sparse = - oBuilder - .withLongName("sparse") - .withDescription("control creation of sparse files") - .withArgument( - aBuilder - .withName("WHEN") - .withMinimum(1) - .withMaximum(1) - .withInitialSeparator('=') - .create()) - .create(); - - recursive2 = - oBuilder - .withShortName("R") - .withLongName("recursive") - .withDescription("copy directories recursively") - .create(); - - symbolicLink = - oBuilder - .withShortName("s") - .withLongName("symbolic-link") - .withDescription("make symbolic links instead of copying") - .create(); - - suffix = - oBuilder - .withShortName("S") - .withLongName("suffix") - .withDescription("override the usual backup suffix") - .withArgument( - aBuilder - .withName("SUFFIX") - .withMinimum(1) - .withMaximum(1) - .create()) - .create(); - - update = - oBuilder - .withShortName("u") - .withLongName("update") - .withDescription("copy only when the SOURCE file is newer than the destination file or when the destination file is missing") - .create(); - - verbose = - oBuilder - .withShortName("v") - .withLongName("verbose") - .withDescription("explain what is being done") - .create(); - - versionControl = - oBuilder - .withShortName("V") - .withLongName("version-contol") - .withDescription("explain what is being done") - .withArgument( - aBuilder - .withName("WORD") - .withInitialSeparator('=') - .withMinimum(1) - .withMaximum(1) - .create()) - .create(); - - oneFileSystem = - oBuilder - .withShortName("x") - .withLongName("one-file-system") - .withDescription("stay on this file system") - .create(); - - help = - oBuilder - .withLongName("help") - .withDescription("display this help and exit") - .create(); - - version = - oBuilder - .withLongName("version") - .withDescription("output version information and exit") - .create(); - - options = - gBuilder - .withOption(archive) - .withOption(backup) - .withOption(noDereference) - .withOption(force) - .withOption(interactive) - .withOption(link) - .withOption(preserve) - .withOption(parents) - .withOption(recursive1) - .withOption(sparse) - .withOption(recursive2) - .withOption(symbolicLink) - .withOption(suffix) - .withOption(update) - .withOption(verbose) - .withOption(versionControl) - .withOption(oneFileSystem) - .withOption(help) - .withOption(version) - .withOption(targets) - .withName("OPTIONS") - .create(); - } - - public void testNoSource() { - Parser parser = new Parser(); - parser.setGroup(options); - try { - parser.parse(new String[0]); - } - catch (OptionException mve) { - assertEquals( - "Missing value(s) SOURCE [SOURCE ...]", - mve.getMessage()); - } - } - - public void testOneSource() throws OptionException { - final String[] args = new String[] { "source1", "dest1" }; - final Parser parser = new Parser(); - parser.setGroup(options); - final CommandLine commandLine = parser.parse(args); - - assertTrue(commandLine.getValues(source).contains("source1")); - assertEquals(1, commandLine.getValues(source).size()); - assertTrue(commandLine.getValues(dest).contains("dest1")); - assertEquals(1, commandLine.getValues(dest).size()); - } - - public void testMultiSource() throws OptionException { - final String[] args = - new String[] { "source1", "source2", "source3", "dest1" }; - final Parser parser = new Parser(); - parser.setGroup(options); - final CommandLine commandLine = parser.parse(args); - - assertTrue(commandLine.getValues(source).contains("source1")); - assertTrue(commandLine.getValues(source).contains("source2")); - assertTrue(commandLine.getValues(source).contains("source3")); - assertEquals(3, commandLine.getValues(source).size()); - - assertTrue(commandLine.getValues(dest).contains("dest1")); - assertEquals(1, commandLine.getValues(dest).size()); - } - - public void testHelp() throws IOException { - final StringWriter out = new StringWriter(); - final HelpFormatter helpFormatter = new HelpFormatter(); - helpFormatter.setGroup(options); - helpFormatter.setPrintWriter(new PrintWriter(out)); - helpFormatter.print(); - - final BufferedReader in = - new BufferedReader(new StringReader(out.toString())); - assertEquals( - "Usage: ", - in.readLine()); - assertEquals( - " [-a -b -d -f -i -l -p -P -r --sparse <WHEN> -R -s -S <SUFFIX> -u -v -V <WORD> ", - in.readLine()); - assertEquals( - "-x --help --version] <SOURCE1> [<SOURCE2> ...] <DEST> ", - in.readLine()); - assertEquals( - "OPTIONS ", - in.readLine()); - assertEquals( - " -a (--archive) same as -dpR ", - in.readLine()); - assertEquals( - " -b (--backup) make backup before removal ", - in.readLine()); - assertEquals( - " -d (--no-dereference) preserve links ", - in.readLine()); - assertEquals( - " -f (--force) remove existing destinations, never prompt ", - in.readLine()); - assertEquals( - " -i (--interactive) prompt before overwrite ", - in.readLine()); - assertEquals( - " -l (--link) link files instead of copying ", - in.readLine()); - assertEquals( - " -p (--preserve) preserve file attributes if possible ", - in.readLine()); - assertEquals( - " -P (--parents) append source path to DIRECTORY ", - in.readLine()); - assertEquals( - " -r copy recursively, non-directories as files ", - in.readLine()); - assertEquals( - " --sparse WHEN control creation of sparse files ", - in.readLine()); - assertEquals( - " -R (--recursive) copy directories recursively ", - in.readLine()); - assertEquals( - " -s (--symbolic-link) make symbolic links instead of copying ", - in.readLine()); - assertEquals( - " -S (--suffix) SUFFIX override the usual backup suffix ", - in.readLine()); - assertEquals( - " -u (--update) copy only when the SOURCE file is newer than ", - in.readLine()); - assertEquals( - " the destination file or when the destination ", - in.readLine()); - assertEquals( - " file is missing ", - in.readLine()); - assertEquals( - " -v (--verbose) explain what is being done ", - in.readLine()); - assertEquals( - " -V (--version-contol) WORD explain what is being done ", - in.readLine()); - assertEquals( - " -x (--one-file-system) stay on this file system ", - in.readLine()); - assertEquals( - " --help display this help and exit ", - in.readLine()); - assertEquals( - " --version output version information and exit ", - in.readLine()); - assertEquals( - " SOURCE [SOURCE ...] ", - in.readLine()); - assertEquals( - " DEST ", - in.readLine()); - assertNull(in.readLine()); - } -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/application/CvsTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/application/CvsTest.java b/src/test/org/apache/commons/cli2/application/CvsTest.java deleted file mode 100644 index bee4a12..0000000 --- a/src/test/org/apache/commons/cli2/application/CvsTest.java +++ /dev/null @@ -1,311 +0,0 @@ -/** - * Copyright 2003-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.cli2.application; - -import junit.framework.TestCase; - -import org.apache.commons.cli2.Group; -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.option.ArgumentTest; - -//TODO Build up CvsTest like CpTest -public class CvsTest extends TestCase { - public void testCVS() { - final DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); - final ArgumentBuilder abuilder = new ArgumentBuilder(); - final CommandBuilder cbuilder = new CommandBuilder(); - final GroupBuilder gbuilder = new GroupBuilder(); - - final Group commands = - gbuilder - .withName("commands") - .withOption( - cbuilder - .withName("add") - .withName("ad") - .withName("new") - .withDescription("Add a new file/directory to the repository") - .create()) - .withOption( - cbuilder - .withName("admin") - .withName("adm") - .withName("rcs") - .withDescription("Administration front end for rcs") - .create()) - .withOption( - cbuilder - .withName("annotate") - .withName("ann") - .withDescription("Show last revision where each line was modified") - .create()) - .withOption( - cbuilder - .withName("checkout") - .withName("co") - .withName("get") - .withDescription("Checkout sources for editing") - .create()) - .withOption( - cbuilder - .withName("commit") - .withName("ci") - .withName("com") - .withDescription("Check files into the repository") - .create()) - .withOption( - cbuilder - .withName("diff") - .withName("di") - .withName("dif") - .withDescription("Show differences between revisions") - .create()) - .withOption( - cbuilder - .withName("edit") - .withDescription("Get ready to edit a watched file") - .create()) - .withOption( - cbuilder - .withName("editors") - .withDescription("See who is editing a watched file") - .create()) - .withOption( - cbuilder - .withName("export") - .withName("exp") - .withName("ex") - .withDescription("Export sources from CVS, similar to checkout") - .create()) - .withOption( - cbuilder - .withName("history") - .withName("hi") - .withName("his") - .withDescription("Show repository access history") - .create()) - .withOption( - cbuilder - .withName("import") - .withName("im") - .withName("imp") - .withDescription("Import sources into CVS, using vendor branches") - .create()) - .withOption( - cbuilder - .withName("init") - .withDescription("Create a CVS repository if it doesn't exist") - .create()) - .withOption( - cbuilder - .withName("log") - .withName("lo") - .withName("rlog") - .withDescription("Print out history information for files") - .create()) - .withOption( - cbuilder - .withName("login") - .withName("logon") - .withName("lgn") - .withDescription("Prompt for password for authenticating server") - .create()) - .withOption( - cbuilder - .withName("logout") - .withDescription("Removes entry in .cvspass for remote repository") - .create()) - .withOption( - cbuilder - .withName("rdiff") - .withName("patch") - .withName("pa") - .withDescription("Create 'patch' format diffs between releases") - .create()) - .withOption( - cbuilder - .withName("release") - .withName("re") - .withName("rel") - .withDescription("Indicate that a Module is no longer in use") - .create()) - .withOption( - cbuilder - .withName("remove") - .withName("rm") - .withName("delete") - .withDescription("Remove an entry from the repository") - .create()) - .withOption( - cbuilder - .withName("rtag") - .withName("rt") - .withName("rfreeze") - .withDescription("Add a symbolic tag to a module") - .create()) - .withOption( - cbuilder - .withName("status") - .withName("st") - .withName("stat") - .withDescription("Display status information on checked out files") - .create()) - .withOption( - cbuilder - .withName("tag") - .withName("ta") - .withName("freeze") - .withDescription("Add a symbolic tag to checked out version of files") - .create()) - .withOption( - cbuilder - .withName("unedit") - .withDescription("Undo an edit command") - .create()) - .withOption( - cbuilder - .withName("update") - .withName("up") - .withName("upd") - .withDescription("Bring work tree in sync with repository") - .create()) - .withOption( - cbuilder - .withName("watch") - .withDescription("Set watches") - .create()) - .withOption( - cbuilder - .withName("watchers") - .withDescription("See who is watching a file") - .create()) - .withOption( - cbuilder - .withName("version") - .withName("ve") - .withName("ver") - .withDescription("????") - .create()) - .withOption(ArgumentTest.buildTargetsArgument()) - .create(); - - final Group cvsOptions = - new GroupBuilder() - .withName("cvs-options") - .withOption( - obuilder - .withShortName("H") - .withDescription("Displays usage information for command.") - .create()) - .withOption( - obuilder - .withShortName("Q") - .withDescription("Cause CVS to be really quiet.") - .create()) - .withOption( - obuilder - .withShortName("q") - .withDescription("Cause CVS to be somewhat quiet.") - .create()) - .withOption( - obuilder - .withShortName("r") - .withDescription("Make checked-out files read-only.") - .create()) - .withOption( - obuilder - .withShortName("w") - .withDescription("Make checked-out files read-write (default).") - .create()) - .withOption( - obuilder - .withShortName("l") - .withDescription("Turn history logging off.") - .create()) - .withOption( - obuilder - .withShortName("n") - .withDescription("Do not execute anything that will change the disk.") - .create()) - .withOption( - obuilder - .withShortName("t") - .withDescription("Show trace of program execution -- try with -n.") - .create()) - .withOption( - obuilder - .withShortName("v") - .withDescription("CVS version and copyright.") - .create()) - .withOption( - obuilder - .withLongName("crlf") - .withDescription("Use the Dos line feed for text files (default).") - .create()) - .withOption( - obuilder - .withLongName("lf") - .withDescription("Use the Unix line feed for text files.") - .create()) - .withOption( - obuilder - .withShortName("T") - .withDescription("Use 'tmpdir' for temporary files.") - .withArgument(abuilder.withName("tmpdir").create()) - .create()) - .withOption( - obuilder - .withShortName("e") - .withDescription("Use 'editor' for editing log information.") - .withArgument(abuilder.withName("editor").create()) - .create()) - .withOption( - obuilder - .withShortName("d") - .withDescription("Overrides $CVSROOT as the root of the CVS tree.") - .withArgument(abuilder.withName("CVS_root").create()) - .create()) - .withOption( - obuilder - .withShortName("f") - .withDescription("Do not use the ~/.cvsrc file.") - .create()) - .withOption( - obuilder - .withShortName("z") - .withDescription("Use compression level '#' for net traffic.") - .withArgument(abuilder.withName("#").create()) - .create()) - .withOption( - obuilder - .withShortName("a") - .withDescription("Authenticate all net traffic.") - .create()) - .withOption( - obuilder - .withShortName("s") - .withDescription("Set CVS user variable.") - .withArgument(abuilder.withName("VAR=VAL").create()) - .create()) - .withOption(commands) - .create(); - - assertNotNull(cvsOptions); - } -} http://git-wip-us.apache.org/repos/asf/commons-cli/blob/9e65354f/src/test/org/apache/commons/cli2/application/LsTest.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/cli2/application/LsTest.java b/src/test/org/apache/commons/cli2/application/LsTest.java deleted file mode 100644 index 6f597bf..0000000 --- a/src/test/org/apache/commons/cli2/application/LsTest.java +++ /dev/null @@ -1,223 +0,0 @@ -/** - * Copyright 2003-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.cli2.application; - -import java.util.HashSet; -import java.util.Set; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -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 org.apache.commons.cli2.validation.EnumValidator; - -/** - * <p>Test the <code>ls</code> command. Duplicated Option types are not - * tested e.g. -a and -d are the same Option type.</p> - * - * <p>The following is the man output for 'ls'. See - * http://www.rt.com/man/ls.1.html.</p> - * - * <pre> - * LS(1) FSF LS(1) - * - * NAME ls - list directory contents - * - * SYNOPSIS ls [OPTION]... [FILE]... - * - * DESCRIPTION List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuSUX nor --sort. - * - * -a, --all do not hide entries starting with . - * - * -A, --almost-all do not list implied . and .. - * - * -b, --escape print octal escapes for nongraphic characters - * - * --block-size=SIZE use SIZE-byte blocks - * - * -B, --ignore-backups do not list implied entries ending with ~ -c sort by change time; with -l: show ctime -C list entries by columns - * - * --color[=WHEN] control whether color is used to distinguish file types. WHEN may be `never', `always', or `auto' - * - * -d, --directory list directory entries instead of contents - * - * -D, --dired generate output designed for Emacs' dired mode -f do not sort, enable -aU, disable -lst - * - * -F, --classify append indicator (one of /=@|*) to entries - * - * --format=WORD across -x, commas -m, horizontal -x, long -l, sin- gle-column -1, verbose -l, vertical -C - * - * --full-time list both full date and full time -g (ignored) - * - * -G, --no-group inhibit display of group information - * - * -h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G) - * - * -H, --si likewise, but use powers of 1000 not 1024 - * - * --indicator-style=WORD append indicator with style WORD to entry names: none (default), classify (-F), file-type (-p) - * - * -i, --inode print index number of each file - * - * -I, --ignore=PATTERN do not list implied entries matching shell PATTERN - * - * -k, --kilobytes like --block-size=1024 -l use a long listing format - * - * -L, --dereference list entries pointed to by symbolic links -m fill width with a comma separated list of entries - * - * -n, --numeric-uid-gid list numeric UIDs and GIDs instead of names - * - * -N, --literal print raw entry names (don't treat e.g. control characters specially) -o use long listing format without group info - * - * -p, --file-type append indicator (one of /=@|) to entries - * - * -q, --hide-control-chars print ? instead of non graphic characters - * - * --show-control-chars show non graphic characters as-is (default) - * - * -Q, --quote-name enclose entry names in double quotes - * - * --quoting-style=WORD use quoting style WORD for entry names: literal, shell, shell-always, c, escape - * - * -r, --reverse reverse order while sorting - * - * -R, --recursive list subdirectories recursively - * - * -s, --size print size of each file, in blocks -S sort by file size - * - * --sort=WORD extension -X, none -U, size -S, time -t, version -v status -c, time -t, atime -u, access -u, use -u - * - * --time=WORD show time as WORD instead of modification time: atime, access, use, ctime or status; use specified time as sort key if --sort=time -t sort by modification time - * - * -T, --tabsize=COLS assume tab stops at each COLS instead of 8 -u sort by last access time; with -l: show atime -U do not sort; list entries in directory order -v sort by version - * - * -w, --width=COLS assume screen width instead of current value -x list entries by lines instead of by columns -X sort alphabetically by entry extension -1 list one file per line - * - * --help display this help and exit - * - * --version output version information and exit - * - * By default, color is not used to distinguish types of files. That is equivalent to using --color=none. Using the --color option without the optional WHEN argument is equivalent to using --color=always. With --color=auto, color codes are output only if standard output is con- nected to a terminal (tty). - * </pre> - * - * @author Rob Oxspring - * @author John Keyes - */ -public class LsTest extends TestCase { - - /** Option Builder */ - private static final DefaultOptionBuilder oBuilder = - new DefaultOptionBuilder(); - - /** Argument Builder */ - private static final ArgumentBuilder aBuilder = new ArgumentBuilder(); - - /** Group Builder */ - private static final GroupBuilder gBuilder = new GroupBuilder(); - - private static Group options; - - public static Test suite() { - return new TestSuite(LsTest.class); - } - - /** - * Required ctor. - * - * @param name - * the name of the TestCase - */ - public LsTest(final String name) { - super(name); - } - - public void setUp() { - if (LsTest.options == null) { - final Option a = - oBuilder - .withShortName("a") - .withLongName("all") - .withDescription("do not hide entries starting with .") - .create(); - - final Option blockSize = - oBuilder - .withLongName("block-size") - .withRequired(false) - .withDescription("use SIZE-byte blocks") - .withArgument( - aBuilder - .withMaximum(1) - .withMinimum(1) - .withInitialSeparator('=') - .create()) - .create(); - - final Option c = - oBuilder - .withShortName("c") - .withRequired(false) - .withDescription("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") - .create(); - - final Set colors = new HashSet(); - colors.add("never"); - colors.add("always"); - colors.add("auto"); - final Option color = - oBuilder - .withLongName("color") - .withRequired(false) - .withDescription("control whether color is used to distinguish file types. WHEN may be `never', `always', or `auto'") - .withArgument( - aBuilder - .withMaximum(1) - .withMinimum(1) - .withInitialSeparator('=') - .withValidator(new EnumValidator(colors)) - .create()) - .create(); - - LsTest.options = - gBuilder - .withOption(a) - .withOption(blockSize) - .withOption(c) - .withOption(color) - .create(); - } - } - - public void testLs() throws OptionException { - // create the command line parser - Parser parser = new Parser(); - parser.setGroup(options); - CommandLine line = - parser.parse(new String[] { "--block-size=10", "--color=never" }); - - assertTrue(line.hasOption("--block-size")); - assertEquals(line.getValue("--block-size"), "10"); - assertFalse(line.hasOption("--ignore-backups")); - } -}
