A
download CliBuilderTest.groovy
Language: NonCode
LOC: 0
Project Info
Core(groovy-core)
Server: Groovy
Type: svn
...‑core\src\test\groovy\util\
   AllTestSuiteTest.groovy
   AntTest.groovy
   AntTest.xml
   BuilderSupportTest.groovy
   CliBuilderTest.groovy
   ConfigSlurperTest.groovy
   Dummy.java
   DummyMBean.java
   EmptyScriptTest.groovy
   EvalTest.java
   FileNameFinderTest.groovy
   GroovyTestCaseTest.groovy
   MBeanTest.java
   MessageSourceTest.groovy
   ...geSourceTest.properties
   NavToWiki.groovy
   NodeTest.groovy
   OrderByTest.groovy
   ProxyTest.groovy
   SpoofTask.java
   SpoofTaskContainer.java
   StringTestUtil.groovy
   XmlParserTest.groovy
   XmlSlurperTest.groovy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
/*
 *  Copyright 2003-2007 the original author or authors.
 *
 *  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 groovy.util

import org.apache.commons.cli.GnuParser
import org.apache.commons.cli.Option
import org.apache.commons.cli.OptionBuilder
import org.apache.commons.cli.PosixParser
import org.apache.commons.cli.BasicParser

/**
 *  Test class for the CliBuilder -- but then that is obvious from the name :-)
 *
 *  <p>There appear to be issues when using the <code>PosixParser</code> &ndash; when an option with a
 *  parameter is passed using a long form and a single letter parameter of some sort has been declared (the
 *  problem does not occur if no single letter option has been declared) then the value "--" is returned
 *  instead of the option parameter value.  This problem does not happen using the
 *  <code>GnuParser</code>.</p>
 *
 *  <p>There appears to be an issue with <code>GnuParser</code> &ndash; if only a long option is defined
 *  then the usual Groovy syntax for accessing the option fails to work.  It is fine if a short option of
 *  some sort is defined.  This must be a <code>CliBuilder</code>/<code>OptionAccessor</code> problem.  This
 *  problem does not happen with the <code>PosixParser</code>.</p>
 *
 *  <p>Commons CLI 1.0 appears not to be able to access arguments using a long name, if that option has a
 *  short name -- in this case access is only using a short name.  This means it is possible to work with
 *  long name option if and only if they have no short name.</p>
 *
 *  <p>Commons CLI 1.1 whilst it has fixed most of the problems in 1.0, appears to have a broken
 *  getOptionValues -- it returns only the first value -- and so is worse than useless.</p>
 *
 *  <p>1.0 PosixBuilder removes unrecognized single letter options silently.  1.1 version may also do this.
 *  GnuParser behaves according to the <code>stopAtNonOption</code> parameter -- throw
 *  <code>UnrecognizedOptionException</code> when <code>false</code>, terminate parse leaving everything
 *  following unprocessed if <code>true</code>.
 *
 *  @author Dierk König
 *  @author Russel Winder
 */

//// Tests marked with 4 slashes work in Commons CLI 1.1 but not in 1.0.  There are other differences, read
//// the comments.

class CliBuilderTest extends GroovyTestCase {

  private StringWriter stringWriter
  private PrintWriter printWriter

  void setUp ( ) {
    stringWriter = new StringWriter ( )
    printWriter = new PrintWriter ( stringWriter )
  }

  private final expectedParameter = 'ASCII'
  private final usageString =  'groovy [option]* filename'

