|  | 
| 1 | 1 | 'use strict'; | 
| 2 |  | -require('../common'); | 
| 3 |  | -var assert = require('assert'); | 
|  | 2 | +const common = require('../common'); | 
|  | 3 | +const assert = require('assert'); | 
|  | 4 | +const spawn = require('child_process').spawn; | 
| 4 | 5 | 
 | 
| 5 |  | -var errs = 0; | 
|  | 6 | +if (process.argv[2] === 'child') { | 
|  | 7 | +  var errs = 0; | 
| 6 | 8 | 
 | 
| 7 |  | -process.stdin.resume(); | 
| 8 |  | -process.stdin._handle.close(); | 
| 9 |  | -process.stdin._handle.unref();  // Should not segfault. | 
| 10 |  | -process.stdin.on('error', function(err) { | 
| 11 |  | -  errs++; | 
| 12 |  | -}); | 
|  | 9 | +  process.stdin.resume(); | 
|  | 10 | +  process.stdin._handle.close(); | 
|  | 11 | +  process.stdin._handle.unref();  // Should not segfault. | 
|  | 12 | +  process.stdin.on('error', function(err) { | 
|  | 13 | +    errs++; | 
|  | 14 | +  }); | 
| 13 | 15 | 
 | 
| 14 |  | -process.on('exit', function() { | 
| 15 |  | -  assert.strictEqual(errs, 1); | 
| 16 |  | -}); | 
|  | 16 | +  process.on('exit', function() { | 
|  | 17 | +    assert.strictEqual(errs, 1); | 
|  | 18 | +  }); | 
|  | 19 | +  return; | 
|  | 20 | +} | 
|  | 21 | + | 
|  | 22 | +// Use spawn so that we can be sure that stdin has a _handle property. | 
|  | 23 | +// Refs: https://github.com/nodejs/node/pull/5916 | 
|  | 24 | +const proc = spawn(process.execPath, [__filename, 'child'], { stdio: 'pipe' }); | 
|  | 25 | + | 
|  | 26 | +proc.stderr.pipe(process.stderr); | 
|  | 27 | +proc.on('exit', common.mustCall(function(exitCode) { | 
|  | 28 | +  if (exitCode !== 0) | 
|  | 29 | +    process.exitCode = exitCode; | 
|  | 30 | +})); | 
0 commit comments