Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test-stdout-to-file.js « simple « test - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 44206589a25a0401c962cf3d79531b5b159b66c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var common = require('../common');
var assert = require('assert');
var path = require('path');
var childProccess = require('child_process');
var fs = require('fs');

var scriptString = path.join(common.fixturesDir, 'print-chars.js');
var scriptBuffer = path.join(common.fixturesDir, 'print-chars-from-buffer.js');
var tmpFile = path.join(common.fixturesDir, 'stdout.txt');

function test(size, useBuffer, cb) {
  var cmd = '"' + process.argv[0] + '"' +
            ' ' +
            '"' + (useBuffer ? scriptBuffer : scriptString) + '"' +
            ' ' +
            size +
            ' > ' +
            '"' + tmpFile + '"';

  try {
    fs.unlinkSync(tmpFile);
  } catch (e) {}

  common.print(size + ' chars to ' + tmpFile + '...');

  childProccess.exec(cmd, function(err) {
    if (err) throw err;

    console.log('done!');

    var stat = fs.statSync(tmpFile);

    console.log(tmpFile + ' has ' + stat.size + ' bytes');

    assert.equal(size, stat.size);
    fs.unlinkSync(tmpFile);

    cb();
  });
}

var finished = false;
test(1024 * 1024, false, function() {
  console.log('Done printing with string');
  test(1024 * 1024, true, function() {
    console.log('Done printing with buffer');
    finished = true;
  });
});

process.addListener('exit', function() {
  assert.ok(finished);
});