diff options
author | cjihrig <cjihrig@gmail.com> | 2016-07-15 15:43:24 -0400 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2016-07-18 17:14:16 -0400 |
commit | 04b4d15b396a7befea31dbfec89f69ff71dc71ca (patch) | |
tree | 7819010b9b687fb20328c04645e9ec64c25b9328 /test/parallel/test-stdout-stderr-reading.js | |
parent | 59741a9beeb0ccaac6fc3247605bf090d36ad50e (diff) | |
download | android-node-v8-04b4d15b396a7befea31dbfec89f69ff71dc71ca.tar.gz android-node-v8-04b4d15b396a7befea31dbfec89f69ff71dc71ca.tar.bz2 android-node-v8-04b4d15b396a7befea31dbfec89f69ff71dc71ca.zip |
test: use mustCall() for simple flow tracking
Many of the tests use variables to track when callback functions
are invoked or events are emitted. These variables are then
asserted on process exit. This commit replaces this pattern in
straightforward cases with common.mustCall(). This makes the
tests easier to reason about, leads to a net reduction in lines
of code, and uncovered a few bugs in tests. This commit also
replaces some callbacks that should never be called with
common.fail().
PR-URL: https://github.com/nodejs/node/pull/7753
Reviewed-By: Wyatt Preul <wpreul@gmail.com>
Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'test/parallel/test-stdout-stderr-reading.js')
-rw-r--r-- | test/parallel/test-stdout-stderr-reading.js | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/test/parallel/test-stdout-stderr-reading.js b/test/parallel/test-stdout-stderr-reading.js index 2cc029c501..e154d41b6b 100644 --- a/test/parallel/test-stdout-stderr-reading.js +++ b/test/parallel/test-stdout-stderr-reading.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +const common = require('../common'); var assert = require('assert'); // verify that stdout is never read from. @@ -22,7 +22,6 @@ else function parent() { var spawn = require('child_process').spawn; var node = process.execPath; - var closes = 0; var c1 = spawn(node, [__filename, 'child']); var c1out = ''; @@ -34,13 +33,12 @@ function parent() { c1.stderr.on('data', function(chunk) { console.error('c1err: ' + chunk.split('\n').join('\nc1err: ')); }); - c1.on('close', function(code, signal) { - closes++; + c1.on('close', common.mustCall(function(code, signal) { assert(!code); assert(!signal); assert.equal(c1out, 'ok\n'); console.log('ok'); - }); + })); var c2 = spawn(node, ['-e', 'console.log("ok")']); var c2out = ''; @@ -52,17 +50,12 @@ function parent() { c1.stderr.on('data', function(chunk) { console.error('c1err: ' + chunk.split('\n').join('\nc1err: ')); }); - c2.on('close', function(code, signal) { - closes++; + c2.on('close', common.mustCall(function(code, signal) { assert(!code); assert(!signal); assert.equal(c2out, 'ok\n'); console.log('ok'); - }); - - process.on('exit', function() { - assert.equal(closes, 2, 'saw both closes'); - }); + })); } function child() { |