test.variadic.args.js
This file
Path
test/test.variadic.args.js
64 lines · 1.4 KiB · JavaScript
Last changed by
Merge pull request #313 from zhiyelee/codestyleZhiye Libefore adoption543e47f
History of this fileTake it
Merge pull request #277 from whitlockjc/fix-issue-53Zhiye Libefore adoptionaf05389
lines 1–13why, one step back1/**2 * Module dependencies.3 */45var program = require('../')6 , should = require('should')7 , util = require('util')8 , programArgs = ['node', 'test', 'mycommand', 'arg0', 'arg1', 'arg2', 'arg3']9 , requiredArg10 , variadicArg;1112program13 .version('0.0.1')Merge pull request #308 from zhiyelee/fixvariadicZhiye Libefore adoptiona03b902
line 14why, one step back14 .command('mycommand <id> [variadicArg...]')Merge pull request #277 from whitlockjc/fix-issue-53Zhiye Libefore adoptionaf05389
lines 15–24why, one step back15 .action(function (arg0, arg1) {16 requiredArg = arg0;17 variadicArg = arg1;18 });1920program.parse(programArgs);2122requiredArg.should.eql('arg0');23variadicArg.should.eql(['arg1', 'arg2', 'arg3']);24Merge pull request #291 from Quentin01/masterZhiye Libefore adoption875e498
line 25why, one step back25program.args.should.have.lengthOf(3);Merge pull request #277 from whitlockjc/fix-issue-53Zhiye Libefore adoptionaf05389
lines 26–41why, one step back26program.args[0].should.eql('arg0');27program.args[1].should.eql(['arg1', 'arg2', 'arg3']);2829program30 .version('0.0.1')31 .command('mycommand <variadicArg...> [optionalArg]')32 .action(function (arg0, arg1) {3334 });3536// Make sure we still catch errors with required values for options37var consoleErrors = [];38var oldProcessExit = process.exit;39var oldConsoleError = console.error;40var errorMessage;41Merge pull request #313 from zhiyelee/codestyleZhiye Libefore adoption543e47f
lines 42–45why, one step back42process.exit = function () {43 throw new Error(consoleErrors.join('\n'));44};45console.error = function () {Merge pull request #277 from whitlockjc/fix-issue-53Zhiye Libefore adoptionaf05389
lines 46–64why, one step back46 consoleErrors.push(util.format.apply(util, arguments));47};4849try {50 program.parse(programArgs);5152 should.fail(null, null, 'An Error should had been thrown above');53} catch (err) {54 errorMessage = err.message;55}5657process.exit = oldProcessExit;58console.error = oldConsoleError;5960[61 '',62 ' error: variadic arguments must be last `variadicArg\'',63 ''64].join('\n').should.eql(errorMessage);