commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r683156 - /commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ApplicationTest.java
Date Wed, 06 Aug 2008 08:19:30 GMT
Author: ebourg
Date: Wed Aug  6 01:19:28 2008
New Revision: 683156

URL: http://svn.apache.org/viewvc?rev=683156&view=rev
Log:
Added a test for the Groovy command line

Modified:
    commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ApplicationTest.java

Modified: commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ApplicationTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ApplicationTest.java?rev=683156&r1=683155&r2=683156&view=diff
==============================================================================
--- commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ApplicationTest.java
(original)
+++ commons/proper/cli/branches/cli-1.x/src/test/org/apache/commons/cli/ApplicationTest.java
Wed Aug  6 01:19:28 2008
@@ -103,4 +103,71 @@
         assertTrue( line.hasOption( "projecthelp") );
     }
 
+    public void testGroovy() throws Exception {
+        Options options = new Options();
+
+        options.addOption(
+            OptionBuilder.withLongOpt("define").
+                withDescription("define a system property").
+                hasArg(true).
+                withArgName("name=value").
+                create('D'));
+        options.addOption(
+            OptionBuilder.hasArg(false)
+            .withDescription("usage information")
+            .withLongOpt("help")
+            .create('h'));
+        options.addOption(
+            OptionBuilder.hasArg(false)
+            .withDescription("debug mode will print out full stack traces")
+            .withLongOpt("debug")
+            .create('d'));
+        options.addOption(
+            OptionBuilder.hasArg(false)
+            .withDescription("display the Groovy and JVM versions")
+            .withLongOpt("version")
+            .create('v'));
+        options.addOption(
+            OptionBuilder.withArgName("charset")
+            .hasArg()
+            .withDescription("specify the encoding of the files")
+            .withLongOpt("encoding")
+            .create('c'));
+        options.addOption(
+            OptionBuilder.withArgName("script")
+            .hasArg()
+            .withDescription("specify a command line script")
+            .create('e'));
+        options.addOption(
+            OptionBuilder.withArgName("extension")
+            .hasOptionalArg()
+            .withDescription("modify files in place; create backup if extension is given
(e.g. \'.bak\')")
+            .create('i'));
+        options.addOption(
+            OptionBuilder.hasArg(false)
+            .withDescription("process files line by line using implicit 'line' variable")
+            .create('n'));
+        options.addOption(
+            OptionBuilder.hasArg(false)
+            .withDescription("process files line by line and print result (see also -n)")
+            .create('p'));
+        options.addOption(
+            OptionBuilder.withArgName("port")
+            .hasOptionalArg()
+            .withDescription("listen on a port and process inbound lines")
+            .create('l'));
+        options.addOption(
+            OptionBuilder.withArgName("splitPattern")
+            .hasOptionalArg()
+            .withDescription("split lines using splitPattern (default '\\s') using implicit
'split' variable")
+            .withLongOpt("autosplit")
+            .create('a'));
+
+        Parser parser = new PosixParser();
+        CommandLine line = parser.parse(options, new String[] { "-e", "println 'hello'" });
+
+        assertTrue(line.hasOption('e'));
+        assertEquals("println 'hello'", line.getOptionValue('e'));
+    }
+
 }



Mime
View raw message