|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +if (process.config.variables.node_without_node_options) |
| 4 | + common.skip('missing NODE_OPTIONS support'); |
| 5 | + |
| 6 | +// Test options specified by env variable. |
| 7 | + |
| 8 | +const assert = require('assert'); |
| 9 | +const fs = require('fs'); |
| 10 | +const path = require('path') |
| 11 | + |
| 12 | +const rootDir = path.resolve(__dirname, '..', '..'); |
| 13 | +const cliMd = path.join(rootDir, 'doc', 'api', 'cli.md'); |
| 14 | +const cliText = fs.readFileSync(cliMd, { encoding: 'utf8' }); |
| 15 | + |
| 16 | +const nodeOptionsCC = fs.readFileSync(path.resolve(rootDir, 'src', 'node_options.cc'), 'utf8'); |
| 17 | +const addOptionRE = /AddOption[\s\n\r]*\([\s\n\r]*"([^"]+)"(.*?)\);/gs; |
| 18 | + |
| 19 | +const nodeOptionsText = cliText.match(/<!-- node-options-node start -->(.*)<!-- node-options-others end -->/s)[1]; |
| 20 | + |
| 21 | +for (const [, envVar, config ] of nodeOptionsCC.matchAll(addOptionRE)) { |
| 22 | + let hasTrueAsDefaultValue = false |
| 23 | + let isNodeOption = false; |
| 24 | + if (envVar.startsWith('[')) { |
| 25 | + continue; |
| 26 | + } |
| 27 | + |
| 28 | + if (config.includes('kAllowedInEnvvar')) { |
| 29 | + isNodeOption = true; |
| 30 | + } |
| 31 | + if (config.includes('kDisallowedInEnvvar')) { |
| 32 | + isNodeOption = false; |
| 33 | + } |
| 34 | + |
| 35 | + if (/^\s*true\s*$/.test(config.split(',').pop())) { |
| 36 | + hasTrueAsDefaultValue = true |
| 37 | + } |
| 38 | + |
| 39 | + if (!hasTrueAsDefaultValue && new RegExp(`\#\#\#.*\`${envVar}[\[=\\s\\b\`]`).test(cliText) === false) { |
| 40 | + console.log(`Should have option ${envVar} documented`) |
| 41 | + } |
| 42 | + |
| 43 | + if (!hasTrueAsDefaultValue && new RegExp(`\#\#\#.*\`--no-${envVar.slice(2)}[\[=\\s\\b\`]`).test(cliText) === true) { |
| 44 | + console.log(`Should not have option --no-${envVar.slice(2)} documented`) |
| 45 | + } |
| 46 | + |
| 47 | + if (hasTrueAsDefaultValue && new RegExp(`\#\#\#.*\`--no-${envVar.slice(2)}[\[=\\s\\b\`]`).test(cliText) === false) { |
| 48 | + console.log(`Should have option --no-${envVar.slice(2)} documented`) |
| 49 | + } |
| 50 | + |
| 51 | + if (!hasTrueAsDefaultValue && new RegExp(`\`${envVar}\``).test(nodeOptionsText) === false) { |
| 52 | + console.log(`Should have option ${envVar} in NODE_OPTIONS documented`) |
| 53 | + } |
| 54 | + |
| 55 | + if (hasTrueAsDefaultValue && new RegExp(`\`--no-${envVar.slice(2)}`).test(cliText) === false) { |
| 56 | + console.log(`Should have option --no-${envVar.slice(2)} in NODE_OPTIONS documented`) |
| 57 | + } |
| 58 | + |
| 59 | + if (!hasTrueAsDefaultValue && new RegExp(`\`--no-${envVar.slice(2)}`).test(cliText) === true) { |
| 60 | + console.log(`Should not have option --no-${envVar.slice(2)} in NODE_OPTIONS documented`) |
| 61 | + } |
| 62 | +} |
0 commit comments