| 1 | /*
|
|---|
| 2 | * Jake JavaScript build tool
|
|---|
| 3 | * Copyright 2112 Matthew Eernisse (mde@fleegix.org)
|
|---|
| 4 | *
|
|---|
| 5 | * Licensed under the Apache License, Version 2.0 (the "License");
|
|---|
| 6 | * you may not use this file except in compliance with the License.
|
|---|
| 7 | * You may obtain a copy of the License at
|
|---|
| 8 | *
|
|---|
| 9 | * http://www.apache.org/licenses/LICENSE-2.0
|
|---|
| 10 | *
|
|---|
| 11 | * Unless required by applicable law or agreed to in writing, software
|
|---|
| 12 | * distributed under the License is distributed on an "AS IS" BASIS,
|
|---|
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|---|
| 14 | * See the License for the specific language governing permissions and
|
|---|
| 15 | * limitations under the License.
|
|---|
| 16 | *
|
|---|
| 17 | */
|
|---|
| 18 |
|
|---|
| 19 | const PROJECT_DIR = process.env.PROJECT_DIR;
|
|---|
| 20 |
|
|---|
| 21 | let parseargs = require(`${PROJECT_DIR}/lib/parseargs`);
|
|---|
| 22 | let assert = require('assert');
|
|---|
| 23 | let optsReg = [
|
|---|
| 24 | { full: 'directory',
|
|---|
| 25 | abbr: 'C',
|
|---|
| 26 | preempts: false,
|
|---|
| 27 | expectValue: true
|
|---|
| 28 | },
|
|---|
| 29 | { full: 'jakefile',
|
|---|
| 30 | abbr: 'f',
|
|---|
| 31 | preempts: false,
|
|---|
| 32 | expectValue: true
|
|---|
| 33 | },
|
|---|
| 34 | { full: 'tasks',
|
|---|
| 35 | abbr: 'T',
|
|---|
| 36 | preempts: true
|
|---|
| 37 | },
|
|---|
| 38 | { full: 'tasks',
|
|---|
| 39 | abbr: 'ls',
|
|---|
| 40 | preempts: true
|
|---|
| 41 | },
|
|---|
| 42 | { full: 'trace',
|
|---|
| 43 | abbr: 't',
|
|---|
| 44 | preempts: false,
|
|---|
| 45 | expectValue: false
|
|---|
| 46 | },
|
|---|
| 47 | { full: 'help',
|
|---|
| 48 | abbr: 'h',
|
|---|
| 49 | preempts: true
|
|---|
| 50 | },
|
|---|
| 51 | { full: 'version',
|
|---|
| 52 | abbr: 'V',
|
|---|
| 53 | preempts: true
|
|---|
| 54 | }
|
|---|
| 55 | ];
|
|---|
| 56 | let p = new parseargs.Parser(optsReg);
|
|---|
| 57 | let z = function (s) { return s.split(' '); };
|
|---|
| 58 | let res;
|
|---|
| 59 |
|
|---|
| 60 | suite('parseargs', function () {
|
|---|
| 61 |
|
|---|
| 62 | test('long preemptive opt and val with equal-sign, ignore further opts', function () {
|
|---|
| 63 | res = p.parse(z('--tasks=foo --jakefile=asdf'));
|
|---|
| 64 | assert.equal('foo', res.opts.tasks);
|
|---|
| 65 | assert.equal(undefined, res.opts.jakefile);
|
|---|
| 66 | });
|
|---|
| 67 |
|
|---|
| 68 | test('long preemptive opt and val without equal-sign, ignore further opts', function () {
|
|---|
| 69 | res = p.parse(z('--tasks foo --jakefile=asdf'));
|
|---|
| 70 | assert.equal('foo', res.opts.tasks);
|
|---|
| 71 | assert.equal(undefined, res.opts.jakefile);
|
|---|
| 72 | });
|
|---|
| 73 |
|
|---|
| 74 | test('long preemptive opt and no val, ignore further opts', function () {
|
|---|
| 75 | res = p.parse(z('--tasks --jakefile=asdf'));
|
|---|
| 76 | assert.equal(true, res.opts.tasks);
|
|---|
| 77 | assert.equal(undefined, res.opts.jakefile);
|
|---|
| 78 | });
|
|---|
| 79 |
|
|---|
| 80 | test('preemptive opt with no val, should be true', function () {
|
|---|
| 81 | res = p.parse(z('-T'));
|
|---|
| 82 | assert.equal(true, res.opts.tasks);
|
|---|
| 83 | });
|
|---|
| 84 |
|
|---|
| 85 | test('preemptive opt with no val, should be true and ignore further opts', function () {
|
|---|
| 86 | res = p.parse(z('-T -f'));
|
|---|
| 87 | assert.equal(true, res.opts.tasks);
|
|---|
| 88 | assert.equal(undefined, res.opts.jakefile);
|
|---|
| 89 | });
|
|---|
| 90 |
|
|---|
| 91 | test('preemptive opt with val, should be val', function () {
|
|---|
| 92 | res = p.parse(z('-T zoobie -f foo/bar/baz'));
|
|---|
| 93 | assert.equal('zoobie', res.opts.tasks);
|
|---|
| 94 | assert.equal(undefined, res.opts.jakefile);
|
|---|
| 95 | });
|
|---|
| 96 |
|
|---|
| 97 | test('-f expects a value, -t does not (howdy is task-name)', function () {
|
|---|
| 98 | res = p.parse(z('-f zoobie -t howdy'));
|
|---|
| 99 | assert.equal('zoobie', res.opts.jakefile);
|
|---|
| 100 | assert.equal(true, res.opts.trace);
|
|---|
| 101 | assert.equal('howdy', res.taskNames[0]);
|
|---|
| 102 | });
|
|---|
| 103 |
|
|---|
| 104 | test('different order, -f expects a value, -t does not (howdy is task-name)', function () {
|
|---|
| 105 | res = p.parse(z('-f zoobie howdy -t'));
|
|---|
| 106 | assert.equal('zoobie', res.opts.jakefile);
|
|---|
| 107 | assert.equal(true, res.opts.trace);
|
|---|
| 108 | assert.equal('howdy', res.taskNames[0]);
|
|---|
| 109 | });
|
|---|
| 110 |
|
|---|
| 111 | test('-f expects a value, -t does not (foo=bar is env var)', function () {
|
|---|
| 112 | res = p.parse(z('-f zoobie -t foo=bar'));
|
|---|
| 113 | assert.equal('zoobie', res.opts.jakefile);
|
|---|
| 114 | assert.equal(true, res.opts.trace);
|
|---|
| 115 | assert.equal('bar', res.envVars.foo);
|
|---|
| 116 | assert.equal(undefined, res.taskNames[0]);
|
|---|
| 117 | });
|
|---|
| 118 |
|
|---|
| 119 | test('-f expects a value, -t does not (foo=bar is env-var, task-name follows)', function () {
|
|---|
| 120 | res = p.parse(z('-f zoobie -t howdy foo=bar'));
|
|---|
| 121 | assert.equal('zoobie', res.opts.jakefile);
|
|---|
| 122 | assert.equal(true, res.opts.trace);
|
|---|
| 123 | assert.equal('bar', res.envVars.foo);
|
|---|
| 124 | assert.equal('howdy', res.taskNames[0]);
|
|---|
| 125 | });
|
|---|
| 126 |
|
|---|
| 127 | test('-t does not expect a value, -f does (howdy is task-name)', function () {
|
|---|
| 128 | res = p.parse(z('-t howdy -f zoobie'));
|
|---|
| 129 | assert.equal(true, res.opts.trace);
|
|---|
| 130 | assert.equal('zoobie', res.opts.jakefile);
|
|---|
| 131 | assert.equal('howdy', res.taskNames[0]);
|
|---|
| 132 | });
|
|---|
| 133 |
|
|---|
| 134 | test('--trace does not expect a value, -f does (howdy is task-name)', function () {
|
|---|
| 135 | res = p.parse(z('--trace howdy --jakefile zoobie'));
|
|---|
| 136 | assert.equal(true, res.opts.trace);
|
|---|
| 137 | assert.equal('zoobie', res.opts.jakefile);
|
|---|
| 138 | assert.equal('howdy', res.taskNames[0]);
|
|---|
| 139 | });
|
|---|
| 140 |
|
|---|
| 141 | test('--trace does not expect a value (equal), -f does (throw howdy away)', function () {
|
|---|
| 142 | res = p.parse(z('--trace=howdy --jakefile=zoobie'));
|
|---|
| 143 | assert.equal(true, res.opts.trace);
|
|---|
| 144 | assert.equal('zoobie', res.opts.jakefile);
|
|---|
| 145 | assert.equal(undefined, res.taskNames[0]);
|
|---|
| 146 | });
|
|---|
| 147 |
|
|---|
| 148 | /*
|
|---|
| 149 | , test('task-name with positional args', function () {
|
|---|
| 150 | res = p.parse(z('foo:bar[asdf,qwer]'));
|
|---|
| 151 | assert.equal('asdf', p.taskArgs[0]);
|
|---|
| 152 | assert.equal('qwer', p.taskArgs[1]);
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | , test('opts, env vars, task-name with positional args', function () {
|
|---|
| 156 | res = p.parse(z('-f ./tests/Jakefile -t default[asdf,qwer] foo=bar'));
|
|---|
| 157 | assert.equal('./tests/Jakefile', res.opts.jakefile);
|
|---|
| 158 | assert.equal(true, res.opts.trace);
|
|---|
| 159 | assert.equal('bar', res.envVars.foo);
|
|---|
| 160 | assert.equal('default', res.taskName);
|
|---|
| 161 | assert.equal('asdf', p.taskArgs[0]);
|
|---|
| 162 | assert.equal('qwer', p.taskArgs[1]);
|
|---|
| 163 | }
|
|---|
| 164 | */
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 | });
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|