Skip to content

Commit 43b4c91

Browse files
committed
docs: test for cli options
1 parent 64c6d97 commit 43b4c91

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

doc/api/cli.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2602,11 +2602,15 @@ V8 options that are allowed are:
26022602

26032603
<!-- node-options-v8 end -->
26042604

2605+
<!-- node-options-others start -->
2606+
26052607
`--perf-basic-prof-only-functions`, `--perf-basic-prof`,
26062608
`--perf-prof-unwinding-info`, and `--perf-prof` are only available on Linux.
26072609

26082610
`--enable-etw-stack-walking` is only available on Windows.
26092611

2612+
<!-- node-options-others end -->
2613+
26102614
### `NODE_PATH=path[:…]`
26112615

26122616
<!-- YAML
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

Comments
 (0)