11cb0ef41Sopenharmony_ci// Flags: --expose-internals
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciconst common = require('../common');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci// The following tests assert that the node.cc PrintHelp() function
71cb0ef41Sopenharmony_ci// returns the proper set of cli options when invoked
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst assert = require('assert');
101cb0ef41Sopenharmony_ciconst { exec } = require('child_process');
111cb0ef41Sopenharmony_cilet stdOut;
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_cifunction startPrintHelpTest() {
151cb0ef41Sopenharmony_ci  exec(`${process.execPath} --help`, common.mustSucceed((stdout, stderr) => {
161cb0ef41Sopenharmony_ci    stdOut = stdout;
171cb0ef41Sopenharmony_ci    validateNodePrintHelp();
181cb0ef41Sopenharmony_ci  }));
191cb0ef41Sopenharmony_ci}
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_cifunction validateNodePrintHelp() {
221cb0ef41Sopenharmony_ci  const HAVE_OPENSSL = common.hasCrypto;
231cb0ef41Sopenharmony_ci  const NODE_HAVE_I18N_SUPPORT = common.hasIntl;
241cb0ef41Sopenharmony_ci  const HAVE_INSPECTOR = process.features.inspector;
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci  const cliHelpOptions = [
271cb0ef41Sopenharmony_ci    { compileConstant: HAVE_OPENSSL,
281cb0ef41Sopenharmony_ci      flags: [ '--openssl-config=...', '--tls-cipher-list=...',
291cb0ef41Sopenharmony_ci               '--use-bundled-ca', '--use-openssl-ca',
301cb0ef41Sopenharmony_ci               '--enable-fips', '--force-fips' ] },
311cb0ef41Sopenharmony_ci    { compileConstant: NODE_HAVE_I18N_SUPPORT,
321cb0ef41Sopenharmony_ci      flags: [ '--icu-data-dir=...', 'NODE_ICU_DATA' ] },
331cb0ef41Sopenharmony_ci    { compileConstant: HAVE_INSPECTOR,
341cb0ef41Sopenharmony_ci      flags: [ '--inspect-brk[=[host:]port]', '--inspect-port=[host:]port',
351cb0ef41Sopenharmony_ci               '--inspect[=[host:]port]' ] },
361cb0ef41Sopenharmony_ci  ];
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci  cliHelpOptions.forEach(testForSubstring);
391cb0ef41Sopenharmony_ci}
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_cifunction testForSubstring(options) {
421cb0ef41Sopenharmony_ci  if (options.compileConstant) {
431cb0ef41Sopenharmony_ci    options.flags.forEach((flag) => {
441cb0ef41Sopenharmony_ci      assert.strictEqual(stdOut.indexOf(flag) !== -1, true,
451cb0ef41Sopenharmony_ci                         `Missing flag ${flag} in ${stdOut}`);
461cb0ef41Sopenharmony_ci    });
471cb0ef41Sopenharmony_ci  } else {
481cb0ef41Sopenharmony_ci    options.flags.forEach((flag) => {
491cb0ef41Sopenharmony_ci      assert.strictEqual(stdOut.indexOf(flag), -1,
501cb0ef41Sopenharmony_ci                         `Unexpected flag ${flag} in ${stdOut}`);
511cb0ef41Sopenharmony_ci    });
521cb0ef41Sopenharmony_ci  }
531cb0ef41Sopenharmony_ci}
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_cistartPrintHelpTest();
56