summaryrefslogtreecommitdiff
path: root/test/simple/test-stdout-to-file.js
blob: 3df3bfad1f26e25e25974532c16ce7abda0815c5 (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
require('../common');
path = require('path');
childProccess = require('child_process');
fs = require('fs');
scriptString = path.join(fixturesDir, 'print-chars.js');
scriptBuffer = path.join(fixturesDir, 'print-chars-from-buffer.js');
tmpFile = path.join(fixturesDir, 'stdout.txt');

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

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

  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();
  });
}

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);
});