  private void runSample ( parser , optionList ) {
    def cli = new CliBuilder ( usage : usageString , writer : printWriter , parser : parser )
    cli.h ( longOpt : 'help', 'usage information' )
    cli.c ( argName : 'charset' , args :1 , longOpt : 'encoding' , 'character encoding' )
    cli.i ( argName : 'extension' , optionalArg : true, 'modify files in place, create backup if extension is given (e.g. \'.bak\')' )
    def stringified = cli.options.toString ( )
    assert stringified =~ /i=. option: i  :: modify files in place, create backup if extension is given/
    assert stringified =~ /c=. option: c encoding  :: character encoding/
    assert stringified =~ /h=. option: h help  :: usage information/
    assert stringified =~ /encoding=. option: c encoding  :: character encoding/
    assert stringified =~ /help=. option: h help  :: usage information/
    def options = cli.parse ( optionList )
    assert options.hasOption ( 'h' )
    ////assert options.hasOption ( 'help' )
    assert options.h
    ////assert options.help
    if ( options.h ) { cli.usage ( ) }
    def expectedUsage = """usage: $usageString
 -c,--encoding <charset>   character encoding
 -h,--help                 usage information
 -i                        modify files in place, create backup if
                           extension is given (e.g. '.bak')"""
    assertEquals ( expectedUsage , stringWriter.toString ( ).tokenize ( '\r\n' ).join ( '\n' ) )
    stringWriter = new StringWriter ( )
    printWriter = new PrintWriter ( stringWriter )
    cli.writer = printWriter
    ////if ( options.help ) { cli.usage ( ) }
    ////assertEquals ( expectedUsage , stringWriter.toString ( ).tokenize ( '\r\n' ).join ( '\n' ) )
    assert options.hasOption ( 'c' )
    assert options.c
    ////assert options.hasOption ( 'encoding' )
    ////assert options.encoding
    assertEquals ( expectedParameter, options.getOptionValue ( 'c' ) )
    assertEquals ( expectedParameter, options.c )
    ////assertEquals ( expectedParameter, options.getOptionValue ( 'encoding' ) )
    ////assertEquals ( expectedParameter, options.encoding )
    assertEquals ( false, options.noSuchOptionGiven )
    assertEquals ( false, options.hasOption ( 'noSuchOptionGiven' ) )
    assertEquals ( false, options.x )
    assertEquals ( false, options.hasOption ( 'x' ) )
  }
  void testSampleShort_BasicParser ( ) {
    runSample ( new BasicParser ( ) , [ '-h' , '-c' , expectedParameter ] )
  }
  void testSampleShort_GnuParser ( ) {
    runSample ( new GnuParser ( ) , [ '-h' , '-c' , expectedParameter ] )
  }
  void testSampleShort_PosixParser ( ) {
    runSample ( new PosixParser ( ) , [ '-h' , '-c' , expectedParameter ] )
  }
  void testSampleLong_BasicParser ( ) {
    runSample ( new GnuParser ( ) , [ '--help' , '--encoding' , expectedParameter ] )
  }
  void testSampleLong_GnuParser ( ) {
    runSample ( new GnuParser ( ) , [ '--help' , '--encoding' , expectedParameter ] )
  }
  /*
   *  Cannot run this test because of the "--" instead of "ASCII" problem.  See
   *  testLongAndShortOpts_PosixParser below.  This is a 1.0 and a 1.1 problem.
   */
  void XXX_testSampleLong_PosixParser ( ) {
    runSample ( new PosixParser ( ) , [ '--help' , '--encoding' , expectedParameter ] )
  }

  void testMultipleArgs ( ) {
    def cli = new CliBuilder ( )
    cli.a ( longOpt : 'arg' , args : 2 , valueSeparator : ',' as char , 'arguments' )
    def options = cli.parse ( [ '-a' , '1,2' ] )
    assertEquals ( '1' , options.a )
    assertEquals ( [ '1' , '2' ] , options.as )
    ////assertEquals ( '1' , options.arg )
    ////assertEquals ( [ '1' , '2' ] , options.args )
  }

  void testArgs ( ) {
    def cli = new CliBuilder ( )
    cli.a ( [:] , '' )
    def options = cli.parse ( [ '-a' , '1' , '2' ] )
    assertEquals ( [ '1' , '2' ] , options.arguments ( ) )
  }

