From 4ceca76729c577166395f19172854cbbcce3cec1 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Sat, 9 Apr 2022 19:48:49 -0700 Subject: [PATCH] fix(bin): get correct value from arg separated by equals (#449) Fixes #431 --- bin/semver.js | 3 ++- tap-snapshots/test/bin/semver.js.test.cjs | 2 +- test/bin/semver.js | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/bin/semver.js b/bin/semver.js index 779b8b0c..8d1b5572 100755 --- a/bin/semver.js +++ b/bin/semver.js @@ -37,8 +37,9 @@ const main = () => { let a = argv.shift() const indexOfEqualSign = a.indexOf('=') if (indexOfEqualSign !== -1) { + const value = a.slice(indexOfEqualSign + 1) a = a.slice(0, indexOfEqualSign) - argv.unshift(a.slice(indexOfEqualSign + 1)) + argv.unshift(value) } switch (a) { case '-rv': case '-rev': case '--rev': case '--reverse': diff --git a/tap-snapshots/test/bin/semver.js.test.cjs b/tap-snapshots/test/bin/semver.js.test.cjs index 0e11ff06..4093fdab 100644 --- a/tap-snapshots/test/bin/semver.js.test.cjs +++ b/tap-snapshots/test/bin/semver.js.test.cjs @@ -305,7 +305,7 @@ exports[`test/bin/semver.js TAP inc tests > -i premajor 1.0.0 --preid=beta 1`] = Object { "code": 0, "err": "", - "out": "2.0.0-0\\n", + "out": "2.0.0-beta.0\\n", "signal": null, } ` diff --git a/test/bin/semver.js b/test/bin/semver.js index 56ca6a1c..04333fd5 100644 --- a/test/bin/semver.js +++ b/test/bin/semver.js @@ -60,3 +60,21 @@ t.test('coercing', t => Promise.all([ ['not a version', '1.2.3', '-c'], ['not a version', '-c'], ].map(args => t.resolveMatchSnapshot(run(args), args.join(' '))))) + +t.test('args with equals', t => Promise.all([ + [['--version', '1.2.3'], '1.2.3'], + [['--range', '1'], ['1.2.3'], ['2.3.4'], '1.2.3'], + [['--increment', 'major'], ['1.0.0'], '2.0.0'], + [['--increment', 'premajor'], ['--preid', 'beta'], ['1.0.0'], '2.0.0-beta.0'], +].map(async (args) => { + const expected = args.pop() + const equals = args.map((a) => a.join('=')) + const spaces = args.reduce((acc, a) => acc.concat(a), []) + const res1 = await run(equals) + const res2 = await run(spaces) + t.equal(res1.signal, null) + t.equal(res1.code, 0) + t.equal(res1.err, '') + t.equal(res1.out.trim(), expected) + t.strictSame(res1, res2, args.join(' ')) +})))