Skip to content

Commit d89e42a

Browse files
committed
Added a test for the Groovy command line
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/cli/branches/cli-1.x@683156 13f79535-47bb-0310-9956-ffa450edef68
1 parent 55db14e commit d89e42a

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

src/test/org/apache/commons/cli/ApplicationTest.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,71 @@ public void testAnt() throws Exception {
103103
assertTrue( line.hasOption( "projecthelp") );
104104
}
105105

106+
public void testGroovy() throws Exception {
107+
Options options = new Options();
108+
109+
options.addOption(
110+
OptionBuilder.withLongOpt("define").
111+
withDescription("define a system property").
112+
hasArg(true).
113+
withArgName("name=value").
114+
create('D'));
115+
options.addOption(
116+
OptionBuilder.hasArg(false)
117+
.withDescription("usage information")
118+
.withLongOpt("help")
119+
.create('h'));
120+
options.addOption(
121+
OptionBuilder.hasArg(false)
122+
.withDescription("debug mode will print out full stack traces")
123+
.withLongOpt("debug")
124+
.create('d'));
125+
options.addOption(
126+
OptionBuilder.hasArg(false)
127+
.withDescription("display the Groovy and JVM versions")
128+
.withLongOpt("version")
129+
.create('v'));
130+
options.addOption(
131+
OptionBuilder.withArgName("charset")
132+
.hasArg()
133+
.withDescription("specify the encoding of the files")
134+
.withLongOpt("encoding")
135+
.create('c'));
136+
options.addOption(
137+
OptionBuilder.withArgName("script")
138+
.hasArg()
139+
.withDescription("specify a command line script")
140+
.create('e'));
141+
options.addOption(
142+
OptionBuilder.withArgName("extension")
143+
.hasOptionalArg()
144+
.withDescription("modify files in place; create backup if extension is given (e.g. \'.bak\')")
145+
.create('i'));
146+
options.addOption(
147+
OptionBuilder.hasArg(false)
148+
.withDescription("process files line by line using implicit 'line' variable")
149+
.create('n'));
150+
options.addOption(
151+
OptionBuilder.hasArg(false)
152+
.withDescription("process files line by line and print result (see also -n)")
153+
.create('p'));
154+
options.addOption(
155+
OptionBuilder.withArgName("port")
156+
.hasOptionalArg()
157+
.withDescription("listen on a port and process inbound lines")
158+
.create('l'));
159+
options.addOption(
160+
OptionBuilder.withArgName("splitPattern")
161+
.hasOptionalArg()
162+
.withDescription("split lines using splitPattern (default '\\s') using implicit 'split' variable")
163+
.withLongOpt("autosplit")
164+
.create('a'));
165+
166+
Parser parser = new PosixParser();
167+
CommandLine line = parser.parse(options, new String[] { "-e", "println 'hello'" });
168+
169+
assertTrue(line.hasOption('e'));
170+
assertEquals("println 'hello'", line.getOptionValue('e'));
171+
}
172+
106173
}

0 commit comments

Comments
 (0)