Skip to content

Commit 8279826

Browse files
BridgeARMylesBorins
authored andcommitted
test: verify input flags
This makes sure all required flags are passed through to the test. If that's not the case an error is thrown to inform the user what flag is missing. PR-URL: #24876 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 155d1d5 commit 8279826

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

‎test/common/index.js‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,44 @@ const isMainThread = (() => {
4545
}
4646
})();
4747

48+
// Check for flags. Skip this for workers (both, the `cluster` module and
49+
// `worker_threads`) and child processes.
50+
if(process.argv.length===2&&
51+
isMainThread&&
52+
module.parent&&
53+
require('cluster').isMaster){
54+
// The copyright notice is relatively big and the flags could come afterwards.
55+
constbytesToRead=1500;
56+
constbuffer=Buffer.allocUnsafe(bytesToRead);
57+
constfd=fs.openSync(module.parent.filename,'r');
58+
fs.readSync(fd,buffer,0,bytesToRead);
59+
fs.closeSync(fd);
60+
constsource=buffer.toString();
61+
62+
constflagStart=source.indexOf('// Flags: --')+10;
63+
if(flagStart!==9){
64+
letflagEnd=source.indexOf('\n',flagStart);
65+
// Normalize different EOL.
66+
if(source[flagEnd-1]==='\r'){
67+
flagEnd--;
68+
}
69+
constflags=source
70+
.substring(flagStart,flagEnd)
71+
.replace(/_/g,'-')
72+
.split(' ');
73+
constargs=process.execArgv.map((arg)=>arg.replace(/_/g,'-'));
74+
for(constflagofflags){
75+
if(!args.includes(flag)&&
76+
// If the binary is build without `intl` the inspect option is
77+
// invalid. The test itself should handle this case.
78+
(process.config.variables.v8_enable_inspector!==0||
79+
!flag.startsWith('--inspect'))){
80+
thrownewError(`Test has to be started with the flag: '${flag}'`);
81+
}
82+
}
83+
}
84+
}
85+
4886
constisWindows=process.platform==='win32';
4987
constisAIX=process.platform==='aix';
5088
constisLinuxPPCBE=(process.platform==='linux')&&

0 commit comments

Comments
 (0)