• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4const path = require('path');
5const childProcess = require('child_process');
6const fs = require('fs');
7const fixtures = require('../common/fixtures');
8const tmpdir = require('../common/tmpdir');
9
10const scriptString = fixtures.path('print-chars.js');
11const scriptBuffer = fixtures.path('print-chars-from-buffer.js');
12const tmpFile = path.join(tmpdir.path, 'stdout.txt');
13
14tmpdir.refresh();
15
16function test(size, useBuffer, cb) {
17  const cmd = `"${process.argv[0]}" "${
18    useBuffer ? scriptBuffer : scriptString}" ${size} > "${tmpFile}"`;
19
20  try {
21    fs.unlinkSync(tmpFile);
22  } catch {}
23
24  console.log(`${size} chars to ${tmpFile}...`);
25
26  childProcess.exec(cmd, common.mustSucceed(() => {
27    console.log('done!');
28
29    const stat = fs.statSync(tmpFile);
30
31    console.log(`${tmpFile} has ${stat.size} bytes`);
32
33    assert.strictEqual(size, stat.size);
34    fs.unlinkSync(tmpFile);
35
36    cb();
37  }));
38}
39
40test(1024 * 1024, false, common.mustCall(function() {
41  console.log('Done printing with string');
42  test(1024 * 1024, true, common.mustCall(function() {
43    console.log('Done printing with buffer');
44  }));
45}));
46