Skip to content
Myr

fix tests

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- Many tests were not properly invoking assertion functions. Now they are. - Fixed one test then was then failing because of side-effects from previous test setups. - Made small changes in some setups to avoid potential false negatives. (Also: made a tiny unrelated code change to ensure Options always has boolean properties; does not change any behavior, but may help with debugging.)

authored by usmonster · committed by Roman Vanesyan · parent 649eaef · Browse files · 12 files+34 added−33 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

12 files+34 added−33 removed

  • tests:+31 added−30 removed
  • other:+3 added−3 removed

12 files+34 added−33 removed

modified:test/test.command.name.js+2 added-2 removed
modified:test/test.command.name.set.js+1 added-1 removed
modified:test/test.literal.args.js+1 added-1 removed
modified:test/test.options.args.optional.js+1 added-1 removed
modified:test/test.options.bool.js+2 added-2 removed
modified:test/test.options.bool.no.js+1 added-1 removed
modified:test/test.options.bool.small.combined.js+2 added-2 removed
modified:test/test.options.bool.small.js+2 added-2 removed
modified:test/test.options.commands.js+12 added-11 removed
45 unmodified lines
46 });4748program.parse(['node', 'test', '--config', 'conf']);49program.config.should.equal("conf");50program.commands[0].should.not.have.property.setup_mode;51program.commands[1].should.not.have.property.exec_mode;50program.commands[0].should.not.have.property('setup_mode');51program.commands[1].should.not.have.property('exec_mode');52envValue.should.equal("");53cmdValue.should.equal("");5455program.parse(['node', 'test', '--config', 'conf1', 'setup', '--setup_mode', 'mode3', 'env1']);55program.parse(['node', 'test', '--config', 'conf1', 'setup', '--setup_mode', 'mode2', 'env1']);56program.config.should.equal("conf1");57program.commands[0].setup_mode.should.equal("mode3");58program.commands[0].should.not.have.property.host;57program.commands[0].setup_mode.should.equal("mode2");58program.commands[0].should.not.have.property('host');59envValue.should.equal("env1");6061program.parse(['node', 'test', '--config', 'conf2', 'setup', '--setup_mode', 'mode3', '-o', 'host1', 'env2']);62program.config.should.equal("conf2");
8 unmodified lines
7172program.parse(['node', 'test', '--config', 'conf4', 'exec', '--exec_mode', 'mode1', 'exec1']);73program.config.should.equal("conf4");74program.commands[1].exec_mode.should.equal("mode1");75program.commands[1].should.not.have.property.target;75program.commands[1].should.not.have.property('target');76cmdValue.should.equal("exec1");7778program.parse(['node', 'test', '--config', 'conf5', 'exec', '-e', 'mode2', 'exec2']);79program.config.should.equal("conf5");80program.commands[1].exec_mode.should.equal("mode2");81cmdValue.should.equal("exec2");8283program.parse(['node', 'test', '--config', 'conf6', 'exec', '--target', 'target1', '-e', 'mode2', 'exec3']);83program.parse(['node', 'test', '--config', 'conf6', 'exec', '--target', 'target1', '-e', 'mode6', 'exec3']);84program.config.should.equal("conf6");85program.commands[1].exec_mode.should.equal("mode2");85program.commands[1].exec_mode.should.equal("mode6");86program.commands[1].target.should.equal("target1");87cmdValue.should.equal("exec3");8889delete program.commands[1].target;90program.parse(['node', 'test', '--config', 'conf7', 'ex', '-e', 'mode3', 'exec4']);91program.config.should.equal("conf7");92program.commands[1].exec_mode.should.equal("mode3");92program.commands[1].should.not.have.property.target;93program.commands[1].should.not.have.property('target');94cmdValue.should.equal("exec4");9596// Make sure we still catch errors with required values for options97var exceptionOccurred = false;
22 unmodified lines
120catch (ex) {121}122123process.exit = oldProcessExit;123exceptionOccurred.should.be.true;124customHelp.should.be.true;124exceptionOccurred.should.be.true();125customHelp.should.be.true();
modified:test/test.options.func.js+6 added-6 removed
9 unmodified lines
10 .option('-c, --camel-case', 'convert to camelCase')11 .option('-q, --quux <quux>', 'add some quux');1213program.parse(['node', 'test', '--foo', '--bar', '--no-magic', '--camel-case', '--quux', 'value']);14program.opts.should.be.a.Function;14program.opts.should.be.a.Function();1516var opts = program.opts();17opts.should.be.an.Object;17opts.should.be.an.Object();18opts.version.should.equal('0.0.1');19opts.foo.should.be.true;20opts.bar.should.be.true;21opts.magic.should.be.false;22opts.camelCase.should.be.true;19opts.foo.should.be.true();20opts.bar.should.be.true();21opts.magic.should.be.false();22opts.camelCase.should.be.true();23opts.quux.should.equal('value');
modified:test/test.options.large-only.js+1 added-1 removed
8 unmodified lines
9 .version('0.0.1')10 .option('--verbose', 'do stuff');1112program.parse(['node', 'test', '--verbose']);13program.verbose.should.be.true;13program.verbose.should.be.true();
modified:index.js+3 added-3 removed
41 unmodified lines
42 */4344function Option(flags, description) {45 this.flags = flags;46 this.required = ~flags.indexOf('<');47 this.optional = ~flags.indexOf('[');48 this.bool = !~flags.indexOf('-no-');46 this.required = flags.indexOf('<') >= 0;47 this.optional = flags.indexOf('[') >= 0;48 this.bool = flags.indexOf('-no-') === -1;49 flags = flags.split(/[ ,|]+/);50 if (flags.length > 1 && !/^[[<]/.test(flags[1])) this.short = flags.shift();51 this.long = flags.shift();52 this.description = description || '';
1179 unmodified lines