diff options
author | Rich Trott <rtrott@gmail.com> | 2016-06-23 10:51:48 -0700 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2016-06-30 16:04:54 -0700 |
commit | 0268fd0a9f3a1bfcb9a544017414a39400a4bcfd (patch) | |
tree | 8e4b5d84691b27ff6601cb37f4d357685a8aafca /test | |
parent | 8da541bf5f42031ad966c6b92bb1e153c44eb778 (diff) | |
download | node-new-0268fd0a9f3a1bfcb9a544017414a39400a4bcfd.tar.gz |
child_process: preserve argument type
A previous fix for a `maxBuffer` bug resulted in a change to the
argument type for the `data` event on `child.stdin` and `child.stdout`
when using `child_process.exec()`.
This fixes the `maxBuffer` bug in a way that does not have that side
effect.
PR-URL: https://github.com/nodejs/node/pull/7391
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jackson Tian <shyvo1987@gmail.com>
Fixes: https://github.com/nodejs/node/issues/7342
Refs: https://github.com/nodejs/node/issues/1901
Diffstat (limited to 'test')
-rw-r--r-- | test/known_issues/test-child-process-max-buffer.js | 16 | ||||
-rw-r--r-- | test/parallel/test-child-process-exec-maxBuffer.js | 31 | ||||
-rw-r--r-- | test/parallel/test-child-process-exec-stdout-stderr-data-string.js (renamed from test/parallel/test-child-process-exec-stdout-data-string.js) | 20 | ||||
-rw-r--r-- | test/parallel/test-exec-max-buffer.js | 11 |
4 files changed, 44 insertions, 34 deletions
diff --git a/test/known_issues/test-child-process-max-buffer.js b/test/known_issues/test-child-process-max-buffer.js deleted file mode 100644 index 14a344c706..0000000000 --- a/test/known_issues/test-child-process-max-buffer.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict'; -// Refs: https://github.com/nodejs/node/issues/1901 -const common = require('../common'); -const assert = require('assert'); -const cp = require('child_process'); -const unicode = '中文测试'; // Length = 4, Byte length = 13 - -if (process.argv[2] === 'child') { - console.log(unicode); -} else { - const cmd = `${process.execPath} ${__filename} child`; - - cp.exec(cmd, { maxBuffer: 10 }, common.mustCall((err, stdout, stderr) => { - assert.strictEqual(err.message, 'stdout maxBuffer exceeded'); - })); -} diff --git a/test/parallel/test-child-process-exec-maxBuffer.js b/test/parallel/test-child-process-exec-maxBuffer.js new file mode 100644 index 0000000000..714e029d72 --- /dev/null +++ b/test/parallel/test-child-process-exec-maxBuffer.js @@ -0,0 +1,31 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const cp = require('child_process'); + +function checkFactory(streamName) { + return common.mustCall((err) => { + const message = `${streamName} maxBuffer exceeded`; + assert.strictEqual(err.message, message); + }); +} + +{ + const cmd = 'echo "hello world"'; + + cp.exec(cmd, { maxBuffer: 5 }, checkFactory('stdout')); +} + +const unicode = '中文测试'; // length = 4, byte length = 12 + +{ + const cmd = `"${process.execPath}" -e "console.log('${unicode}');"`; + + cp.exec(cmd, {maxBuffer: 10}, checkFactory('stdout')); +} + +{ + const cmd = `"${process.execPath}" -e "console.('${unicode}');"`; + + cp.exec(cmd, {maxBuffer: 10}, checkFactory('stderr')); +} diff --git a/test/parallel/test-child-process-exec-stdout-data-string.js b/test/parallel/test-child-process-exec-stdout-stderr-data-string.js index a646918957..8ab834c98f 100644 --- a/test/parallel/test-child-process-exec-stdout-data-string.js +++ b/test/parallel/test-child-process-exec-stdout-stderr-data-string.js @@ -4,14 +4,20 @@ const common = require('../common'); const assert = require('assert'); const exec = require('child_process').exec; -const expectedCalls = 2; - -const cb = common.mustCall((data) => { - assert.strictEqual(typeof data, 'string'); -}, expectedCalls); +var stdoutCalls = 0; +var stderrCalls = 0; const command = common.isWindows ? 'dir' : 'ls'; -exec(command).stdout.on('data', cb); +exec(command).stdout.on('data', (data) => { + stdoutCalls += 1; +}); -exec('fhqwhgads').stderr.on('data', cb); +exec('fhqwhgads').stderr.on('data', (data) => { + assert.strictEqual(typeof data, 'string'); + stderrCalls += 1; +}); +process.on('exit', () => { + assert(stdoutCalls > 0); + assert(stderrCalls > 0); +}); diff --git a/test/parallel/test-exec-max-buffer.js b/test/parallel/test-exec-max-buffer.js deleted file mode 100644 index 15c6e70259..0000000000 --- a/test/parallel/test-exec-max-buffer.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; -require('../common'); -var exec = require('child_process').exec; -var assert = require('assert'); - -var cmd = 'echo "hello world"'; - -exec(cmd, { maxBuffer: 5 }, function(err, stdout, stderr) { - assert.ok(err); - assert.ok(/maxBuffer/.test(err.message)); -}); |