Skip to content
Myr

command.allowExcessArguments.test.js

This file

Path

tests/command.allowExcessArguments.test.js

129 lines · 3.6 KiB · JavaScript

Last changed by

Check command-arguments even without action handler (#1502)John Geebefore adoption0504945

History of this file

Take it

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

lines 1–4why, one step back
1const commander = require('../');
23// Not testing output, just testing whether an error is detected.4

Check command-arguments even without action handler (#1502)John Geebefore adoption0504945

lines 5–15why, one step back
5describe.each([true, false])('allowExcessArguments when action handler: %s', (hasActionHandler) => {
6 function configureCommand(cmd) {7 cmd8 .exitOverride()9 .configureOutput({10 writeErr: () => {}11 });12 if (hasActionHandler) {13 cmd.action(() => {});14 }15 }

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

line 16why, one step back
16

Make new excess arguments error opt-in (#1429)John Geebefore adoptione2670f4

line 17why, one step back
17 test('when specify excess program argument then no error by default', () => {

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

line 18why, one step back
18 const program = new commander.Command();

Check command-arguments even without action handler (#1502)John Geebefore adoption0504945

line 19why, one step back
19 configureCommand(program);

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

lines 20–22why, one step back
20
21 expect(() => {22 program.parse(['excess'], { from: 'user' });

Make new excess arguments error opt-in (#1429)John Geebefore adoptione2670f4

line 23why, one step back
23 }).not.toThrow();

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

lines 24–27why, one step back
24 });
2526 test('when specify excess program argument and allowExcessArguments(false) then error', () => {27 const program = new commander.Command();

Check command-arguments even without action handler (#1502)John Geebefore adoption0504945

line 28why, one step back
28 configureCommand(program);

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

line 29why, one step back
29 program

Check command-arguments even without action handler (#1502)John Geebefore adoption0504945

line 30why, one step back
30 .allowExcessArguments(false);

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

lines 31–38why, one step back
31
32 expect(() => {33 program.parse(['excess'], { from: 'user' });34 }).toThrow();35 });3637 test('when specify excess program argument and allowExcessArguments() then no error', () => {38 const program = new commander.Command();

Check command-arguments even without action handler (#1502)John Geebefore adoption0504945

line 39why, one step back
39 configureCommand(program);

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

line 40why, one step back
40 program

Check command-arguments even without action handler (#1502)John Geebefore adoption0504945

line 41why, one step back
41 .allowExcessArguments();

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

lines 42–49why, one step back
42
43 expect(() => {44 program.parse(['excess'], { from: 'user' });45 }).not.toThrow();46 });4748 test('when specify excess program argument and allowExcessArguments(true) then no error', () => {49 const program = new commander.Command();

Check command-arguments even without action handler (#1502)John Geebefore adoption0504945

line 50why, one step back
50 configureCommand(program);

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

line 51why, one step back
51 program

Check command-arguments even without action handler (#1502)John Geebefore adoption0504945

line 52why, one step back
52 .allowExcessArguments(true);

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

lines 53–58why, one step back
53
54 expect(() => {55 program.parse(['excess'], { from: 'user' });56 }).not.toThrow();57 });58

Make new excess arguments error opt-in (#1429)John Geebefore adoptione2670f4

line 59why, one step back
59 test('when specify excess command argument then no error (by default)', () => {

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

line 60why, one step back
60 const program = new commander.Command();

Check command-arguments even without action handler (#1502)John Geebefore adoption0504945

lines 61–63why, one step back
61 const sub = program
62 .command('sub');63 configureCommand(sub);

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

lines 64–66why, one step back
64
65 expect(() => {66 program.parse(['sub', 'excess'], { from: 'user' });

Make new excess arguments error opt-in (#1429)John Geebefore adoptione2670f4

line 67why, one step back
67 }).not.toThrow();

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

lines 68–71why, one step back
68 });
6970 test('when specify excess command argument and allowExcessArguments(false) then error', () => {71 const program = new commander.Command();

Check command-arguments even without action handler (#1502)John Geebefore adoption0504945

line 72why, one step back
72 const sub = program

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

line 73why, one step back
73 .command('sub')

Check command-arguments even without action handler (#1502)John Geebefore adoption0504945

lines 74–75why, one step back
74 .allowExcessArguments(false);
75 configureCommand(sub);

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

lines 76–83why, one step back
76
77 expect(() => {78 program.parse(['sub', 'excess'], { from: 'user' });79 }).toThrow();80 });8182 test('when specify expected arg and allowExcessArguments(false) then no error', () => {83 const program = new commander.Command();

Check command-arguments even without action handler (#1502)John Geebefore adoption0504945

line 84why, one step back
84 configureCommand(program);

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

line 85why, one step back
85 program

More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9

line 86why, one step back
86 .argument('<file>')

Check command-arguments even without action handler (#1502)John Geebefore adoption0504945

line 87why, one step back
87 .allowExcessArguments(false);

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

lines 88–95why, one step back
88
89 expect(() => {90 program.parse(['file'], { from: 'user' });91 }).not.toThrow();92 });9394 test('when specify excess after <arg> and allowExcessArguments(false) then error', () => {95 const program = new commander.Command();

Check command-arguments even without action handler (#1502)John Geebefore adoption0504945

line 96why, one step back
96 configureCommand(program);

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

line 97why, one step back
97 program

More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9

line 98why, one step back
98 .argument('<file>')

Check command-arguments even without action handler (#1502)John Geebefore adoption0504945

line 99why, one step back
99 .allowExcessArguments(false);

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

lines 100–107why, one step back
100
101 expect(() => {102 program.parse(['file', 'excess'], { from: 'user' });103 }).toThrow();104 });105106 test('when specify excess after [arg] and allowExcessArguments(false) then error', () => {107 const program = new commander.Command();

Check command-arguments even without action handler (#1502)John Geebefore adoption0504945

line 108why, one step back
108 configureCommand(program);

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

line 109why, one step back
109 program

More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9

line 110why, one step back
110 .argument('[file]')

Check command-arguments even without action handler (#1502)John Geebefore adoption0504945

line 111why, one step back
111 .allowExcessArguments(false);

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

lines 112–119why, one step back
112
113 expect(() => {114 program.parse(['file', 'excess'], { from: 'user' });115 }).toThrow();116 });117118 test('when specify args for [args...] and allowExcessArguments(false) then no error', () => {119 const program = new commander.Command();

Check command-arguments even without action handler (#1502)John Geebefore adoption0504945

line 120why, one step back
120 configureCommand(program);

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

line 121why, one step back
121 program

More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9

line 122why, one step back
122 .argument('[files...]')

Check command-arguments even without action handler (#1502)John Geebefore adoption0504945

line 123why, one step back
123 .allowExcessArguments(false);

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

lines 124–129why, one step back
124
125 expect(() => {126 program.parse(['file1', 'file2', 'file3'], { from: 'user' });127 }).not.toThrow();128 });129});