summaryrefslogtreecommitdiff
path: root/test/parallel/test-cli-node-print-help.js
blob: 7e21f01b69c0d8a8c0e08826736269ca0f3dece8 (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
54
55
56
57
58
'use strict';

const common = require('../common');

// The following tests assert that the node.cc PrintHelp() function
// returns the proper set of cli options when invoked

const assert = require('assert');
const { exec } = require('child_process');
let stdOut;


function startPrintHelpTest() {
  exec(`${process.execPath} --help`, common.mustCall((err, stdout, stderr) => {
    assert.ifError(err);
    stdOut = stdout;
    validateNodePrintHelp();
  }));
}

function validateNodePrintHelp() {
  const config = process.config;
  const HAVE_OPENSSL = common.hasCrypto;
  const NODE_FIPS_MODE = common.hasFipsCrypto;
  const NODE_HAVE_I18N_SUPPORT = common.hasIntl;
  const HAVE_INSPECTOR = config.variables.v8_enable_inspector === 1;

  const cliHelpOptions = [
    { compileConstant: HAVE_OPENSSL,
      flags: [ '--openssl-config=file', '--tls-cipher-list=val',
               '--use-bundled-ca', '--use-openssl-ca' ] },
    { compileConstant: NODE_FIPS_MODE,
      flags: [ '--enable-fips', '--force-fips' ] },
    { compileConstant: NODE_HAVE_I18N_SUPPORT,
      flags: [ '--experimental-modules', '--experimental-vm-modules',
               '--icu-data-dir=dir', '--preserve-symlinks',
               'NODE_ICU_DATA', 'NODE_PRESERVE_SYMLINKS' ] },
    { compileConstant: HAVE_INSPECTOR,
      flags: [ '--inspect-brk[=[host:]port]', '--inspect-port=[host:]port',
               '--inspect[=[host:]port]' ] },
  ];

  cliHelpOptions.forEach(testForSubstring);
}

function testForSubstring(options) {
  if (options.compileConstant) {
    options.flags.forEach((flag) => {
      assert.strictEqual(stdOut.indexOf(flag) !== -1, true);
    });
  } else {
    options.flags.forEach((flag) => {
      assert.strictEqual(stdOut.indexOf(flag), -1);
    });
  }
}

startPrintHelpTest();