2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-09-29 03:55:59 +02:00
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
2012-06-20 19:28:44 +02:00
|
|
|
|
|
|
|
// simulate `cat readfile.js | node readfile.js`
|
|
|
|
|
2015-08-12 17:53:33 +02:00
|
|
|
if (common.isWindows || common.isAix) {
|
2016-09-29 03:30:32 +02:00
|
|
|
common.skip(`No /dev/stdin on ${process.platform}.`);
|
2015-07-07 17:25:55 +02:00
|
|
|
return;
|
2012-06-20 19:28:44 +02:00
|
|
|
}
|
|
|
|
|
2016-09-29 03:55:59 +02:00
|
|
|
const fs = require('fs');
|
2012-06-20 19:28:44 +02:00
|
|
|
|
2016-09-29 03:55:59 +02:00
|
|
|
const dataExpected = fs.readFileSync(__filename, 'utf8');
|
2012-06-20 19:28:44 +02:00
|
|
|
|
|
|
|
if (process.argv[2] === 'child') {
|
|
|
|
fs.readFile('/dev/stdin', function(er, data) {
|
|
|
|
if (er) throw er;
|
|
|
|
process.stdout.write(data);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-29 03:55:59 +02:00
|
|
|
const exec = require('child_process').exec;
|
|
|
|
const f = JSON.stringify(__filename);
|
|
|
|
const node = JSON.stringify(process.execPath);
|
|
|
|
const cmd = `cat ${f} | ${node} ${f} child`;
|
2012-06-20 19:28:44 +02:00
|
|
|
exec(cmd, function(err, stdout, stderr) {
|
|
|
|
if (err) console.error(err);
|
|
|
|
assert(!err, 'it exits normally');
|
2016-09-17 12:32:33 +02:00
|
|
|
assert.strictEqual(stdout, dataExpected, 'it reads the file and outputs it');
|
|
|
|
assert.strictEqual(stderr, '', 'it does not write to stderr');
|
2012-06-20 19:28:44 +02:00
|
|
|
console.log('ok');
|
|
|
|
});
|