From 63ef0990f30a607bc242b48a1d8af01ce997d85e Mon Sep 17 00:00:00 2001 From: cjihrig Date: Thu, 20 Oct 2016 13:45:38 -0400 Subject: [PATCH] test: add coverage for execFileSync() errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds coverage for errors returned by execFileSync() when the child process exits with a non-zero code. PR-URL: https://github.com/nodejs/node/pull/9211 Reviewed-By: Michaƫl Zasso Reviewed-By: Sakthipriyan Vairamani Reviewed-By: James M Snell Reviewed-By: Ben Noordhuis --- test/sequential/test-child-process-execsync.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/sequential/test-child-process-execsync.js b/test/sequential/test-child-process-execsync.js index 01d7f868845ae0..137ddbda425f2c 100644 --- a/test/sequential/test-child-process-execsync.js +++ b/test/sequential/test-child-process-execsync.js @@ -87,3 +87,19 @@ assert.strictEqual(ret, msg + '\n', execSync('exit -1', {stdio: 'ignore'}); }, /Command failed: exit -1/); } + +// Verify the execFileSync() behavior when the child exits with a non-zero code. +{ + const args = ['-e', 'process.exit(1)']; + + assert.throws(() => { + execFileSync(process.execPath, args); + }, (err) => { + const msg = `Command failed: ${process.execPath} ${args.join(' ')}`; + + assert(err instanceof Error); + assert.strictEqual(err.message.trim(), msg); + assert.strictEqual(err.status, 1); + return true; + }); +}