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 fileTake it
Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
lines 1–4why, one step back1const commander = require('../');23// Not testing output, just testing whether an error is detected.4Check command-arguments even without action handler (#1502)John Geebefore adoption0504945
lines 5–15why, one step back5describe.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 back16Make new excess arguments error opt-in (#1429)John Geebefore adoptione2670f4
line 17why, one step back17 test('when specify excess program argument then no error by default', () => {Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
line 18why, one step back18 const program = new commander.Command();Check command-arguments even without action handler (#1502)John Geebefore adoption0504945
line 19why, one step back19 configureCommand(program);Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
lines 20–22why, one step back2021 expect(() => {22 program.parse(['excess'], { from: 'user' });Make new excess arguments error opt-in (#1429)John Geebefore adoptione2670f4
line 23why, one step back23 }).not.toThrow();Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
lines 24–27why, one step back24 });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 back28 configureCommand(program);Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
line 29why, one step back29 programCheck command-arguments even without action handler (#1502)John Geebefore adoption0504945
line 30why, one step back30 .allowExcessArguments(false);Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
lines 31–38why, one step back3132 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 back39 configureCommand(program);Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
line 40why, one step back40 programCheck command-arguments even without action handler (#1502)John Geebefore adoption0504945
line 41why, one step back41 .allowExcessArguments();Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
lines 42–49why, one step back4243 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 back50 configureCommand(program);Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
line 51why, one step back51 programCheck command-arguments even without action handler (#1502)John Geebefore adoption0504945
line 52why, one step back52 .allowExcessArguments(true);Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
lines 53–58why, one step back5354 expect(() => {55 program.parse(['excess'], { from: 'user' });56 }).not.toThrow();57 });58Make new excess arguments error opt-in (#1429)John Geebefore adoptione2670f4
line 59why, one step back59 test('when specify excess command argument then no error (by default)', () => {Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
line 60why, one step back60 const program = new commander.Command();Check command-arguments even without action handler (#1502)John Geebefore adoption0504945
lines 61–63why, one step back61 const sub = program62 .command('sub');63 configureCommand(sub);Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
lines 64–66why, one step back6465 expect(() => {66 program.parse(['sub', 'excess'], { from: 'user' });Make new excess arguments error opt-in (#1429)John Geebefore adoptione2670f4
line 67why, one step back67 }).not.toThrow();Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
lines 68–71why, one step back68 });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 back72 const sub = programAdd .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
line 73why, one step back73 .command('sub')Check command-arguments even without action handler (#1502)John Geebefore adoption0504945
lines 74–75why, one step back74 .allowExcessArguments(false);75 configureCommand(sub);Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
lines 76–83why, one step back7677 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 back84 configureCommand(program);Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
line 85why, one step back85 programMore consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9
line 86why, one step back86 .argument('<file>')Check command-arguments even without action handler (#1502)John Geebefore adoption0504945
line 87why, one step back87 .allowExcessArguments(false);Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
lines 88–95why, one step back8889 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 back96 configureCommand(program);Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
line 97why, one step back97 programMore consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9
line 98why, one step back98 .argument('<file>')Check command-arguments even without action handler (#1502)John Geebefore adoption0504945
line 99why, one step back99 .allowExcessArguments(false);Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
lines 100–107why, one step back100101 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 back108 configureCommand(program);Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
line 109why, one step back109 programMore consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9
line 110why, one step back110 .argument('[file]')Check command-arguments even without action handler (#1502)John Geebefore adoption0504945
line 111why, one step back111 .allowExcessArguments(false);Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
lines 112–119why, one step back112113 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 back120 configureCommand(program);Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
line 121why, one step back121 programMore consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9
line 122why, one step back122 .argument('[files...]')Check command-arguments even without action handler (#1502)John Geebefore adoption0504945
line 123why, one step back123 .allowExcessArguments(false);Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a
lines 124–129why, one step back124125 expect(() => {126 program.parse(['file1', 'file2', 'file3'], { from: 'user' });127 }).not.toThrow();128 });129});