• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --expose-internals
2'use strict';
3
4const common = require('../common');
5
6// The following tests assert that the node.cc PrintHelp() function
7// returns the proper set of cli options when invoked
8
9const assert = require('assert');
10const { exec } = require('child_process');
11let stdOut;
12
13
14function startPrintHelpTest() {
15  exec(`${process.execPath} --help`, common.mustSucceed((stdout, stderr) => {
16    stdOut = stdout;
17    validateNodePrintHelp();
18  }));
19}
20
21function validateNodePrintHelp() {
22  const HAVE_OPENSSL = common.hasCrypto;
23  const NODE_HAVE_I18N_SUPPORT = common.hasIntl;
24  const HAVE_INSPECTOR = process.features.inspector;
25
26  const cliHelpOptions = [
27    { compileConstant: HAVE_OPENSSL,
28      flags: [ '--openssl-config=...', '--tls-cipher-list=...',
29               '--use-bundled-ca', '--use-openssl-ca',
30               '--enable-fips', '--force-fips' ] },
31    { compileConstant: NODE_HAVE_I18N_SUPPORT,
32      flags: [ '--icu-data-dir=...', 'NODE_ICU_DATA' ] },
33    { compileConstant: HAVE_INSPECTOR,
34      flags: [ '--inspect-brk[=[host:]port]', '--inspect-port=[host:]port',
35               '--inspect[=[host:]port]' ] },
36  ];
37
38  cliHelpOptions.forEach(testForSubstring);
39}
40
41function testForSubstring(options) {
42  if (options.compileConstant) {
43    options.flags.forEach((flag) => {
44      assert.strictEqual(stdOut.indexOf(flag) !== -1, true,
45                         `Missing flag ${flag} in ${stdOut}`);
46    });
47  } else {
48    options.flags.forEach((flag) => {
49      assert.strictEqual(stdOut.indexOf(flag), -1,
50                         `Unexpected flag ${flag} in ${stdOut}`);
51    });
52  }
53}
54
55startPrintHelpTest();
56