Index: maven-commandline-plugin/src/test/org/codelutin/option/def/DefinitionParserTest.java
diff -u /dev/null maven-commandline-plugin/src/test/org/codelutin/option/def/DefinitionParserTest.java:1.1
--- /dev/null Sun Mar 23 00:23:06 2008
+++ maven-commandline-plugin/src/test/org/codelutin/option/def/DefinitionParserTest.java Sun Mar 23 00:23:00 2008
@@ -0,0 +1,158 @@
+/**
+ * ##% Copyright (C) 2002, 2007 Code Lutin This program is free software; you
+ * can redistribute it and/or modify it under the terms of the GNU General
+ * Public License as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. This program is
+ * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details. You
+ * should have received a copy of the GNU General Public License along with this
+ * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place
+ * - Suite 330, Boston, MA 02111-1307, USA. ##%*
+ */
+package org.codelutin.option.def;
+
+import junit.framework.TestCase;
+import org.codelutin.i18n.I18n;
+import org.codelutin.option.def.ParserUtilForTest;
+import org.codelutin.option.def.DefinitionParserFromProperties;
+
+import java.io.File;
+
+/**
+ * DefinitionParser Tester.
+ *
+ * @author chemit
+ * @version 1.0
+ * @since
11/18/2007
+ */
+public class DefinitionParserTest extends TestCase {
+
+ DefinitionParser parser;
+ File file;
+ String optionName;
+
+ static boolean i18nInit = false;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ if (!i18nInit) {
+ DefaultOptionAction.skipDefault = true;
+
+ I18n.init();
+ i18nInit = true;
+ }
+ }
+
+ public void testNoOptions() throws Exception {
+ file = ParserUtilForTest.initFileMock("", "option", "testNoOptions.properties");
+ parser = DefinitionParser.doParse(DefinitionParserFromProperties.class, file);
+ assertTrue(parser.getOptions().length == 0);
+ }
+
+ public void testOneOption() throws Exception {
+
+ /*STRING optionName;
+ optionName = "testOneOptions0";
+ file = initFileMock(optionName, "--testOneOptions0", "with no args and one alias");
+ parser = DefinitionParser.doParse(properties, file);
+ assertEquals(1, parser.getDefinitions().length);
+ assertEquals(1, parser.getDefinitions()[0].getAlias().length);
+ assertEquals("--" + optionName, parser.getDefinitions()[0].getAlias()[0]);
+ assertEquals(0, parser.getDefinitions()[0].getGroups().length);
+
+ optionName = "testOneOptions00";
+ file = initFileMock(optionName, "--testOneOptions00|-one0", "with no args and two alias");
+ parser = DefinitionParser.doParse(properties, file);
+ assertEquals(1, parser.getDefinitions().length);
+ assertEquals(2, parser.getDefinitions()[0].getAlias().length);
+ assertEquals("--" + optionName, parser.getDefinitions()[0].getAlias()[0]);
+ assertEquals("-one0", parser.getDefinitions()[0].getAlias()[1]);
+ assertEquals(0, parser.getDefinitions()[0].getGroups().length);
+
+ optionName = "testOneOptions000";
+ file = initFileMock(optionName, "--testOneOptions000|-one0|-o0", "with no args and three alias");
+ parser = DefinitionParser.doParse(properties, file);
+ assertEquals(1, parser.getDefinitions().length);
+ assertEquals(3, parser.getDefinitions()[0].getAlias().length);
+ assertEquals("--" + optionName, parser.getDefinitions()[0].getAlias()[0]);
+ assertEquals("-one0", parser.getDefinitions()[0].getAlias()[1]);
+ assertEquals("-o0", parser.getDefinitions()[0].getAlias()[2]);
+ assertEquals(0, parser.getDefinitions()[0].getGroups().length);
+
+ optionName = "testOneOptions1";
+ file = initFileMock(optionName, "--testOneOptions1|-one1 ", "with one group of three constant and two alias");
+ parser = DefinitionParser.doParse(properties, file);
+ assertEquals(1, parser.getDefinitions().length);
+ assertEquals(2, parser.getDefinitions()[0].getAlias().length);
+ assertEquals("--" + optionName, parser.getDefinitions()[0].getAlias()[0]);
+ assertEquals("-one1", parser.getDefinitions()[0].getAlias()[1]);
+ assertEquals(3, parser.getDefinitions()[0].getGroups().length);
+
+
+ optionName = "testOneOptions2";
+ file = initFileMock(optionName, "--testOneOptions2|-one2 ", "with one group of 5 valued args and two alias");
+ parser = DefinitionParser.doParse(properties, file);
+ assertEquals(1, parser.getDefinitions().length);
+ assertEquals(2, parser.getDefinitions()[0].getAlias().length);
+ assertEquals("--" + optionName, parser.getDefinitions()[0].getAlias()[0]);
+ assertEquals("-one2", parser.getDefinitions()[0].getAlias()[1]);
+ assertEquals(5, parser.getDefinitions()[0].getGroups().length);
+
+ optionName = "testOneOptions3";
+ file = initFileMock(optionName, "--testOneOptions3|-one3 ", "with one group of 6 namedAndValued args and two alias");
+ parser = DefinitionParser.doParse(properties, file);
+ assertEquals(1, parser.getDefinitions().length);
+ assertEquals(2, parser.getDefinitions()[0].getAlias().length);
+ assertEquals("--" + optionName, parser.getDefinitions()[0].getAlias()[0]);
+ assertEquals("-one3", parser.getDefinitions()[0].getAlias()[1]);
+ assertEquals(6, parser.getDefinitions()[0].getGroups().length);
+
+ optionName = "testOneOptions4";
+ file = initFileMock(optionName, "--testOneOptions4|-one4 ", "with one group of 14 args (3 constants, 5 valued, 6 namedAndValued) and two alias");
+ parser = DefinitionParser.doParse(properties, file);
+ //printParserDetails();
+
+ assertEquals(1, parser.getDefinitions().length);
+ assertEquals(2, parser.getDefinitions()[0].getAlias().length);
+ assertEquals("--" + optionName, parser.getDefinitions()[0].getAlias()[0]);
+ assertEquals("-one4", parser.getDefinitions()[0].getAlias()[1]);
+ assertEquals(14, parser.getDefinitions()[0].getGroups().length);*/
+ }
+
+ public void testOneOptionArgumentCardinalite() throws Exception {
+
+ optionName = "testArgumentConstantCardinalite00005";
+ file = ParserUtilForTest.initFileMock(optionName, "option", "-testArgumentConstantCardinalite00005 ");
+ parser = DefinitionParser.doParse(DefinitionParserFromProperties.class, file);
+ ParserUtilForTest.assertError(parser, 1, 0);
+
+ optionName = "testArgumentConstantCardinalite00015";
+ file = ParserUtilForTest.initFileMock(optionName, "option", "-testArgumentConstantCardinalite00015 [constant]");
+ parser = DefinitionParser.doParse(DefinitionParserFromProperties.class, file);
+ ParserUtilForTest.assertError(parser, 1, 0);
+
+ optionName = "testArgumentValuedCardinalite00003";
+ file = ParserUtilForTest.initFileMock(optionName, "option", "-testArgumentValuedCardinalite00003 ");
+ parser = DefinitionParser.doParse(DefinitionParserFromProperties.class, file);
+ ParserUtilForTest.assertError(parser, 1, 0);
+
+ optionName = "testArgumentValuedCardinalite00004";
+ file = ParserUtilForTest.initFileMock(optionName, "option", "-testArgumentValuedCardinalite00004 ");
+ parser = DefinitionParser.doParse(DefinitionParserFromProperties.class, file);
+ ParserUtilForTest.assertError(parser, 1, 0);
+
+ optionName = "testArgumentValuedCardinalite00010";
+ file = ParserUtilForTest.initFileMock(optionName, "option", "-testArgumentValuedCardinalite00010 [string:String{0,5}]");
+ parser = DefinitionParser.doParse(DefinitionParserFromProperties.class, file);
+ ParserUtilForTest.assertError(parser, 1, 0);
+
+ optionName = "testArgumentValuedCardinalite00011";
+
+ file = ParserUtilForTest.initFileMock(optionName, "option", "-testArgumentValuedCardinalite00011 [string:String*]");
+ parser = DefinitionParser.doParse(DefinitionParserFromProperties.class, file);
+ ParserUtilForTest.assertError(parser, 1, 0);
+ }
+
+}
Index: maven-commandline-plugin/src/test/org/codelutin/option/def/ParserUtilForTest.java
diff -u /dev/null maven-commandline-plugin/src/test/org/codelutin/option/def/ParserUtilForTest.java:1.1
--- /dev/null Sun Mar 23 00:23:06 2008
+++ maven-commandline-plugin/src/test/org/codelutin/option/def/ParserUtilForTest.java Sun Mar 23 00:23:00 2008
@@ -0,0 +1,112 @@
+/**
+ * ##% Copyright (C) 2002, 2007 Code Lutin This program is free software; you
+ * can redistribute it and/or modify it under the terms of the GNU General
+ * Public License as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. This program is
+ * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details. You
+ * should have received a copy of the GNU General Public License along with this
+ * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place
+ * - Suite 330, Boston, MA 02111-1307, USA. ##%*
+ */
+package org.codelutin.option.def;
+
+import junit.framework.Assert;
+import org.codelutin.i18n.I18n;
+import org.codelutin.log.LutinLogFactory;
+import org.codelutin.option.def.DefinitionParser;
+import org.codelutin.option.OptionParser;
+import org.codelutin.option.OptionParserResult;
+import org.codelutin.option.ParserFailedException;
+import org.codelutin.util.FileUtil;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.Writer;
+
+/**
+ * Some usefull methods for testing OptionPArser and others.
+ *
+ * @author chemit
+ */
+
+public class ParserUtilForTest extends Assert {
+
+ static boolean first;
+ static final String HERE = new File("").getAbsolutePath();
+ static final String PROPERTIES_FILE_PATH = HERE + "/target/gen/test-classes/";
+
+ public static void initI18n() {
+ if (!first) {
+ I18n.init();
+ System.setProperty("org.apache.commons.logging.LogFactory", LutinLogFactory.class.getName());
+ first = true;
+
+ }
+ }
+
+ public static void assertError(DefinitionParser parser, int nbOptions, int nbErrors) throws IOException {
+ Writer writer = new StringWriter();
+ parser.printErrors(writer);
+ System.out.println(writer.toString());
+ writer.flush();
+ writer.close();
+ assertEquals(nbErrors != 0, parser.hasFailed());
+ assertEquals(nbOptions, parser.getOptions().length);
+ assertEquals(nbErrors, parser.getErrors().length);
+ }
+
+ public static void assertError(OptionParser parser, int nbOptions, int nbErrors, int nbUnused) throws IOException {
+ OptionParserResult result = parser.getLastResult();
+ ParserFailedException e = result.getError();
+ Writer writer = new StringWriter();
+ writer.append("\n=============================================== nbOptions:");
+ writer.append(String.valueOf(nbOptions));
+ writer.append(", nbErrors:").append(String.valueOf(nbErrors));
+ writer.append(", nbUnused:").append(String.valueOf(nbUnused)).append(", args:").append(result.getUnusedArguments().values().toString()).append("\n");
+ if (e != null) {
+ e.printStackTrace(new PrintWriter(writer));
+ }
+ writer.flush();
+ System.out.println(writer.toString());
+ writer.close();
+
+ assertEquals(nbOptions, result.size());
+ assertEquals(nbErrors, e == null ? 0 : e.getNbErrors());
+ assertEquals(nbUnused, result.getNbUnsued());
+ }
+
+
+ public static File initFileMock(String key, String type, String... defs) throws IOException {
+ //assertTrue(defs.length % 2 == 0);
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < defs.length; i++) {
+ String definition = defs[i];
+ //STRING description = defs[i + 1];
+ builder.append(key);
+ if (i > 0) {
+ builder.append(i);
+ }
+ builder.append(".").append(type).append(".definition=").append(definition).append("\n").append(key);
+ if (i > 0) {
+ builder.append(i);
+ }
+ }
+ String content = builder.toString();
+ return initFileMock0(PROPERTIES_FILE_PATH, key + ".properties", content);
+ }
+
+ protected static File initFileMock0(String prefix, String s, String content) throws IOException {
+ File file = new File(prefix + s);
+ if (!file.getParentFile().exists()) {
+ file.getParentFile().mkdirs();
+ }
+ file.createNewFile();
+ FileUtil.writeString(file, content);
+ file.deleteOnExit();
+ return file;
+ }
+}
Index: maven-commandline-plugin/src/test/org/codelutin/option/def/DefinitionParserBadOptionTest.java
diff -u /dev/null maven-commandline-plugin/src/test/org/codelutin/option/def/DefinitionParserBadOptionTest.java:1.1
--- /dev/null Sun Mar 23 00:23:06 2008
+++ maven-commandline-plugin/src/test/org/codelutin/option/def/DefinitionParserBadOptionTest.java Sun Mar 23 00:23:00 2008
@@ -0,0 +1,202 @@
+/**
+ * ##% Copyright (C) 2002, 2007 Code Lutin This program is free software; you
+ * can redistribute it and/or modify it under the terms of the GNU General
+ * Public License as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. This program is
+ * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details. You
+ * should have received a copy of the GNU General Public License along with this
+ * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place
+ * - Suite 330, Boston, MA 02111-1307, USA. ##%*
+ */
+package org.codelutin.option.def;
+
+import junit.framework.TestCase;
+import org.codelutin.option.def.ParserUtilForTest;
+import org.codelutin.option.def.DefinitionParserFromProperties;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * DefinitionParser Tester.
+ *
+ * @author chemit
+ * @version 1.0
+ * @since