Skip to content

Commit

Permalink
test: check fd 0,1,2 are used, not access mode
Browse files Browse the repository at this point in the history
Don't do a write on stdout/stderr because that checks for their
writability. But fd=1 could legitimately be opened with read-only
access by the user. All this test needs to ensure is that
they are used at startup.

PR-URL: #10339
Fixes: #10234
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
jBarz authored and MylesBorins committed Mar 8, 2017
1 parent de1faeb commit df8438a
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions test/parallel/test-stdio-closed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,15 @@
const common = require('../common');
const assert = require('assert');
const spawn = require('child_process').spawn;
const fs = require('fs');

if (common.isWindows) {
common.skip('platform not supported.');
return;
}

if (process.argv[2] === 'child') {
try {
process.stdout.write('stdout', function() {
try {
process.stderr.write('stderr', function() {
process.exit(42);
});
} catch (e) {
process.exit(84);
}
});
} catch (e) {
assert.strictEqual(e.code, 'EBADF');
assert.strictEqual(e.message, 'EBADF: bad file descriptor, write');
process.exit(126);
}
[0, 1, 2].forEach((i) => assert.doesNotThrow(() => fs.fstatSync(i)));
return;
}

Expand All @@ -32,5 +19,5 @@ const cmd = `"${process.execPath}" "${__filename}" child 1>&- 2>&-`;
const proc = spawn('/bin/sh', ['-c', cmd], { stdio: 'inherit' });

proc.on('exit', common.mustCall(function(exitCode) {
assert.strictEqual(exitCode, common.isAix ? 126 : 42);
assert.strictEqual(exitCode, 0);
}));

0 comments on commit df8438a

Please sign in to comment.