Hi developers, i would like to ask what you think about the appended Unit Test patch. I have enhanced the Unit Test for CVS a "little" and would like to know if you would appreciate to see such kind of a Unit Test in this kind of direction?
If you appreciate such a Unit test i would like to continue this unit test and do some effort on enhancements and of course the JavaDoc's (and the test is not complete; JavaDoc's which is currently missing)...to get the Apache quality... I wrote it to understand the usage of the CLI2 library... I can say it's real good peace of software.... Comments, critisim is highly appreciated.... I have appended a patch based on Revision 595700 on http://svn.apache.org/repos/asf/commons/propber/cli/trunk Kind regards Karl Heinz Marbaise -- SoftwareEntwicklung Beratung Schulung Tel.: +49 (0) 2405 / 415 893 Dipl.Ing.(FH) Karl Heinz Marbaise ICQ#: 135949029 Hauptstrasse 177 USt.IdNr: DE191347579 52146 Würselen http://www.soebes.de
Index: src/test/org/apache/commons/cli2/application/CVSCommandBase.java =================================================================== --- src/test/org/apache/commons/cli2/application/CVSCommandBase.java (revision 0) +++ src/test/org/apache/commons/cli2/application/CVSCommandBase.java (revision 0) @@ -0,0 +1,45 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.cli2.application; + +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.Command; + +/** + * @author Karl Heinz Marbaise + * + */ +public class CVSCommandBase { + private Command command = null; + + protected static final DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); + protected static final ArgumentBuilder abuilder = new ArgumentBuilder(); + protected static final CommandBuilder cbuilder = new CommandBuilder(); + protected static final GroupBuilder gbuilder = new GroupBuilder(); + + public Command getCommand() { + return command; + } + + public void setCommand(Command command) { + this.command = command; + } + +} Index: src/test/org/apache/commons/cli2/application/CVSCommandLine.java =================================================================== --- src/test/org/apache/commons/cli2/application/CVSCommandLine.java (revision 0) +++ src/test/org/apache/commons/cli2/application/CVSCommandLine.java (revision 0) @@ -0,0 +1,738 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.cli2.application; + +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.commandline.Parser; +import org.apache.commons.cli2.option.Command; + +/** + * @author Karl Heinz Marbaise + * + */ +public class CVSCommandLine extends CVSCommandBase { + + private CVSUpdate cvsUpdate = null; + + private Group commands = null; + private Group cvsOptions = null; + + //All globalOptions + private Option globalOptionH = null; + private Option globalOptionQ = null; + private Option globalOptionq = null; + private Option globalOptionr = null; + private Option globalOptionw = null; + private Option globalOptionl = null; + private Option globalOptionn = null; + private Option globalOptiont = null; + private Option globalOptionv = null; + private Option globalOptionT = null; + private Option globalOptione = null; + private Option globalOptiond = null; + private Option globalOptionf = null; + private Option globalOptionz = null; + private Option globalOptiona = null; + private Option globalOptions = null; + + //All commands + private Command addCommand = null; + private Command adminCommand = null; + private Command annotateCommand = null; + private Command checkoutCommand = null; + private Command commitCommand = null; + private Command diffCommand = null; + private Command editCommand = null; + private Command editorsCommand = null; + private Command exportCommand = null; + private Command historyCommand = null; + private Command importCommand = null; + private Command initCommand = null; + private Command logCommand = null; + private Command loginCommand = null; + private Command logoutCommand = null; + private Command rdiffCommand = null; + private Command releaseCommand = null; + private Command removeCommand = null; + private Command rtagCommand = null; + private Command statusCommand = null; + private Command tagCommand = null; + private Command uneditCommand = null; + private Command updateCommand = null; + private Command watchCommand = null; + private Command watchersCommand = null; + private Command versionCommand = null; + + + private void initGlobalOptions() { + //The global globalOptions which CVS has + globalOptionH = obuilder + .withShortName("H") + .withDescription("Displays usage information for command.") + .create(); + globalOptionQ = obuilder + .withShortName("Q") + .withDescription("Cause CVS to be really quiet.") + .create(); + globalOptionq = obuilder + .withShortName("q") + .withDescription("Cause CVS to be somewhat quiet.") + .create(); + globalOptionr = obuilder + .withShortName("r") + .withDescription("Make checked-out files read-only.") + .create(); + globalOptionw = obuilder + .withShortName("w") + .withDescription("Make checked-out files read-write (default).") + .create(); + globalOptionl = obuilder + .withShortName("l") + .withDescription("Turn history logging off.") + .create(); + globalOptionn = obuilder + .withShortName("n") + .withDescription("Do not execute anything that will change the disk.") + .create(); + globalOptiont = obuilder + .withShortName("t") + .withDescription("Show trace of program execution -- try with -n.") + .create(); + globalOptionv = obuilder + .withShortName("v") + .withDescription("CVS version and copyright.") + .create(); + globalOptionT = obuilder + .withShortName("T") + .withDescription("Use 'tmpdir' for temporary files.") + .withArgument(abuilder.withName("tmpdir").create()) + .create(); + globalOptione = obuilder + .withShortName("e") + .withDescription("Use 'editor' for editing log information.") + .withArgument(abuilder.withName("editor").create()) + .create(); + globalOptiond = obuilder + .withShortName("d") + .withDescription("Overrides $CVSROOT as the root of the CVS tree.") + .withArgument(abuilder.withName("CVS_root").create()) + .create(); + globalOptionf = obuilder + .withShortName("f") + .withDescription("Do not use the ~/.cvsrc file.") + .create(); + globalOptionz = obuilder + .withShortName("z") + .withDescription("Use compression level '#' for net traffic.") + .withArgument(abuilder.withName("#").create()) + .create(); + globalOptiona = obuilder + .withShortName("a") + .withDescription("Authenticate all net traffic.") + .create(); + globalOptions = obuilder + .withShortName("s") + .withDescription("Set CVS user variable.") + .withArgument(abuilder.withName("VAR=VAL").create()) + .create(); + } + + private void initCommands() { + //The commands we have in CVS + addCommand = cbuilder + .withName("add") + .withName("ad") + .withName("new") + .withDescription("Add a new file/directory to the repository") + .create(); + + adminCommand = cbuilder + .withName("admin") + .withName("adm") + .withName("rcs") + .withDescription("Administration front end for rcs") + .create(); + + annotateCommand = cbuilder + .withName("annotate") + .withName("ann") + .withDescription("Show last revision where each line was modified") + .create(); + + checkoutCommand = cbuilder + .withName("checkout") + .withName("co") + .withName("get") + .withDescription("Checkout sources for editing") + .create(); + + commitCommand = cbuilder + .withName("commit") + .withName("ci") + .withName("com") + .withDescription("Check files into the repository") + .create(); + + diffCommand = cbuilder + .withName("diff") + .withName("di") + .withName("dif") + .withDescription("Show differences between revisions") + .create(); + + editCommand = cbuilder + .withName("edit") + .withDescription("Get ready to edit a watched file") + .create(); + + editorsCommand = cbuilder + .withName("editors") + .withDescription("See who is editing a watched file") + .create(); + + exportCommand = cbuilder + .withName("export") + .withName("exp") + .withName("ex") + .withDescription("Export sources from CVS, similar to checkout") + .create(); + + historyCommand = cbuilder + .withName("history") + .withName("hi") + .withName("his") + .withDescription("Show repository access history") + .create(); + + importCommand = cbuilder + .withName("import") + .withName("im") + .withName("imp") + .withDescription("Import sources into CVS, using vendor branches") + .create(); + + initCommand = cbuilder + .withName("init") + .withDescription("Create a CVS repository if it doesn't exist") + .create(); + + logCommand = cbuilder + .withName("log") + .withName("lo") + .withName("rlog") + .withDescription("Print out history information for files") + .create(); + + loginCommand = cbuilder + .withName("login") + .withName("logon") + .withName("lgn") + .withDescription("Prompt for password for authenticating server") + .create(); + + logoutCommand = cbuilder + .withName("logout") + .withDescription("Removes entry in .cvspass for remote repository") + .create(); + + rdiffCommand = cbuilder + .withName("rdiff") + .withName("patch") + .withName("pa") + .withDescription("Create 'patch' format diffs between releases") + .create(); + + releaseCommand = cbuilder + .withName("release") + .withName("re") + .withName("rel") + .withDescription("Indicate that a Module is no longer in use") + .create(); + + removeCommand = cbuilder + .withName("remove") + .withName("rm") + .withName("delete") + .withDescription("Remove an entry from the repository") + .create(); + + rtagCommand = cbuilder + .withName("rtag") + .withName("rt") + .withName("rfreeze") + .withDescription("Add a symbolic tag to a module") + .create(); + + statusCommand = cbuilder + .withName("status") + .withName("st") + .withName("stat") + .withDescription("Display status information on checked out files") + .create(); + + tagCommand = cbuilder + .withName("tag") + .withName("ta") + .withName("freeze") + .withDescription("Add a symbolic tag to checked out version of files") + .create(); + + uneditCommand = cbuilder + .withName("unedit") + .withDescription("Undo an edit command") + .create(); + + updateCommand = cvsUpdate.getCommand(); + + watchCommand = cbuilder + .withName("watch") + .withDescription("Set watches") + .create(); + + watchersCommand = cbuilder + .withName("watchers") + .withDescription("See who is watching a file") + .create(); + + versionCommand = cbuilder + .withName("version") + .withName("ve") + .withName("ver") + .withDescription("Show current CVS version(s)") + .create(); + } + + public void init() { + initCommands(); + initGlobalOptions(); + + commands = gbuilder + .withName("commands") + .withOption(addCommand) + .withOption(adminCommand) + .withOption(annotateCommand) + .withOption(checkoutCommand) + .withOption(commitCommand) + .withOption(diffCommand) + .withOption(editCommand) + .withOption(editorsCommand) + .withOption(exportCommand) + .withOption(historyCommand) + .withOption(importCommand) + .withOption(initCommand) + .withOption(logCommand) + .withOption(loginCommand) + .withOption(logoutCommand) + .withOption(rdiffCommand) + .withOption(releaseCommand) + .withOption(removeCommand) + .withOption(rtagCommand) + .withOption(statusCommand) + .withOption(tagCommand) + .withOption(uneditCommand) + .withOption(updateCommand) + .withOption(watchCommand) + .withOption(watchersCommand) + .withOption(versionCommand) + .create(); + + cvsOptions = gbuilder + .withName("cvs-globalOptions") + .withOption(globalOptionH) + .withOption(globalOptionQ) + .withOption(globalOptionq) + .withOption(globalOptionr) + .withOption(globalOptionw) + .withOption(globalOptionl) + .withOption(globalOptionn) + .withOption(globalOptiont) + .withOption(globalOptionv) + .withOption(globalOptionT) + .withOption(globalOptione) + .withOption(globalOptiond) + .withOption(globalOptionf) + .withOption(globalOptionz) + .withOption(globalOptiona) + .withOption(globalOptions) + .withOption(commands) + .create(); + + } + + public CVSCommandLine () { + cvsUpdate = new CVSUpdate(); + init(); + } + + public CommandLine doParseArgs(String[] args) + throws OptionException { + final Parser parser = new Parser(); + parser.setGroup(cvsOptions); + return parser.parse(args); + } + + public Command getAddCommand() { + return addCommand; + } + + public void setAddCommand(Command addCommand) { + this.addCommand = addCommand; + } + + public Command getAdminCommand() { + return adminCommand; + } + + public void setAdminCommand(Command adminCommand) { + this.adminCommand = adminCommand; + } + + public Command getAnnotateCommand() { + return annotateCommand; + } + + public void setAnnotateCommand(Command annotateCommand) { + this.annotateCommand = annotateCommand; + } + + public Command getCheckoutCommand() { + return checkoutCommand; + } + + public void setCheckoutCommand(Command checkoutCommand) { + this.checkoutCommand = checkoutCommand; + } + + public Command getCommitCommand() { + return commitCommand; + } + + public void setCommitCommand(Command commitCommand) { + this.commitCommand = commitCommand; + } + + public Group getCvsOptions() { + return cvsOptions; + } + + public void setCvsOptions(Group cvsOptions) { + this.cvsOptions = cvsOptions; + } + + public Command getDiffCommand() { + return diffCommand; + } + + public void setDiffCommand(Command diffCommand) { + this.diffCommand = diffCommand; + } + + public Command getEditCommand() { + return editCommand; + } + + public void setEditCommand(Command editCommand) { + this.editCommand = editCommand; + } + + public Command getEditorsCommand() { + return editorsCommand; + } + + public void setEditorsCommand(Command editorsCommand) { + this.editorsCommand = editorsCommand; + } + + public Command getExportCommand() { + return exportCommand; + } + + public void setExportCommand(Command exportCommand) { + this.exportCommand = exportCommand; + } + + public Option getGlobalOptiona() { + return globalOptiona; + } + + public void setGlobalOptiona(Option globalOptiona) { + this.globalOptiona = globalOptiona; + } + + public Option getGlobalOptiond() { + return globalOptiond; + } + + public void setGlobalOptiond(Option globalOptiond) { + this.globalOptiond = globalOptiond; + } + + public Option getGlobalOptione() { + return globalOptione; + } + + public void setGlobalOptione(Option globalOptione) { + this.globalOptione = globalOptione; + } + + public Option getGlobalOptionf() { + return globalOptionf; + } + + public void setGlobalOptionf(Option globalOptionf) { + this.globalOptionf = globalOptionf; + } + + public Option getGlobalOptionH() { + return globalOptionH; + } + + public void setGlobalOptionH(Option globalOptionH) { + this.globalOptionH = globalOptionH; + } + + public Option getGlobalOptionl() { + return globalOptionl; + } + + public void setGlobalOptionl(Option globalOptionl) { + this.globalOptionl = globalOptionl; + } + + public Option getGlobalOptionn() { + return globalOptionn; + } + + public void setGlobalOptionn(Option globalOptionn) { + this.globalOptionn = globalOptionn; + } + + public Option getGlobalOptionq() { + return globalOptionq; + } + + public void setGlobalOptionq(Option globalOptionq) { + this.globalOptionq = globalOptionq; + } + + public Option getGlobalOptionQ() { + return globalOptionQ; + } + + public void setGlobalOptionQ(Option globalOptionQ) { + this.globalOptionQ = globalOptionQ; + } + + public Option getGlobalOptionr() { + return globalOptionr; + } + + public void setGlobalOptionr(Option globalOptionr) { + this.globalOptionr = globalOptionr; + } + + public Option getGlobalOptions() { + return globalOptions; + } + + public void setGlobalOptions(Option globalOptions) { + this.globalOptions = globalOptions; + } + + public Option getGlobalOptiont() { + return globalOptiont; + } + + public void setGlobalOptiont(Option globalOptiont) { + this.globalOptiont = globalOptiont; + } + + public Option getGlobalOptionT() { + return globalOptionT; + } + + public void setGlobalOptionT(Option globalOptionT) { + this.globalOptionT = globalOptionT; + } + + public Option getGlobalOptionv() { + return globalOptionv; + } + + public void setGlobalOptionv(Option globalOptionv) { + this.globalOptionv = globalOptionv; + } + + public Option getGlobalOptionw() { + return globalOptionw; + } + + public void setGlobalOptionw(Option globalOptionw) { + this.globalOptionw = globalOptionw; + } + + public Option getGlobalOptionz() { + return globalOptionz; + } + + public void setGlobalOptionz(Option globalOptionz) { + this.globalOptionz = globalOptionz; + } + + public Command getHistoryCommand() { + return historyCommand; + } + + public void setHistoryCommand(Command historyCommand) { + this.historyCommand = historyCommand; + } + + public Command getImportCommand() { + return importCommand; + } + + public void setImportCommand(Command importCommand) { + this.importCommand = importCommand; + } + + public Command getInitCommand() { + return initCommand; + } + + public void setInitCommand(Command initCommand) { + this.initCommand = initCommand; + } + + public Command getLogCommand() { + return logCommand; + } + + public void setLogCommand(Command logCommand) { + this.logCommand = logCommand; + } + + public Command getLoginCommand() { + return loginCommand; + } + + public void setLoginCommand(Command loginCommand) { + this.loginCommand = loginCommand; + } + + public Command getLogoutCommand() { + return logoutCommand; + } + + public void setLogoutCommand(Command logoutCommand) { + this.logoutCommand = logoutCommand; + } + + public Command getRdiffCommand() { + return rdiffCommand; + } + + public void setRdiffCommand(Command rdiffCommand) { + this.rdiffCommand = rdiffCommand; + } + + public Command getReleaseCommand() { + return releaseCommand; + } + + public void setReleaseCommand(Command releaseCommand) { + this.releaseCommand = releaseCommand; + } + + public Command getRemoveCommand() { + return removeCommand; + } + + public void setRemoveCommand(Command removeCommand) { + this.removeCommand = removeCommand; + } + + public Command getRtagCommand() { + return rtagCommand; + } + + public void setRtagCommand(Command rtagCommand) { + this.rtagCommand = rtagCommand; + } + + public Command getStatusCommand() { + return statusCommand; + } + + public void setStatusCommand(Command statusCommand) { + this.statusCommand = statusCommand; + } + + public Command getTagCommand() { + return tagCommand; + } + + public void setTagCommand(Command tagCommand) { + this.tagCommand = tagCommand; + } + + public Command getUneditCommand() { + return uneditCommand; + } + + public void setUneditCommand(Command uneditCommand) { + this.uneditCommand = uneditCommand; + } + + public Command getUpdateCommand() { + return updateCommand; + } + + public void setUpdateCommand(Command updateCommand) { + this.updateCommand = updateCommand; + } + + public Command getVersionCommand() { + return versionCommand; + } + + public void setVersionCommand(Command versionCommand) { + this.versionCommand = versionCommand; + } + + public Command getWatchCommand() { + return watchCommand; + } + + public void setWatchCommand(Command watchCommand) { + this.watchCommand = watchCommand; + } + + public Command getWatchersCommand() { + return watchersCommand; + } + + public void setWatchersCommand(Command watchersCommand) { + this.watchersCommand = watchersCommand; + } + + public CVSUpdate getCvsUpdate() { + return cvsUpdate; + } +} Index: src/test/org/apache/commons/cli2/application/CvsTest.java =================================================================== --- src/test/org/apache/commons/cli2/application/CvsTest.java (revision 601754) +++ src/test/org/apache/commons/cli2/application/CvsTest.java (working copy) @@ -16,297 +16,139 @@ */ package org.apache.commons.cli2.application; -import junit.framework.TestCase; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.List; -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; +import org.apache.commons.cli2.CommandLine; +import org.apache.commons.cli2.OptionException; +import org.apache.commons.cli2.util.HelpFormatter; -//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(); +/** + * This Test class will do mostly (not yet) CVS globalOptions/commands + * and their checking and behaviour of the CLI2 implementation. + * + * @author Karl Heinz Marbaise + * + */ +public class CvsTest extends CvsTestBase { - 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(); + protected void setUp() throws Exception { + super.setUp(); + } - 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(); + public void testNothingGiven() { + try { + final CommandLine cl = cvscli.doParseArgs(new String[0]); + assertNotNull("The return value of the parse is null!", cl); + } catch (OptionException mve) { + fail("Unexpected exception throws " + mve.getMessage()); + } + } - assertNotNull(cvsOptions); - } + /** + * Check the simple command line: + * cvs -H + */ + public void testGlobalOptionHelp() { + final String[] args = new String[] { "-H" }; + try { + final CommandLine commandLine = cvscli.doParseArgs(args); + assertTrue(commandLine.hasOption(cvscli.getGlobalOptionH())); + } catch (OptionException e) { + fail("Unexpected exception has been thrown. " + e.getMessage()); + } + } + + /** + * Check the comnand line: + * cvs add + */ + public void testAdd() { + final String[] args = new String[] { "-H", "add" }; + try { + final CommandLine commandLine = cvscli.doParseArgs(args); + assertTrue(commandLine.hasOption(cvscli.getAddCommand())); + } catch (OptionException e) { + fail("Something has gone wrong!" + e.getMessage()); + } + } + + + /** + * Check the comnand line: + * cvs update + */ + public void testUpdate() { + final String[] args = new String[] { "update" }; + try { + final CommandLine commandLine = cvscli.doParseArgs(args); + assertTrue("There is no update command!", commandLine.hasOption(cvscli.getUpdateCommand())); + } catch (OptionException e) { + fail("Something has gone wrong!" + e.getMessage()); + } + } + + /** + * Check the comnand line (check if something has changed on the repository) + * cvs -nq update + */ + public void testCheckUpdateRepos() { + final String[] args = new String[] { "-nq", "update" }; + try { + final CommandLine commandLine = cvscli.doParseArgs(args); + assertTrue(commandLine.hasOption(cvscli.getUpdateCommand())); + assertTrue(commandLine.hasOption(cvscli.getGlobalOptionn())); + assertTrue(commandLine.hasOption(cvscli.getGlobalOptionq())); + } catch (OptionException e) { + fail("Unexpected exception thrown " + e.getMessage()); + } + } + + /** + * Check the comnand line (check if something has changed on the repository) + * <code>cvs -nq update -d</code> + */ + public void testCheckUpdateReposBuildDirectories() { + final String[] args = new String[] { "-nq", "update", "-d"}; + try { + final CommandLine commandLine = cvscli.doParseArgs(args); + assertTrue(commandLine.hasOption(cvscli.getUpdateCommand())); + assertTrue(commandLine.hasOption(cvscli.getGlobalOptionn())); + assertTrue(commandLine.hasOption(cvscli.getGlobalOptionq())); + assertTrue(commandLine.hasOption(cvscli.getCvsUpdate().getOptionUpdateBuildDirectories())); + } catch (OptionException e) { + fail("Unexpected exception thrown " + e.getMessage()); + } + } + + /** + * This test case will check the following command line: + * <code>cvs -d :local:localhost:/Repos/Test -nq update -d</code> + */ + public void testCheckUpdateGlobalOptionBuildDirectories() { + final String[] args = new String[] { "-d", ":local:localhost:/Repos/Test", "-nq", "update", "-d"}; + try { + final CommandLine commandLine = cvscli.doParseArgs(args); + assertTrue("The update command is missing", commandLine.hasOption(cvscli.getUpdateCommand())); + assertTrue("The -n global option is missing", commandLine.hasOption(cvscli.getGlobalOptionn())); + assertTrue("The -q gloabl option is missing", commandLine.hasOption(cvscli.getGlobalOptionq())); + assertTrue("The -d global option is missing", commandLine.hasOption(cvscli.getGlobalOptiond())); + List list = commandLine.getValues(cvscli.getGlobalOptiond()); + assertEquals("We expect only one parameter in the list", 1, list.size()); + assertEquals("The parameter of the global -d option is not as expected", ":local:localhost:/Repos/Test", list.get(0)); + assertTrue("The -d option after update is missing", commandLine.hasOption(cvscli.getCvsUpdate().getOptionUpdateBuildDirectories())); + } catch (OptionException e) { + fail("Unexpected exception thrown " + e.getMessage()); + } + } + + public void testHelpOutput() { + final StringWriter out = new StringWriter(); + final HelpFormatter helpFormatter = new HelpFormatter(); + helpFormatter.setGroup(cvscli.getCvsOptions()); + helpFormatter.setPrintWriter(new PrintWriter(out)); + helpFormatter.printHelp(); + System.out.println(out); + } } Index: src/test/org/apache/commons/cli2/application/CvsTestBase.java =================================================================== --- src/test/org/apache/commons/cli2/application/CvsTestBase.java (revision 0) +++ src/test/org/apache/commons/cli2/application/CvsTestBase.java (revision 0) @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.cli2.application; + +import junit.framework.TestCase; + +/** + * @author Karl Heinz Marbaise + * + */ +public class CvsTestBase extends TestCase { + + protected CVSCommandLine cvscli = null; + + protected void setUp() throws Exception { + cvscli = new CVSCommandLine(); + } + +} Index: src/test/org/apache/commons/cli2/application/CVSUpdate.java =================================================================== --- src/test/org/apache/commons/cli2/application/CVSUpdate.java (revision 0) +++ src/test/org/apache/commons/cli2/application/CVSUpdate.java (revision 0) @@ -0,0 +1,250 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.cli2.application; + +import org.apache.commons.cli2.Group; +import org.apache.commons.cli2.Option; +import org.apache.commons.cli2.option.Command; + +/** + * This class will hold everything which is in relationship with + * the "cvs update" command. + * + * @author Karl Heinz Marbaise + * + */ +public class CVSUpdate extends CVSCommandBase { + + private Option optionUpdateBuildDirectories = null; + private Option optionUpdateResetSticky = null; + private Option optionUpdatePruneEmptyDirectories = null; + private Option optionUpdateOverwriteLocallyModified = null; + private Option optionUpdateForceHead = null; + private Option optionUpdateLocalDirectoriesOnly = null; + private Option optionUpdateProcessDirectoriesRecursivley = null; + private Option optionUpdateSendUpdatesToStdOut = null; + private Option optionUpdateUseRCSKOpt = null; + private Option optionUpdateRevision = null; + private Option optionUpdateDate = null; + + public CVSUpdate() { + setCommand(createCommand()); + } + + private Command createCommand() { + /* + Usage: cvs update [-APCdflRp] [-k kopt] [-r rev] [-D date] [-j rev] [-I ign] [-W spec] [files...] + -A Reset any sticky tags/date/kopts. + -P Prune empty directories. + -C Overwrite locally modified files with clean repository copies. + -d Build directories, like checkout does. + -f Force a head revision match if tag/date not found. + -l Local directory only, no recursion. + -R Process directories recursively. + -p Send updates to standard output (avoids stickiness). + -k kopt Use RCS kopt -k option on checkout. (is sticky) + -r rev Update using specified revision/tag (is sticky). + -D date Set date to update from (is sticky). + -j rev Merge in changes made between current revision and rev. + -I ign More files to ignore (! to reset). + -W spec Wrappers specification line. + (Specify the --help global option for a list of other help globalOptions + */ + + optionUpdateResetSticky = obuilder + .withShortName("A") + .withDescription("Reset any sticky tags/date/kopts.") + .create(); + + optionUpdatePruneEmptyDirectories = obuilder + .withShortName("P") + .withDescription("Prune empty directories.") + .create(); + + optionUpdateOverwriteLocallyModified = obuilder + .withShortName("C") + .withDescription("Overwrite locally modifiled files with clean repository copies") + .create(); + + optionUpdateBuildDirectories = obuilder + .withShortName("d") + .withDescription("Build directories, like checkout does.") + .create(); + + optionUpdateForceHead = obuilder + .withShortName("f") + .withDescription("Force a head revision match if tag/date not found") + .create(); + + optionUpdateLocalDirectoriesOnly = obuilder + .withShortName("l") + .withDescription("Local directory only, no recursion.") + .create(); + + optionUpdateProcessDirectoriesRecursivley = obuilder + .withShortName("R") + .withDescription("Process directories recursively.") + .create(); + + optionUpdateSendUpdatesToStdOut = obuilder + .withShortName("p") + .withDescription("Send updates to standard output (avoids stickiness).") + .create(); + + optionUpdateUseRCSKOpt = obuilder + .withShortName("k") + .withDescription("kopt Use RCS kopt -k option on checkout. (is sticky)") + .create(); + + optionUpdateRevision = obuilder + .withShortName("r") + .withDescription("Update using specified revision/tag (is sticky).") + .create(); + optionUpdateDate = obuilder + .withShortName("D") + .withDescription("Set date to update from (is sticky).") + .create(); + + Group optionUpdate = gbuilder + .withOption(optionUpdateBuildDirectories) + .withOption(optionUpdateResetSticky) + .withOption(optionUpdatePruneEmptyDirectories) + .withOption(optionUpdateOverwriteLocallyModified) + .withOption(optionUpdateForceHead) + .withOption(optionUpdateLocalDirectoriesOnly) + .withOption(optionUpdateProcessDirectoriesRecursivley) + .withOption(optionUpdateSendUpdatesToStdOut) + .withOption(optionUpdateUseRCSKOpt) + .withOption(optionUpdateRevision) + .withOption(optionUpdateDate) + .create(); + + return cbuilder + .withName("update") + .withName("up") + .withName("upd") + .withDescription("Bring work tree in sync with repository") + .withChildren(optionUpdate) + .create(); + } + + + public Option getOptionUpdateDate() { + return optionUpdateDate; + } + + public void setOptionUpdateDate(Option optionUpdateDate) { + this.optionUpdateDate = optionUpdateDate; + } + + public Option getOptionUpdateProcessDirectoriesRecursivley() { + return optionUpdateProcessDirectoriesRecursivley; + } + + public void setOptionUpdateProcessDirectoriesRecursivley( + Option optionUpdateProcessDirectoriesRecursivley) { + this.optionUpdateProcessDirectoriesRecursivley = optionUpdateProcessDirectoriesRecursivley; + } + + public Option getOptionUpdateRevision() { + return optionUpdateRevision; + } + + public void setOptionUpdateRevision(Option optionUpdateRevision) { + this.optionUpdateRevision = optionUpdateRevision; + } + + public Option getOptionUpdateSendUpdatesToStdOut() { + return optionUpdateSendUpdatesToStdOut; + } + + public void setOptionUpdateSendUpdatesToStdOut( + Option optionUpdateSendUpdatesToStdOut) { + this.optionUpdateSendUpdatesToStdOut = optionUpdateSendUpdatesToStdOut; + } + + public Option getOptionUpdateUseRCSKOpt() { + return optionUpdateUseRCSKOpt; + } + + public void setOptionUpdateUseRCSKOpt(Option optionUpdateUseRCSKOpt) { + this.optionUpdateUseRCSKOpt = optionUpdateUseRCSKOpt; + } + + public Option getOptionUpdateBuildDirectories() { + return optionUpdateBuildDirectories; + } + + + public void setOptionUpdateBuildDirectories(Option optionUpdateBuildDirectories) { + this.optionUpdateBuildDirectories = optionUpdateBuildDirectories; + } + + + public Option getOptionUpdateForceHead() { + return optionUpdateForceHead; + } + + + public void setOptionUpdateForceHead(Option optionUpdateForceHead) { + this.optionUpdateForceHead = optionUpdateForceHead; + } + + + public Option getOptionUpdateLocalDirectoriesOnly() { + return optionUpdateLocalDirectoriesOnly; + } + + + public void setOptionUpdateLocalDirectoriesOnly( + Option optionUpdateLocalDirectoriesOnly) { + this.optionUpdateLocalDirectoriesOnly = optionUpdateLocalDirectoriesOnly; + } + + + public Option getOptionUpdateOverwriteLocallyModified() { + return optionUpdateOverwriteLocallyModified; + } + + + public void setOptionUpdateOverwriteLocallyModified( + Option optionUpdateOverwriteLocallyModified) { + this.optionUpdateOverwriteLocallyModified = optionUpdateOverwriteLocallyModified; + } + + + public Option getOptionUpdatePruneEmptyDirectories() { + return optionUpdatePruneEmptyDirectories; + } + + + public void setOptionUpdatePruneEmptyDirectories( + Option optionUpdatePruneEmptyDirectories) { + this.optionUpdatePruneEmptyDirectories = optionUpdatePruneEmptyDirectories; + } + + + public Option getOptionUpdateResetSticky() { + return optionUpdateResetSticky; + } + + + public void setOptionUpdateResetSticky(Option optionUpdateResetSticky) { + this.optionUpdateResetSticky = optionUpdateResetSticky; + } + +}
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]