  void testFailedParsePrintsUsage ( ) {
    def cli = new CliBuilder ( writer : printWriter )
    cli.x ( required : true , 'message' )
    def options = cli.parse ( [ ] )
    /*
     *  Error messages are slightly different between 1.0 and 1.1.
     *
    assertEquals ( '''error: Missing required option: x
usage: groovy
 -x   message''',  stringWriter.toString ( ).tokenize ( '\r\n' ).join ( '\n' ) )
    */
    assertEquals ( '''error: -x
usage: groovy
 -x   message''',  stringWriter.toString ( ).tokenize ( '\r\n' ).join ( '\n' ) )
    }

  void testLongOptsOnly_GnuParser ( ) {
    def cli = new CliBuilder ( writer : printWriter , parser : new GnuParser ( ) )
    def anOption = OptionBuilder.withLongOpt ( 'anOption' ).hasArg ( ).withDescription ( 'An option.' ).create ( )
    cli.options.addOption ( anOption )
    def options = cli.parse ( [ '-v' , '--anOption' , 'something' ] )
    /*
     *  The behaviour here depends ont whether stopAtNonOption is true or false in the call to parser.parse
     *  in CliBuilder.parse.  Currently this is true, so parse simply terminates.  Any options after the
     *  unrecognized one are unprocessed.
     *
    assertEquals ( '''error: -v
usage: groovy
 --anOption   message''',  stringWriter.toString ( ).tokenize ( '\r\n' ).join ( '\n' ) )
    */
    assertEquals ( '''''', stringWriter.toString ( ).tokenize ( '\r\n' ).join ( '\n' ) )
    assert ! options.v
    /*
     *  In 1.1, when run individually using testOne groovy.util.CliBuilderTest, but not when run using testAll or
     *  testOne UberTestCaseGroovySourceSubPackages, the <arg> is missing and this test fails.  What is it
     *  about this way of running things that means the above Commons CLI calls fail to work as they should?
     *  This is WORRYING.
     *
     *  TODO: fixme
     *
    assertEquals ( '''usage: groovy
    --anOption <arg>   An option.''' , stringWriter.toString ( ).tokenize ( '\r\n' ).join ( '\n' ) )
    *
    *  1.0 gets it wrong always :-(
    */
    /*
    assertEquals ( '''usage: groovy
    --anOption    An option.''' , stringWriter.toString ( ).tokenize ( '\r\n' ).join ( '\n' ) )
    */
    /*
     *  For some reason, no matter how this test is run, anOption is not a recognized option.  This is the
     *  extant behaviour and not what should happen, i.e. this is a bug to be investigated and fixed.  This
     *  is a bug for 1.1, 1.0 just always gets it wrong anyway.
     *
     *  TODO:  Fixme
     *
    assertEquals ( 'something' , options.getOptionValue ( 'anOption' ) )
    assertEquals ( 'something' , options.anOption )
    */
    assertEquals ( null , options.getOptionValue ( 'anOption' ) )
    assertEquals ( false , options.anOption )
  }
  void testLongOptsOnly_PosixParser ( ) {
    def cli = new CliBuilder ( writer : printWriter , parser : new PosixParser ( ) )
    def anOption = OptionBuilder.withLongOpt ( 'anOption' ).hasArg ( ).withDescription ( 'An option.' ).create ( )
    cli.options.addOption ( anOption )
    def options = cli.parse ( [ '-v' , '--anOption' , 'something' ] )
    cli.usage ( )
    /*
     *  1.0 gets this totally wrong.
     *
    assertEquals ( '''usage: groovy
    --anOption <arg>   An option.''' , stringWriter.toString ( ).tokenize ( '\r\n' ).join ( '\n' ) )
    */
    assertEquals ( '''usage: groovy
    --anOption    An option.''' , stringWriter.toString ( ).tokenize ( '\r\n' ).join ( '\n' ) )
    assertEquals ( 'something' , options.getOptionValue ( 'anOption' ) )
    assertEquals ( 'something' , options.anOption )
    assert ! options.v
  }

