mirror of https://github.com/lukechilds/node.git
Ryan Dahl
15 years ago
4 changed files with 74 additions and 23 deletions
@ -0,0 +1,9 @@ |
|||||
|
require("../common"); |
||||
|
Buffer = require("buffer").Buffer; |
||||
|
|
||||
|
var n = parseInt(process.argv[2]); |
||||
|
|
||||
|
b = new Buffer(n); |
||||
|
for (var i = 0; i < n; i++) { b[i] = 100; } |
||||
|
|
||||
|
process.stdout.write(b); |
@ -1,2 +0,0 @@ |
|||||
var sys = require('sys'); |
|
||||
sys.puts('test'); |
|
@ -1,19 +1,52 @@ |
|||||
require('../common'); |
require('../common'); |
||||
var path = require('path') |
path = require('path'); |
||||
, childProccess = require('child_process') |
childProccess = require('child_process'); |
||||
, fs = require('fs') |
fs = require('fs'); |
||||
, stdoutScript = path.join(path.dirname(__dirname), 'fixtures/stdout.js') |
scriptString = path.join(fixturesDir, 'print-chars.js'); |
||||
, tmpFile = path.join(path.dirname(__dirname), 'fixtures/stdout.txt') |
scriptBuffer = path.join(fixturesDir, 'print-chars-from-buffer.js'); |
||||
, cmd = process.argv[0]+' '+stdoutScript+' > '+tmpFile; |
tmpFile = path.join(fixturesDir, 'stdout.txt'); |
||||
|
|
||||
try { |
function test (size, useBuffer, cb) { |
||||
fs.unlinkSync(tmpFile); |
var cmd = process.argv[0] |
||||
} catch (e) {} |
+ ' ' |
||||
|
+ (useBuffer ? scriptBuffer : scriptString) |
||||
childProccess.exec(cmd, function(err) { |
+ ' ' |
||||
if (err) throw err; |
+ size |
||||
|
+ ' > ' |
||||
var data = fs.readFileSync(tmpFile); |
+ tmpFile |
||||
assert.equal(data, "test\n"); |
; |
||||
fs.unlinkSync(tmpFile); |
|
||||
|
try { |
||||
|
fs.unlinkSync(tmpFile); |
||||
|
} catch (e) {} |
||||
|
|
||||
|
print(size + ' chars to ' + tmpFile + '...'); |
||||
|
|
||||
|
childProccess.exec(cmd, function(err) { |
||||
|
if (err) throw err; |
||||
|
|
||||
|
puts('done!'); |
||||
|
|
||||
|
var stat = fs.statSync(tmpFile); |
||||
|
|
||||
|
puts(tmpFile + ' has ' + stat.size + ' bytes'); |
||||
|
|
||||
|
assert.equal(size, stat.size); |
||||
|
fs.unlinkSync(tmpFile); |
||||
|
|
||||
|
cb(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
finished = false; |
||||
|
test(1024*1024, false, function () { |
||||
|
puts("Done printing with string"); |
||||
|
test(1024*1024, true, function () { |
||||
|
puts("Done printing with buffer"); |
||||
|
finished = true; |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
process.addListener('exit', function () { |
||||
|
assert.ok(finished); |
||||
}); |
}); |
Loading…
Reference in new issue