|
1 | 1 | const commander = require('../'); |
2 | | -const { test } = require('node:test'); |
| 2 | +const { test, describe } = require('node:test'); |
3 | 3 | const assert = require('node:assert/strict'); |
4 | 4 |
|
5 | 5 | // Utility Conventions: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02 |
6 | 6 | // |
7 | 7 | // 12.2 Utility Syntax Guidelines, Guideline 10: |
8 | 8 | // The first -- argument that is not an option-argument should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the '-' character. |
9 | 9 |
|
10 | | -test('when arguments includes -- then stop processing options', () => { |
11 | | - const program = new commander.Command(); |
12 | | - program |
13 | | - .option('-f, --foo', 'add some foo') |
14 | | - .option('-b, --bar', 'add some bar') |
15 | | - .argument('[args...]'); |
16 | | - program.parse(['node', 'test', '--foo', '--', '--bar', 'baz']); |
17 | | - // More than one assert, ported from legacy test |
18 | | - const opts = program.opts(); |
19 | | - assert.equal(opts.foo, true); |
20 | | - assert.equal(opts.bar, undefined); |
21 | | - assert.deepEqual(program.args, ['--bar', 'baz']); |
22 | | -}); |
| 10 | +describe('end of options delimiter "--"', () => { |
| 11 | + test('when arguments includes -- then stop processing options', () => { |
| 12 | + const program = new commander.Command(); |
| 13 | + program |
| 14 | + .option('-f, --foo', 'add some foo') |
| 15 | + .option('-b, --bar', 'add some bar') |
| 16 | + .argument('[args...]'); |
| 17 | + program.parse(['node', 'test', '--foo', '--', '--bar', 'baz']); |
| 18 | + // More than one assert, ported from legacy test |
| 19 | + const opts = program.opts(); |
| 20 | + assert.equal(opts.foo, true); |
| 21 | + assert.equal(opts.bar, undefined); |
| 22 | + assert.deepEqual(program.args, ['--bar', 'baz']); |
| 23 | + }); |
23 | 24 |
|
24 | | -test('when arguments include -- then more literals are passed-through as args', () => { |
25 | | - const program = new commander.Command(); |
26 | | - program |
27 | | - .option('-f, --foo', 'add some foo') |
28 | | - .option('-b, --bar', 'add some bar') |
29 | | - .argument('[args...]'); |
30 | | - program.parse(['node', 'test', '--', 'cmd', '--', '--arg']); |
31 | | - assert.deepEqual(program.args, ['cmd', '--', '--arg']); |
| 25 | + test('when arguments include -- then more -- are passed-through as args', () => { |
| 26 | + const program = new commander.Command(); |
| 27 | + program |
| 28 | + .option('-f, --foo', 'add some foo') |
| 29 | + .option('-b, --bar', 'add some bar') |
| 30 | + .argument('[args...]'); |
| 31 | + program.parse(['node', 'test', '--', 'cmd', '--', '--arg']); |
| 32 | + assert.deepEqual(program.args, ['cmd', '--', '--arg']); |
| 33 | + }); |
32 | 34 | }); |
0 commit comments