• 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');
11const { internalBinding } = require('internal/test/binding');
12const { fipsMode } = internalBinding('config');
13let stdOut;
14
15
16function startPrintHelpTest() {
17  exec(`${process.execPath} --help`, common.mustCall((err, stdout, stderr) => {
18    assert.ifError(err);
19    stdOut = stdout;
20    validateNodePrintHelp();
21  }));
22}
23
24function validateNodePrintHelp() {
25  const HAVE_OPENSSL = common.hasCrypto;
26  const NODE_HAVE_I18N_SUPPORT = common.hasIntl;
27  const HAVE_INSPECTOR = process.features.inspector;
28
29  const cliHelpOptions = [
30    { compileConstant: HAVE_OPENSSL,
31      flags: [ '--openssl-config=...', '--tls-cipher-list=...',
32               '--use-bundled-ca', '--use-openssl-ca' ] },
33    { compileConstant: fipsMode,
34      flags: [ '--enable-fips', '--force-fips' ] },
35    { compileConstant: NODE_HAVE_I18N_SUPPORT,
36      flags: [ '--icu-data-dir=...', 'NODE_ICU_DATA' ] },
37    { compileConstant: HAVE_INSPECTOR,
38      flags: [ '--inspect-brk[=[host:]port]', '--inspect-port=[host:]port',
39               '--inspect[=[host:]port]' ] },
40  ];
41
42  cliHelpOptions.forEach(testForSubstring);
43}
44
45function testForSubstring(options) {
46  if (options.compileConstant) {
47    options.flags.forEach((flag) => {
48      assert.strictEqual(stdOut.indexOf(flag) !== -1, true,
49                         `Missing flag ${flag} in ${stdOut}`);
50    });
51  } else {
52    options.flags.forEach((flag) => {
53      assert.strictEqual(stdOut.indexOf(flag), -1,
54                         `Unexpected flag ${flag} in ${stdOut}`);
55    });
56  }
57}
58
59startPrintHelpTest();
60