Skip to content

Commit b209f6b

Browse files
aduh95RafaelGSS
authored andcommitted
test: simplify test-cli-node-options-docs
PR-URL: #61006 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Erick Wendel <erick.workspace@gmail.com>
1 parent 1b378cf commit b209f6b

1 file changed

Lines changed: 19 additions & 43 deletions

File tree

‎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]ofnodeOptionsCC.matchAll(addOptionRE)){
42-
lethasTrueAsDefaultValue=false;
43-
letisInNodeOption=false;
44-
letisV8Option=false;
45-
letisNoOp=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+
consthasTrueAsDefaultValue=/,\s*(?:true|HAVE_[A-Z_]+)\s*$/.test(config);
43+
constisInNodeOption=config.includes('kAllowedInEnvvar')&&!config.includes('kDisallowedInEnvvar');
44+
constisV8Option=config.includes('V8Option{}');
45+
constisNoOp=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(newRegExp(`####.*\`${envVar}[[=\\s\\b\`]`).test(internalApiText)===true){
58+
if(newRegExp(`####.*\`${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(newRegExp(`###.*\`${envVar}[[=\\s\\b\`]`).test(cliText)===false){
90-
assert(false,`Should have option ${envVar} documented`);
65+
if(!newRegExp(`###.*\`${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&&newRegExp(`###.*\`--no${envVar.slice(1)}[[=\\s\\b\`]`).test(cliText)===true){
97-
assert(false,`Should not have option --no${envVar.slice(1)} documented`);
72+
if(!hasTrueAsDefaultValue&&newRegExp(`###.*\`--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(newRegExp(`###.*\`--no${envVar.slice(1)}[[=\\s\\b\`]`).test(cliText)===false){
102-
assert(false,`Should have option --no${envVar.slice(1)} documented`);
77+
if(!newRegExp(`###.*\`--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-
newRegExp(`\`${envVar}\``).test(nodeOptionsText)===false){
111-
assert(false,`Should have option ${envVar} in NODE_OPTIONS documented`);
86+
!newRegExp(`\`${RegExp.escape(envVar)}\``).test(nodeOptionsText)){
87+
assert.fail(`Should have option ${envVar} in NODE_OPTIONS documented`);
11288
}
11389

114-
if(isInNodeOption&&hasTrueAsDefaultValue&&newRegExp(`\`--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&&!newRegExp(`\`--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&&newRegExp(`\`--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&&newRegExp(`\`--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(newRegExp(`###.*\`${envVar}[[=\\s\\b\`]`).test(v8OptionsText)===false){
125-
assert(false,`Should have option ${envVar} in V8 options documented`);
100+
if(!newRegExp(`###.*\`${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)