|
| 1 | +'use strict'; |
| 2 | +constcommon=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 | +constassert=require('assert'); |
| 9 | +constfs=require('fs'); |
| 10 | +constpath=require('path'); |
| 11 | + |
| 12 | +constrootDir=path.resolve(__dirname,'..','..'); |
| 13 | +constcliMd=path.join(rootDir,'doc','api','cli.md'); |
| 14 | +constcliText=fs.readFileSync(cliMd,{encoding: 'utf8'}); |
| 15 | + |
| 16 | +constinternalApiMd=path.join(rootDir,'doc','contributing','internal-api.md'); |
| 17 | +constinternalApiText=fs.readFileSync(internalApiMd,{encoding: 'utf8'}); |
| 18 | + |
| 19 | +constnodeOptionsCC=fs.readFileSync(path.resolve(rootDir,'src','node_options.cc'),'utf8'); |
| 20 | +constaddOptionRE=/AddOption[\s\n\r]*\([\s\n\r]*"([^"]+)"(.*?)\);/gs; |
| 21 | + |
| 22 | +constnodeOptionsText=cliText.match(/<!--node-options-nodestart-->(.*)<!--node-options-othersend-->/s)[1]; |
| 23 | +constv8OptionsText=cliText.match(/<!--v8-optionsstart-->(.*)<!--v8-optionsend-->/s)[1]; |
| 24 | + |
| 25 | +constmanPage=path.join(rootDir,'doc','node.1'); |
| 26 | +constmanPageText=fs.readFileSync(manPage,{encoding: 'utf8'}); |
| 27 | + |
| 28 | +// Documented in /doc/api/deprecations.md |
| 29 | +constdeprecated=[ |
| 30 | +'--debug', |
| 31 | +'--debug-brk', |
| 32 | +]; |
| 33 | + |
| 34 | + |
| 35 | +constmanPagesOptions=newSet(); |
| 36 | + |
| 37 | +for(const[,envVar]ofmanPageText.matchAll(/\.ItFl(-[a-zA-Z0-9._-]+)/g)){ |
| 38 | +manPagesOptions.add(envVar); |
| 39 | +} |
| 40 | + |
| 41 | +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 | +if( |
| 67 | +envVar.startsWith('[')|| |
| 68 | +deprecated.includes(envVar)|| |
| 69 | +isNoOp |
| 70 | +){ |
| 71 | +// assert(!manPagesOptions.has(envVar.slice(1)), `Option ${envVar} should not be documented`) |
| 72 | +manPagesOptions.delete(envVar.slice(1)); |
| 73 | +continue; |
| 74 | +} |
| 75 | + |
| 76 | +// Internal API options are documented in /doc/contributing/internal-api.md |
| 77 | +if(newRegExp(`####.*\`${envVar}[[=\\s\\b\`]`).test(internalApiText)===true){ |
| 78 | +manPagesOptions.delete(envVar.slice(1)); |
| 79 | +continue; |
| 80 | +} |
| 81 | + |
| 82 | +// CLI options |
| 83 | +if(!isV8Option&&!hasTrueAsDefaultValue){ |
| 84 | +if(newRegExp(`###.*\`${envVar}[[=\\s\\b\`]`).test(cliText)===false){ |
| 85 | +assert(false,`Should have option ${envVar} documented`); |
| 86 | +}else{ |
| 87 | +manPagesOptions.delete(envVar.slice(1)); |
| 88 | +} |
| 89 | +} |
| 90 | + |
| 91 | +if(!hasTrueAsDefaultValue&&newRegExp(`###.*\`--no${envVar.slice(1)}[[=\\s\\b\`]`).test(cliText)===true){ |
| 92 | +assert(false,`Should not have option --no${envVar.slice(1)} documented`); |
| 93 | +} |
| 94 | + |
| 95 | +if(!isV8Option&&hasTrueAsDefaultValue){ |
| 96 | +if(newRegExp(`###.*\`--no${envVar.slice(1)}[[=\\s\\b\`]`).test(cliText)===false){ |
| 97 | +assert(false,`Should have option --no${envVar.slice(1)} documented`); |
| 98 | +}else{ |
| 99 | +manPagesOptions.delete(`-no${envVar.slice(1)}`); |
| 100 | +} |
| 101 | +} |
| 102 | + |
| 103 | +// NODE_OPTIONS |
| 104 | +if(isInNodeOption&&!hasTrueAsDefaultValue&&newRegExp(`\`${envVar}\``).test(nodeOptionsText)===false){ |
| 105 | +assert(false,`Should have option ${envVar} in NODE_OPTIONS documented`); |
| 106 | +} |
| 107 | + |
| 108 | +if(isInNodeOption&&hasTrueAsDefaultValue&&newRegExp(`\`--no${envVar.slice(1)}`).test(cliText)===false){ |
| 109 | +assert(false,`Should have option --no${envVar.slice(1)} in NODE_OPTIONS documented`); |
| 110 | +} |
| 111 | + |
| 112 | +if(!hasTrueAsDefaultValue&&newRegExp(`\`--no${envVar.slice(1)}`).test(cliText)===true){ |
| 113 | +assert(false,`Should not have option --no${envVar.slice(1)} in NODE_OPTIONS documented`); |
| 114 | +} |
| 115 | + |
| 116 | +// V8 options |
| 117 | +if(isV8Option){ |
| 118 | +if(newRegExp(`###.*\`${envVar}[[=\\s\\b\`]`).test(v8OptionsText)===false){ |
| 119 | +assert(false,`Should have option ${envVar} in V8 options documented`); |
| 120 | +}else{ |
| 121 | +manPagesOptions.delete(envVar.slice(1)); |
| 122 | +} |
| 123 | +} |
| 124 | +} |
| 125 | + |
| 126 | +// add alias handling |
| 127 | +manPagesOptions.delete('-trace-events-enabled'); |
| 128 | + |
| 129 | +assert.strictEqual(manPagesOptions.size,0,`Man page options not documented: ${[...manPagesOptions]}`); |
0 commit comments