@@ -61,6 +61,31 @@ const hasOpenSSL3 = hasCrypto &&
61
61
62
62
const hasQuic = hasCrypto && ! ! process . config . variables . openssl_quic ;
63
63
64
+ function parseTestFlags ( filename = process . argv [ 1 ] ) {
65
+ // The copyright notice is relatively big and the flags could come afterwards.
66
+ const bytesToRead = 1500 ;
67
+ const buffer = Buffer . allocUnsafe ( bytesToRead ) ;
68
+ const fd = fs . openSync ( filename , 'r' ) ;
69
+ const bytesRead = fs . readSync ( fd , buffer , 0 , bytesToRead ) ;
70
+ fs . closeSync ( fd ) ;
71
+ const source = buffer . toString ( 'utf8' , 0 , bytesRead ) ;
72
+
73
+ const flagStart = source . indexOf ( '// Flags: --' ) + 10 ;
74
+
75
+ if ( flagStart === 9 ) {
76
+ return [ ] ;
77
+ }
78
+ let flagEnd = source . indexOf ( '\n' , flagStart ) ;
79
+ // Normalize different EOL.
80
+ if ( source [ flagEnd - 1 ] === '\r' ) {
81
+ flagEnd -- ;
82
+ }
83
+ return source
84
+ . substring ( flagStart , flagEnd )
85
+ . replace ( / _ / g, '-' )
86
+ . split ( ' ' ) ;
87
+ }
88
+
64
89
// Check for flags. Skip this for workers (both, the `cluster` module and
65
90
// `worker_threads`) and child processes.
66
91
// If the binary was built without-ssl then the crypto flags are
@@ -71,44 +96,25 @@ if (process.argv.length === 2 &&
71
96
hasCrypto &&
72
97
require ( 'cluster' ) . isPrimary &&
73
98
fs . existsSync ( process . argv [ 1 ] ) ) {
74
- // The copyright notice is relatively big and the flags could come afterwards.
75
- const bytesToRead = 1500 ;
76
- const buffer = Buffer . allocUnsafe ( bytesToRead ) ;
77
- const fd = fs . openSync ( process . argv [ 1 ] , 'r' ) ;
78
- const bytesRead = fs . readSync ( fd , buffer , 0 , bytesToRead ) ;
79
- fs . closeSync ( fd ) ;
80
- const source = buffer . toString ( 'utf8' , 0 , bytesRead ) ;
81
-
82
- const flagStart = source . indexOf ( '// Flags: --' ) + 10 ;
83
- if ( flagStart !== 9 ) {
84
- let flagEnd = source . indexOf ( '\n' , flagStart ) ;
85
- // Normalize different EOL.
86
- if ( source [ flagEnd - 1 ] === '\r' ) {
87
- flagEnd -- ;
88
- }
89
- const flags = source
90
- . substring ( flagStart , flagEnd )
91
- . replace ( / _ / g, '-' )
92
- . split ( ' ' ) ;
93
- const args = process . execArgv . map ( ( arg ) => arg . replace ( / _ / g, '-' ) ) ;
94
- for ( const flag of flags ) {
95
- if ( ! args . includes ( flag ) &&
96
- // If the binary is build without `intl` the inspect option is
97
- // invalid. The test itself should handle this case.
98
- ( process . features . inspector || ! flag . startsWith ( '--inspect' ) ) ) {
99
- console . log (
100
- 'NOTE: The test started as a child_process using these flags:' ,
101
- inspect ( flags ) ,
102
- 'Use NODE_SKIP_FLAG_CHECK to run the test with the original flags.' ,
103
- ) ;
104
- const args = [ ...flags , ...process . execArgv , ...process . argv . slice ( 1 ) ] ;
105
- const options = { encoding : 'utf8' , stdio : 'inherit' } ;
106
- const result = spawnSync ( process . execPath , args , options ) ;
107
- if ( result . signal ) {
108
- process . kill ( 0 , result . signal ) ;
109
- } else {
110
- process . exit ( result . status ) ;
111
- }
99
+ const flags = parseTestFlags ( ) ;
100
+ const args = process . execArgv . map ( ( arg ) => arg . replace ( / _ / g, '-' ) ) ;
101
+ for ( const flag of flags ) {
102
+ if ( ! args . includes ( flag ) &&
103
+ // If the binary is build without `intl` the inspect option is
104
+ // invalid. The test itself should handle this case.
105
+ ( process . features . inspector || ! flag . startsWith ( '--inspect' ) ) ) {
106
+ console . log (
107
+ 'NOTE: The test started as a child_process using these flags:' ,
108
+ inspect ( flags ) ,
109
+ 'Use NODE_SKIP_FLAG_CHECK to run the test with the original flags.' ,
110
+ ) ;
111
+ const args = [ ...flags , ...process . execArgv , ...process . argv . slice ( 1 ) ] ;
112
+ const options = { encoding : 'utf8' , stdio : 'inherit' } ;
113
+ const result = spawnSync ( process . execPath , args , options ) ;
114
+ if ( result . signal ) {
115
+ process . kill ( 0 , result . signal ) ;
116
+ } else {
117
+ process . exit ( result . status ) ;
112
118
}
113
119
}
114
120
}
@@ -929,6 +935,7 @@ const common = {
929
935
mustSucceed,
930
936
nodeProcessAborted,
931
937
PIPE ,
938
+ parseTestFlags,
932
939
platformTimeout,
933
940
printSkipMessage,
934
941
pwdCommand,
0 commit comments