  private createOptionsWithLongAndShortOpts ( parser ) {
    def cli = new CliBuilder ( writer : printWriter , parser : parser )
    def anOption = OptionBuilder.withLongOpt ( 'anOption' ).hasArg ( ).withDescription ( 'An option.' ).create ( )
    cli.options.addOption ( anOption )
    cli.v ( longOpt : 'verbose' , 'verbose mode' )
    def options = cli.parse ( [ '-v' , '--anOption' , 'something' ] )
    cli.usage ( )
    /*
     *  1.0 gets this totally wrong.
     *
    assertEquals ( '''usage: groovy
    --anOption <arg>   An option.
 -v,--verbose          verbose mode''' , stringWriter.toString ( ).tokenize ( '\r\n' ).join ( '\n' ) )
    */
    assertEquals ( '''usage: groovy
    --anOption    An option.
 -v,--verbose     verbose mode''' , stringWriter.toString ( ).tokenize ( '\r\n' ).join ( '\n' ) )
     assert options.v
    return options
  }

  void testLongAndShortOpts_BasicParser ( ) {
    def options = createOptionsWithLongAndShortOpts ( new BasicParser ( ) )
    assertEquals ( 'something' , options.getOptionValue ( 'anOption' ) )
    assertEquals ( 'something' , options.anOption )
  }

  void testLongAndShortOpts_PosixParser ( ) {
    def options = createOptionsWithLongAndShortOpts ( new PosixParser ( ) )
    //
    //  This represents what currently happens, not what should happen.  The problem needs investigating so
    //  that the expected results here can be set to 'something' as it should.
    //
    assertEquals ( '--' , options.getOptionValue ( 'anOption' ) )
    assertEquals ( '--' , options.anOption )
  }

  void testLongAndShortOpts_GnuParser ( ) {
    def options = createOptionsWithLongAndShortOpts ( new GnuParser ( ) )
    assertEquals ( 'something' , options.getOptionValue ( 'anOption' ) )
    assertEquals ( 'something' , options.anOption )
  }

  void unknownOptions ( parser ) {
    def cli = new CliBuilder ( parser : parser )
    cli.v ( longOpt : 'verbose' , 'verbose mode' )
    def options = cli.parse ( [ '-x' , '-yyy' , '--zzz' , 'something' ] )
    assertEquals ( [ '-x' , '-yyy' , '--zzz' , 'something' ] , options.arguments ( ) )
  }
  void testUnrecognizedOptions_BasicParser ( ) { unknownOptions ( new BasicParser ( ) ) }
  void testUnrecognizedOptions_GnuParser ( ) { unknownOptions ( new GnuParser ( ) ) }
  //
  //  The Posix Parser absorbs unrecognized options rather than passing them through.  It is not clear if
  //  this is the correct or incorrect behaviour.
  //
  void testUnrecognizedOptions_PosixParser ( ) {
    def cli = new CliBuilder ( parser : new PosixParser ( ) )
    cli.v ( longOpt : 'verbose' , 'verbose mode' )
    def options = cli.parse ( [ '-x' , '-yyy' , '--zzz' , 'something' ] )
    assertEquals ( [ '-yyy' , '--zzz' , 'something' ] , options.arguments ( ) )
 }

  void bizarreProcessing ( parser ) {
    def cli = new CliBuilder ( parser : parser )
    def options = cli.parse ( [ '-xxxx' ] )
    assertEquals ( [ '-xxxx' ] , options.arguments ( ) )
  }
  void testBizarreProcessing_BasicParser ( ) { bizarreProcessing ( new BasicParser ( ) ) }
  void testBizarreProcessing_GnuParser ( ) { bizarreProcessing ( new GnuParser ( ) ) }
  //
  //  This behaviour by the PosixParser is truly bizarre and so militates in favour of the switch from
  //  PosixParser to GnuParser as the CliBuilder default.
  //
  void testPosixBizarreness ( ) {
    def cli = new CliBuilder ( parser : new PosixParser ( ) )
    def options = cli.parse ( [ '-xxx' ] )
    assertEquals ( [ 'xxx' , 'xx' , 'x' ] , options.arguments ( ) )
  }

