From 4c7bce2dc08ffd477d41f8754a1c53a3c7b170c5 Mon Sep 17 00:00:00 2001 From: Mickael Daniel Date: Sun, 22 Jul 2018 17:51:57 +0200 Subject: [PATCH] test: recover some coverage --- lib/index.js | 12 ++++++------ test/basic.js | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/lib/index.js b/lib/index.js index e931b7c..a552b14 100644 --- a/lib/index.js +++ b/lib/index.js @@ -66,11 +66,6 @@ tabtab.install = (options = { name: '', completer: '' }) => { * Returns the data env object. */ tabtab.parseEnv = (options = {}, env) => { - // debug('COMP_CWORD', env.COMP_CWORD); - // debug('COMP_LINE', env.COMP_LINE); - // debug('COMP_POINT', env.COMP_POINT); - - options = options || {}; const args = options._; let cword = Number(env.COMP_CWORD); @@ -128,7 +123,7 @@ tabtab.parseEnv = (options = {}, env) => { **/ tabtab.log = (args, env) => { if (!env) { - env = tabtab.parseEnv(process.env); + env = tabtab.parseEnv({ _: [] }, process.env); } const shell = tabtab.shell(); @@ -139,6 +134,11 @@ tabtab.log = (args, env) => { for (const arg of args) { console.log(`\n${arg}`); } + + return { + args, + env + }; }; module.exports = tabtab; diff --git a/test/basic.js b/test/basic.js index a23e3d3..864a800 100644 --- a/test/basic.js +++ b/test/basic.js @@ -10,12 +10,46 @@ describe('tabtab basic suite', () => { it('has a tabtab.log function', () => { assert.equal(typeof tabtab.log, 'function'); - const env = Object.assign({}, process.env, { + const environment = Object.assign({}, process.env, { COMP_CWORD: 2, COMP_LINE: 'tabtab --foo', COMP_POINT: 12 }); - tabtab.log(['--foo', '--bar'], env); + const env = tabtab.parseEnv({ _: ['tabtab'] }, environment); + + const result = tabtab.log(['--foo', '--bar'], env); + assert.deepEqual(result.args, ['--foo']); + assert.deepEqual(result.env, env); + }); + + it('has a tabtab.log function, without env', () => { + const result = tabtab.log(['--foo', '--bar']); + assert.deepEqual(result.args, ['--foo', '--bar']); + assert.deepEqual(result.env, { + args: [], + complete: false, + last: '', + lastPartial: '', + line: '', + partial: '', + point: 0, + prev: undefined, + words: 0 + }); + }); + + it('tabtab.shell()', () => { + let shell = tabtab.shell(); + assert.equal(shell, 'bash'); + + shell = tabtab.shell({ SHELL: '/bin/bash' }); + assert.equal(shell, 'bash'); + + shell = tabtab.shell({ SHELL: '/usr/bin/zsh'}); + assert.equal(shell, 'zsh'); + + shell = tabtab.shell({ SHELL: '/usr/bin/fish'}); + assert.equal(shell, 'fish'); }); });