• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5const execFile = require('child_process').execFile;
6const { getSystemErrorName } = require('util');
7const fixtures = require('../common/fixtures');
8
9const fixture = fixtures.path('exit.js');
10const execOpts = { encoding: 'utf8', shell: true };
11
12{
13  execFile(
14    process.execPath,
15    [fixture, 42],
16    common.mustCall((e) => {
17      // Check that arguments are included in message
18      assert.strictEqual(e.message.trim(),
19                         `Command failed: ${process.execPath} ${fixture} 42`);
20      assert.strictEqual(e.code, 42);
21    })
22  );
23}
24
25{
26  // Verify that negative exit codes can be translated to UV error names.
27  const errorString = `Error: Command failed: ${process.execPath}`;
28  const code = -1;
29  const callback = common.mustCall((err, stdout, stderr) => {
30    assert.strictEqual(err.toString().trim(), errorString);
31    assert.strictEqual(err.code, getSystemErrorName(code));
32    assert.strictEqual(err.killed, true);
33    assert.strictEqual(err.signal, null);
34    assert.strictEqual(err.cmd, process.execPath);
35    assert.strictEqual(stdout.trim(), '');
36    assert.strictEqual(stderr.trim(), '');
37  });
38  const child = execFile(process.execPath, callback);
39
40  child.kill();
41  child.emit('close', code, null);
42}
43
44{
45  // Verify the shell option works properly
46  execFile(process.execPath, [fixture, 0], execOpts, common.mustCall((err) => {
47    assert.ifError(err);
48  }));
49}
50