2019-01-15 05:14:30 +01:00
|
|
|
// Flags: --expose-internals
|
2018-04-08 01:33:19 -05:00
|
|
|
'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');
|
2024-05-12 14:43:13 -05:00
|
|
|
const { exec, spawn } = require('child_process');
|
|
|
|
const { once } = require('events');
|
2018-04-08 01:33:19 -05:00
|
|
|
let stdOut;
|
|
|
|
|
|
|
|
function startPrintHelpTest() {
|
2024-09-29 22:44:52 +02:00
|
|
|
exec(...common.escapePOSIXShell`"${process.execPath}" --help`, common.mustSucceed((stdout, stderr) => {
|
2018-04-08 01:33:19 -05:00
|
|
|
stdOut = stdout;
|
|
|
|
validateNodePrintHelp();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
function validateNodePrintHelp() {
|
|
|
|
const HAVE_OPENSSL = common.hasCrypto;
|
|
|
|
const NODE_HAVE_I18N_SUPPORT = common.hasIntl;
|
2019-01-30 23:19:45 +08:00
|
|
|
const HAVE_INSPECTOR = process.features.inspector;
|
2018-04-08 01:33:19 -05:00
|
|
|
|
|
|
|
const cliHelpOptions = [
|
|
|
|
{ compileConstant: HAVE_OPENSSL,
|
2018-08-23 22:07:13 +02:00
|
|
|
flags: [ '--openssl-config=...', '--tls-cipher-list=...',
|
2025-01-28 15:54:50 +00:00
|
|
|
'--use-bundled-ca', '--use-openssl-ca', '--use-system-ca',
|
2020-08-25 14:04:54 +02:00
|
|
|
'--enable-fips', '--force-fips' ] },
|
2018-04-08 01:33:19 -05:00
|
|
|
{ compileConstant: NODE_HAVE_I18N_SUPPORT,
|
2018-08-23 22:07:13 +02:00
|
|
|
flags: [ '--icu-data-dir=...', 'NODE_ICU_DATA' ] },
|
2018-04-08 01:33:19 -05:00
|
|
|
{ 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) => {
|
2018-08-23 22:40:01 +02:00
|
|
|
assert.strictEqual(stdOut.indexOf(flag) !== -1, true,
|
|
|
|
`Missing flag ${flag} in ${stdOut}`);
|
2018-04-08 01:33:19 -05:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
options.flags.forEach((flag) => {
|
2018-08-23 22:40:01 +02:00
|
|
|
assert.strictEqual(stdOut.indexOf(flag), -1,
|
|
|
|
`Unexpected flag ${flag} in ${stdOut}`);
|
2018-04-08 01:33:19 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
startPrintHelpTest();
|
2024-05-12 14:43:13 -05:00
|
|
|
|
|
|
|
// Test closed stdout for `node --help`. Like `node --help | head -n5`.
|
|
|
|
(async () => {
|
|
|
|
const cp = spawn(process.execPath, ['--help'], {
|
|
|
|
stdio: ['inherit', 'pipe', 'inherit'],
|
|
|
|
});
|
|
|
|
cp.stdout.destroy();
|
|
|
|
const [exitCode] = await once(cp, 'exit');
|
|
|
|
assert.strictEqual(exitCode, 0);
|
|
|
|
})().then(common.mustCall());
|