-
Notifications
You must be signed in to change notification settings - Fork 30.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
66 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
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,62 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
if (process.config.variables.node_without_node_options) | ||
common.skip('missing NODE_OPTIONS support'); | ||
|
||
// Test options specified by env variable. | ||
|
||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
const path = require('path') | ||
|
||
const rootDir = path.resolve(__dirname, '..', '..'); | ||
const cliMd = path.join(rootDir, 'doc', 'api', 'cli.md'); | ||
const cliText = fs.readFileSync(cliMd, { encoding: 'utf8' }); | ||
|
||
const nodeOptionsCC = fs.readFileSync(path.resolve(rootDir, 'src', 'node_options.cc'), 'utf8'); | ||
const addOptionRE = /AddOption[\s\n\r]*\([\s\n\r]*"([^"]+)"(.*?)\);/gs; | ||
|
||
const nodeOptionsText = cliText.match(/<!-- node-options-node start -->(.*)<!-- node-options-others end -->/s)[1]; | ||
|
||
for (const [, envVar, config ] of nodeOptionsCC.matchAll(addOptionRE)) { | ||
let hasTrueAsDefaultValue = false | ||
let isNodeOption = false; | ||
if (envVar.startsWith('[')) { | ||
continue; | ||
} | ||
|
||
if (config.includes('kAllowedInEnvvar')) { | ||
isNodeOption = true; | ||
} | ||
if (config.includes('kDisallowedInEnvvar')) { | ||
isNodeOption = false; | ||
} | ||
|
||
if (/^\s*true\s*$/.test(config.split(',').pop())) { | ||
hasTrueAsDefaultValue = true | ||
} | ||
|
||
if (!hasTrueAsDefaultValue && new RegExp(`\#\#\#.*\`${envVar}[\[=\\s\\b\`]`).test(cliText) === false) { | ||
console.log(`Should have option ${envVar} documented`) | ||
} | ||
|
||
if (!hasTrueAsDefaultValue && new RegExp(`\#\#\#.*\`--no-${envVar.slice(2)}[\[=\\s\\b\`]`).test(cliText) === true) { | ||
console.log(`Should not have option --no-${envVar.slice(2)} documented`) | ||
} | ||
|
||
if (hasTrueAsDefaultValue && new RegExp(`\#\#\#.*\`--no-${envVar.slice(2)}[\[=\\s\\b\`]`).test(cliText) === false) { | ||
console.log(`Should have option --no-${envVar.slice(2)} documented`) | ||
} | ||
|
||
if (!hasTrueAsDefaultValue && new RegExp(`\`${envVar}\``).test(nodeOptionsText) === false) { | ||
console.log(`Should have option ${envVar} in NODE_OPTIONS documented`) | ||
} | ||
|
||
if (hasTrueAsDefaultValue && new RegExp(`\`--no-${envVar.slice(2)}`).test(cliText) === false) { | ||
console.log(`Should have option --no-${envVar.slice(2)} in NODE_OPTIONS documented`) | ||
} | ||
|
||
if (!hasTrueAsDefaultValue && new RegExp(`\`--no-${envVar.slice(2)}`).test(cliText) === true) { | ||
console.log(`Should not have option --no-${envVar.slice(2)} in NODE_OPTIONS documented`) | ||
} | ||
} |