  private void multipleOccurrencesSeparateSeparate ( parser ) {
    def cli = new CliBuilder ( parser : parser )
    cli.a ( longOpt : 'arg' , args : Option.UNLIMITED_VALUES , 'arguments' )
    def options = cli.parse ( [ '-a' , '1' , '-a' , '2' , '-a' , '3' ] )
    assertEquals ( '1' , options.a )
    assertEquals ( [ '1' , '2' , '3' ] , options.as )
    ////assertEquals ( '1' , options.arg )
    ////assertEquals ( [ '1' , '2' , '3' ] , options.args )
    assertEquals ( [ ] , options.arguments ( ) )
  }
  void testMultipleOccurrencesSeparateSeparate_BasicParser ( ) { multipleOccurrencesSeparateSeparate ( new BasicParser ( ) ) }
  void testMultipleOccurrencesSeparateSeparate_GnuParser ( ) { multipleOccurrencesSeparateSeparate ( new GnuParser ( ) ) }
  void testMultipleOccurrencesSeparateSeparate_PosixParser ( ) { multipleOccurrencesSeparateSeparate ( new PosixParser ( ) ) }

  private void multipleOccurrencesSeparateJuxtaposed ( parser ) {
    def cli = new CliBuilder ( parser : parser )
    cli.a ( longOpt : 'arg' , args : Option.UNLIMITED_VALUES , 'arguments' )
    def options = cli.parse ( [ '-a1' , '-a2' , '-a3' ] )
    assertEquals ( '1' , options.a )
    assertEquals ( [ '1' , '2' , '3' ] , options.as )
    ////assertEquals ( '1' , options.arg )
    ////assertEquals ( [ '1' , '2' , '3' ] , options.args )
    assertEquals ( [ ] , options.arguments ( ) )
  }
  //
  //  BasicParser cannot handle this one.
  //
  //void testMultipleOccurrencesSeparateJuxtaposed_BasicParser ( ) { multipleOccurrencesSeparateJuxtaposed ( new BasicParser ( ) ) }
  void testMultipleOccurrencesSeparateJuxtaposed_GnuParser ( ) { multipleOccurrencesSeparateJuxtaposed ( new GnuParser ( ) ) }
  void testMultipleOccurrencesSeparateJuxtaposed_PosixParser ( ) { multipleOccurrencesSeparateJuxtaposed ( new PosixParser ( ) ) }

  private void multipleOccurrencesTogetherSeparate ( parser ) {
    def cli = new CliBuilder ( parser : parser )
    cli.a ( longOpt : 'arg' , args : Option.UNLIMITED_VALUES , valueSeparator : ',' as char , 'arguments' )
    def options = cli.parse ( [ '-a 1,2,3' ] )
    assertEquals ( ' 1' , options.a )
    assertEquals ( [ ' 1' , '2' , '3' ] , options.as )
    ////assertEquals ( ' 1' , options.arg )
    ////assertEquals ( [ ' 1' , '2' , '3' ] , options.args )
    assertEquals ( [ ] , options.arguments ( ) )
  }
  //
  //  BasicParser cannot handle this one.
  //
  //void testMultipleOccurrencesTogetherSeparate_BasicParser ( ) { multipleOccurrencesTogetherSeparate ( new BasicParser ( ) ) }
  void testMultipleOccurrencesTogetherSeparate_GnuParser ( ) { multipleOccurrencesTogetherSeparate ( new GnuParser ( ) ) }
  void testMultipleOccurrencesTogetherSeparate_PosixParser ( ) { multipleOccurrencesTogetherSeparate ( new PosixParser ( ) ) }

