Skip to content

Commit 029ebac

Browse files
authored
test: simplify test-cli-node-options-docs
PR-URL: #61006 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Erick Wendel <[email protected]>
1 parent 29477c5 commit 029ebac

File tree

1 file changed

+19
-43
lines changed

1 file changed

+19
-43
lines changed

test/parallel/test-cli-node-options-docs.js

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -39,34 +39,10 @@ for (const [, envVar] of manPageText.matchAll(/\.It Fl (-[a-zA-Z0-9._-]+)/g)) {
3939
}
4040

4141
for (const [, envVar, config] of nodeOptionsCC.matchAll(addOptionRE)) {
42-
let hasTrueAsDefaultValue = false;
43-
let isInNodeOption = false;
44-
let isV8Option = false;
45-
let isNoOp = false;
46-
47-
if (config.includes('NoOp{}')) {
48-
isNoOp = true;
49-
}
50-
51-
if (config.includes('kAllowedInEnvvar')) {
52-
isInNodeOption = true;
53-
}
54-
if (config.includes('kDisallowedInEnvvar')) {
55-
isInNodeOption = false;
56-
}
57-
58-
if (config.includes('V8Option{}')) {
59-
isV8Option = true;
60-
}
61-
62-
if (/^\s*true\s*$/.test(config.split(',').pop())) {
63-
hasTrueAsDefaultValue = true;
64-
}
65-
66-
// Exception for HAVE_AMARO conditional default (defaults to true when Amaro is available)
67-
if (config.includes('HAVE_AMARO')) {
68-
hasTrueAsDefaultValue = true;
69-
}
42+
const hasTrueAsDefaultValue = /,\s*(?:true|HAVE_[A-Z_]+)\s*$/.test(config);
43+
const isInNodeOption = config.includes('kAllowedInEnvvar') && !config.includes('kDisallowedInEnvvar');
44+
const isV8Option = config.includes('V8Option{}');
45+
const isNoOp = config.includes('NoOp{}');
7046

7147
if (
7248
envVar.startsWith('[') ||
@@ -79,50 +55,50 @@ for (const [, envVar, config] of nodeOptionsCC.matchAll(addOptionRE)) {
7955
}
8056

8157
// Internal API options are documented in /doc/contributing/internal-api.md
82-
if (new RegExp(`####.*\`${envVar}[[=\\s\\b\`]`).test(internalApiText) === true) {
58+
if (new RegExp(`####.*\`${RegExp.escape(envVar)}[[=\\s\\b\`]`).test(internalApiText)) {
8359
manPagesOptions.delete(envVar.slice(1));
8460
continue;
8561
}
8662

8763
// CLI options
8864
if (!isV8Option && !hasTrueAsDefaultValue) {
89-
if (new RegExp(`###.*\`${envVar}[[=\\s\\b\`]`).test(cliText) === false) {
90-
assert(false, `Should have option ${envVar} documented`);
65+
if (!new RegExp(`###.*\`${RegExp.escape(envVar)}[[=\\s\\b\`]`).test(cliText)) {
66+
assert.fail(`Should have option ${envVar} documented`);
9167
} else {
9268
manPagesOptions.delete(envVar.slice(1));
9369
}
9470
}
9571

96-
if (!hasTrueAsDefaultValue && new RegExp(`###.*\`--no${envVar.slice(1)}[[=\\s\\b\`]`).test(cliText) === true) {
97-
assert(false, `Should not have option --no${envVar.slice(1)} documented`);
72+
if (!hasTrueAsDefaultValue && new RegExp(`###.*\`--no${RegExp.escape(envVar.slice(1))}[[=\\s\\b\`]`).test(cliText)) {
73+
assert.fail(`Should not have option --no${envVar.slice(1)} documented`);
9874
}
9975

10076
if (!isV8Option && hasTrueAsDefaultValue) {
101-
if (new RegExp(`###.*\`--no${envVar.slice(1)}[[=\\s\\b\`]`).test(cliText) === false) {
102-
assert(false, `Should have option --no${envVar.slice(1)} documented`);
77+
if (!new RegExp(`###.*\`--no${RegExp.escape(envVar.slice(1))}[[=\\s\\b\`]`).test(cliText)) {
78+
assert.fail(`Should have option --no${envVar.slice(1)} documented`);
10379
} else {
10480
manPagesOptions.delete(`-no${envVar.slice(1)}`);
10581
}
10682
}
10783

10884
// NODE_OPTIONS
10985
if (isInNodeOption && !hasTrueAsDefaultValue &&
110-
new RegExp(`\`${envVar}\``).test(nodeOptionsText) === false) {
111-
assert(false, `Should have option ${envVar} in NODE_OPTIONS documented`);
86+
!new RegExp(`\`${RegExp.escape(envVar)}\``).test(nodeOptionsText)) {
87+
assert.fail(`Should have option ${envVar} in NODE_OPTIONS documented`);
11288
}
11389

114-
if (isInNodeOption && hasTrueAsDefaultValue && new RegExp(`\`--no${envVar.slice(1)}\``).test(cliText) === false) {
115-
assert(false, `Should have option --no${envVar.slice(1)} in NODE_OPTIONS documented`);
90+
if (isInNodeOption && hasTrueAsDefaultValue && !new RegExp(`\`--no${RegExp.escape(envVar.slice(1))}\``).test(cliText)) {
91+
assert.fail(`Should have option --no${envVar.slice(1)} in NODE_OPTIONS documented`);
11692
}
11793

118-
if (!hasTrueAsDefaultValue && new RegExp(`\`--no${envVar.slice(1)}\``).test(cliText) === true) {
119-
assert(false, `Should not have option --no${envVar.slice(1)} in NODE_OPTIONS documented`);
94+
if (!hasTrueAsDefaultValue && new RegExp(`\`--no${RegExp.escape(envVar.slice(1))}\``).test(cliText)) {
95+
assert.fail(`Should not have option --no${envVar.slice(1)} in NODE_OPTIONS documented`);
12096
}
12197

12298
// V8 options
12399
if (isV8Option) {
124-
if (new RegExp(`###.*\`${envVar}[[=\\s\\b\`]`).test(v8OptionsText) === false) {
125-
assert(false, `Should have option ${envVar} in V8 options documented`);
100+
if (!new RegExp(`###.*\`${RegExp.escape(envVar)}[[=\\s\\b\`]`).test(v8OptionsText)) {
101+
assert.fail(`Should have option ${envVar} in V8 options documented`);
126102
} else {
127103
manPagesOptions.delete(envVar.slice(1));
128104
}

0 commit comments

Comments
 (0)