-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: create tests for newly sorted cli options
Created tests to validate that the newly ascii sorted cli options in the node.PrintHelp() function are being returned according to build configurations as expected.
- Loading branch information
1 parent
aa31cff
commit dd33653
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); |