  private void multipleOccurrencesTogetherJuxtaposed ( parser ) {
    def cli = new CliBuilder ( parser : parser )
    cli.a ( longOpt : 'arg' , args : Option.UNLIMITED_VALUES , valueSeparator : ',' as char , 'arguments' )
    def options = cli.parse ( [ '-a1,2,3' ] )
    assertEquals ( '1' , options.a )
    assertEquals ( [ '1' , '2' , '3' ] , options.as )
    ////assertEquals ( '1' , options.arg )
    ////assertEquals ( [ '1' , '2' , '3' ] , options.args )
    assertEquals ( [ ] , options.arguments ( ) )
  }
  //
  //  BasicParser cannot handle this one.
  //
  //void testMultipleOccurrencesTogetherJuxtaposed_BasicParser ( ) { multipleOccurrencesTogetherJuxtaposed ( new BasicParser ( ) ) }
  void testMultipleOccurrencesTogetherJuxtaposed_GnuParser ( ) { multipleOccurrencesTogetherJuxtaposed ( new GnuParser ( ) ) }
  void testMultipleOccurrencesTogetherJuxtaposed_PosixParser ( ) { multipleOccurrencesTogetherJuxtaposed ( new PosixParser ( ) ) }

  /*
   *  Investigate problems with unrecognized options.  Should add the BasicParser here as well.
   */

  void testUnrecognizedOptionSilentlyIgnored_GnuParser ( ) {
    def cli = new CliBuilder ( usage : usageString , writer : printWriter , parser : new GnuParser ( ) )
    def options = cli.parse ( [ '-v' ] )
    /*
     *  The behaviour here depends on whether stopAtNonOption is true or false in the call to parser.parse
     *  in CliBuilder.parse.  Currently this is true, so parse simply terminates.  Any options after the
     *  unrecognized one are unprocessed.
     *
    assertEquals ( '''error: Unrecognized option: -v
usage: groovy [option]* filename''', stringWriter.toString ( ).tokenize ( '\r\n' ).join ( '\n' ) )
    assertEquals ( null , options )
    */
    assertEquals ( '''''', stringWriter.toString ( ).tokenize ( '\r\n' ).join ( '\n' ) )
    assert !options.v
  }
  void testUnrecognizedOptionSilentlyIgnored_PosixParser ( ) {
    //
    //  The PosixParser silently absorbs unrecognized options.
    //
    def cli = new CliBuilder ( usage : usageString , writer : printWriter , parser : new PosixParser ( ) )
    def options = cli.parse ( [ '-v' ] )
    assertEquals ( '''''', stringWriter.toString ( ).tokenize ( '\r\n' ).join ( '\n' ) )
    assert ! options.v
  }
  void testUnrecognizedOptionTerminatesParse_GnuParser ( ) {
    def cli = new CliBuilder ( usage : usageString , writer : printWriter , parser : new GnuParser ( ) )
    cli.h ( longOpt : 'help', 'usage information' )
    def options = cli.parse ( [ '-v' , '-h' ] )
    /*
     *  The behaviour here depends on whether stopAtNonOption is true or false in the call to parser.parse
     *  in CliBuilder.parse.  Currently this is true, so parse simply terminates.  Any options after the
     *  unrecognized one are unprocessed.
     *
    assertEquals ( '''error: Unrecognized option: -v
usage: groovy [option]* filename''', stringWriter.toString ( ).tokenize ( '\r\n' ).join ( '\n' ) )
    assertEquals ( null , options )
    */
    assertEquals ( '''''', stringWriter.toString ( ).tokenize ( '\r\n' ).join ( '\n' ) )
    assert !options.v
    //
    //  Why is options.h not recognized here.  This is weird.
    //
    //assert ! options.h
    assertEquals ( [ '-v' , '-h' ] , options.arguments ( ) )
  }
  void testUnrecognizedOptionTerminatesParse_PosixParser ( ) {
    //
    //  The PosixParser silently absorbs unrecognized options.
    //
    def cli = new CliBuilder ( usage : usageString , writer : printWriter , parser : new PosixParser ( ) )
    cli.h ( longOpt : 'help', 'usage information' )
    def options = cli.parse ( [ '-v' , '-h' ] )
    assertEquals ( '''''', stringWriter.toString ( ).tokenize ( '\r\n' ).join ( '\n' ) )
    assert ! options.v
    //
    //  Why is options.h not recognized here.  This is weird.
    //
    //assert ! options.h
    assertEquals ( [ ] , options.arguments ( ) )
  }

}

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us