|
| 1 | +// Copyright Joyent, Inc. and other Node contributors. |
| 2 | +// |
| 3 | +// Permission is hereby granted, free of charge, to any person obtaining a |
| 4 | +// copy of this software and associated documentation files (the |
| 5 | +// "Software"), to deal in the Software without restriction, including |
| 6 | +// without limitation the rights to use, copy, modify, merge, publish, |
| 7 | +// distribute, sublicense, and/or sell copies of the Software, and to permit |
| 8 | +// persons to whom the Software is furnished to do so, subject to the |
| 9 | +// following conditions: |
| 10 | +// |
| 11 | +// The above copyright notice and this permission notice shall be included |
| 12 | +// in all copies or substantial portions of the Software. |
| 13 | +// |
| 14 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 | +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 16 | +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN |
| 17 | +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 18 | +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 19 | +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 20 | +// USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 | + |
| 22 | +var common = require('../common'); |
| 23 | +var assert = require('assert'); |
| 24 | + |
| 25 | +// simulate `cat readfile.js | node readfile.js` |
| 26 | + |
| 27 | +// TODO: Have some way to make this work on windows. |
| 28 | +if (process.platform === 'win32') { |
| 29 | + console.error('No /dev/stdin on windows. Skipping test.'); |
| 30 | + process.exit(); |
| 31 | +} |
| 32 | + |
| 33 | +var fs = require('fs'); |
| 34 | + |
| 35 | +var dataExpected = fs.readFileSync(__filename, 'utf8'); |
| 36 | + |
| 37 | +if (process.argv[2] === 'child') { |
| 38 | + fs.readFile('/dev/stdin', function(er, data) { |
| 39 | + if (er) throw er; |
| 40 | + process.stdout.write(data); |
| 41 | + }); |
| 42 | + return; |
| 43 | +} |
| 44 | + |
| 45 | +var exec = require('child_process').exec; |
| 46 | +var f = JSON.stringify(__filename); |
| 47 | +var node = JSON.stringify(process.execPath); |
| 48 | +var cmd = 'cat ' + f + ' | ' + node + ' ' + f + ' child'; |
| 49 | +exec(cmd, function(err, stdout, stderr) { |
| 50 | + if (err) console.error(err); |
| 51 | + assert(!err, 'it exits normally'); |
| 52 | + assert(stdout === dataExpected, 'it reads the file and outputs it'); |
| 53 | + assert(stderr === '', 'it does not write to stderr'); |
| 54 | + console.log('ok'); |
| 55 | +}); |
0 commit comments