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
Provenance
- Commit
dcddf69- Tree
dc92744- Author
usmonster <akeju00+github@gmail.com>- Committer
Roman Vanesyan <romain.vanesyan@gmail.com>- Parent
649eaef
12 files changed+34 added−33 removed
modified:test/test.command.name.js+2 added-2 removed
8 unmodified lines91011121313141516172 unmodified lines2021222324248 unmodified lines .command('mycommand [options]', 'this is my command');
program.parse(['node', 'test']);
program.name.should.be.a.Function;program.name.should.be.a.Function();program.name().should.equal('test');program.commands[0].name().should.equal('mycommand');program.commands[1].name().should.equal('help');
2 unmodified linesoutput[0].should.containEql([ ' mycommand [options] this is my command'].join('\n'));
sinon.restore();No newline at end of filesinon.restore();modified:test/test.command.name.set.js+1 added-1 removed
5 unmodified lines67891010111213142 unmodified lines5 unmodified linessinon.stub(process.stdout, 'write');
program.name('foobar').description('This is a test.');
program.name.should.be.a.Function;program.name.should.be.a.Function();program.name().should.equal('foobar');program.description().should.equal('This is a test.');
var output = process.stdout.write.args[0];2 unmodified linesmodified:test/test.literal.args.js+1 added-1 removed
9 unmodified lines101112131414151617182 unmodified lines9 unmodified lines .option('-f, --foo', 'add some foo') .option('-b, --bar', 'add some bar');
program.parse(['node', 'test', '--foo', '--', '--bar', 'baz']);program.foo.should.be.true;program.foo.should.be.true();should.equal(undefined, program.bar);program.args.should.eql(['--bar', 'baz']);
// subsequent literals are passed-through as args2 unmodified linesmodified:test/test.options.args.optional.js+1 added-1 removed
8 unmodified lines910111213138 unmodified lines .version('0.0.1') .option('-c, --cheese [type]', 'optionally specify the type of cheese');
program.parse(['node', 'test', '--cheese']);program.cheese.should.be.true;program.cheese.should.be.true();modified:test/test.options.bool.js+2 added-2 removed
9 unmodified lines10111213141514159 unmodified lines .option('-p, --pepper', 'add pepper') .option('-c, --no-cheese', 'remove cheese');
program.parse(['node', 'test', '--pepper']);program.pepper.should.be.true;program.cheese.should.be.true;program.pepper.should.be.true();program.cheese.should.be.true();modified:test/test.options.bool.no.js+1 added-1 removed
10 unmodified lines11121314151510 unmodified lines .option('-c|--no-cheese', 'remove cheese');
program.parse(['node', 'test', '--no-cheese']);should.equal(undefined, program.pepper);program.cheese.should.be.false;program.cheese.should.be.false();modified:test/test.options.bool.small.combined.js+2 added-2 removed
9 unmodified lines10111213141514159 unmodified lines .option('-p, --pepper', 'add pepper') .option('-c, --no-cheese', 'remove cheese');
program.parse(['node', 'test', '-pc']);program.pepper.should.be.true;program.cheese.should.be.false;program.pepper.should.be.true();program.cheese.should.be.false();modified:test/test.options.bool.small.js+2 added-2 removed
9 unmodified lines10111213141514159 unmodified lines .option('-p, --pepper', 'add pepper') .option('-c, --no-cheese', 'remove cheese');
program.parse(['node', 'test', '-p', '-c']);program.pepper.should.be.true;program.cheese.should.be.false;program.pepper.should.be.true();program.cheese.should.be.false();modified:test/test.options.commands.js+12 added-11 removed
45 unmodified lines46 });47 48 program.parse(['node', 'test', '--config', 'conf']);49 program.config.should.equal("conf");50-program.commands[0].should.not.have.property.setup_mode;51-program.commands[1].should.not.have.property.exec_mode;50+program.commands[0].should.not.have.property('setup_mode');51+program.commands[1].should.not.have.property('exec_mode');52 envValue.should.equal("");53 cmdValue.should.equal("");54 55-program.parse(['node', 'test', '--config', 'conf1', 'setup', '--setup_mode', 'mode3', 'env1']);55+program.parse(['node', 'test', '--config', 'conf1', 'setup', '--setup_mode', 'mode2', 'env1']);56 program.config.should.equal("conf1");57-program.commands[0].setup_mode.should.equal("mode3");58-program.commands[0].should.not.have.property.host;57+program.commands[0].setup_mode.should.equal("mode2");58+program.commands[0].should.not.have.property('host');59 envValue.should.equal("env1");60 61 program.parse(['node', 'test', '--config', 'conf2', 'setup', '--setup_mode', 'mode3', '-o', 'host1', 'env2']);62 program.config.should.equal("conf2");8 unmodified lines71 72 program.parse(['node', 'test', '--config', 'conf4', 'exec', '--exec_mode', 'mode1', 'exec1']);73 program.config.should.equal("conf4");74 program.commands[1].exec_mode.should.equal("mode1");75-program.commands[1].should.not.have.property.target;75+program.commands[1].should.not.have.property('target');76 cmdValue.should.equal("exec1");77 78 program.parse(['node', 'test', '--config', 'conf5', 'exec', '-e', 'mode2', 'exec2']);79 program.config.should.equal("conf5");80 program.commands[1].exec_mode.should.equal("mode2");81 cmdValue.should.equal("exec2");82 83-program.parse(['node', 'test', '--config', 'conf6', 'exec', '--target', 'target1', '-e', 'mode2', 'exec3']);83+program.parse(['node', 'test', '--config', 'conf6', 'exec', '--target', 'target1', '-e', 'mode6', 'exec3']);84 program.config.should.equal("conf6");85-program.commands[1].exec_mode.should.equal("mode2");85+program.commands[1].exec_mode.should.equal("mode6");86 program.commands[1].target.should.equal("target1");87 cmdValue.should.equal("exec3");88 89+delete program.commands[1].target;90 program.parse(['node', 'test', '--config', 'conf7', 'ex', '-e', 'mode3', 'exec4']);91 program.config.should.equal("conf7");92 program.commands[1].exec_mode.should.equal("mode3");92-program.commands[1].should.not.have.property.target;93+program.commands[1].should.not.have.property('target');94 cmdValue.should.equal("exec4");95 96 // Make sure we still catch errors with required values for options97 var exceptionOccurred = false;22 unmodified lines120 catch (ex) {121 }122 123 process.exit = oldProcessExit;123-exceptionOccurred.should.be.true;124-customHelp.should.be.true;124+exceptionOccurred.should.be.true();125+customHelp.should.be.true();modified:test/test.options.func.js+6 added-6 removed
9 unmodified lines10 .option('-c, --camel-case', 'convert to camelCase')11 .option('-q, --quux <quux>', 'add some quux');12 13 program.parse(['node', 'test', '--foo', '--bar', '--no-magic', '--camel-case', '--quux', 'value']);14-program.opts.should.be.a.Function;14+program.opts.should.be.a.Function();15 16 var opts = program.opts();17-opts.should.be.an.Object;17+opts.should.be.an.Object();18 opts.version.should.equal('0.0.1');19-opts.foo.should.be.true;20-opts.bar.should.be.true;21-opts.magic.should.be.false;22-opts.camelCase.should.be.true;19+opts.foo.should.be.true();20+opts.bar.should.be.true();21+opts.magic.should.be.false();22+opts.camelCase.should.be.true();23 opts.quux.should.equal('value');modified:test/test.options.large-only.js+1 added-1 removed
8 unmodified lines9 .version('0.0.1')10 .option('--verbose', 'do stuff');11 12 program.parse(['node', 'test', '--verbose']);13-program.verbose.should.be.true;13+program.verbose.should.be.true();modified:index.js+3 added-3 removed
41 unmodified lines42 */43 44 function 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