@@ -248,7 +248,7 @@ type runContext struct {
248
248
249
249
func buildConfigFromShortRepr (t * testing.T , repr string , config map [string ]interface {}) {
250
250
kv := strings .Split (repr , "=" )
251
- require .Len (t , kv , 2 )
251
+ require .Len (t , kv , 2 , "repr: %s" , repr )
252
252
253
253
keyParts := strings .Split (kv [0 ], "." )
254
254
require .True (t , len (keyParts ) >= 2 , len (keyParts ))
@@ -308,47 +308,55 @@ func extractRunContextFromComments(t *testing.T, sourcePath string) *runContext
308
308
continue
309
309
}
310
310
311
- line = strings .TrimLeft (strings .TrimPrefix (line , "//" ), " " )
312
- if strings .HasPrefix (line , "args: " ) {
311
+ if ! strings .HasPrefix (line , "//golangcitest:" ) {
312
+ require .Failf (t , "invalid prefix of comment line %s" , line )
313
+ }
314
+
315
+ // TODO(ldez) replace that by strings.Cut when we will drop go1.17
316
+ var before string
317
+ var after string
318
+ if i := strings .Index (line , " " ); i >= 0 {
319
+ before = line [:i ]
320
+ after = strings .TrimSpace (line [i + len (" " ):])
321
+ } else {
322
+ require .Failf (t , "invalid prefix of comment line %s" , line )
323
+ }
324
+
325
+ switch before {
326
+ case "//golangcitest:args" :
313
327
require .Nil (t , rc .args )
314
- args := strings .TrimPrefix (line , "args: " )
315
- require .NotEmpty (t , args )
316
- rc .args = strings .Split (args , " " )
328
+ require .NotEmpty (t , after )
329
+ rc .args = strings .Split (after , " " )
317
330
continue
318
- }
319
331
320
- if strings .HasPrefix (line , "config: " ) {
321
- repr := strings .TrimPrefix (line , "config: " )
322
- require .NotEmpty (t , repr )
332
+ case "//golangcitest:config" :
333
+ require .NotEmpty (t , after )
323
334
if rc .config == nil {
324
335
rc .config = map [string ]interface {}{}
325
336
}
326
- buildConfigFromShortRepr (t , repr , rc .config )
337
+ buildConfigFromShortRepr (t , after , rc .config )
327
338
continue
328
- }
329
339
330
- if strings .HasPrefix (line , "config_path: " ) {
331
- configPath := strings .TrimPrefix (line , "config_path: " )
332
- require .NotEmpty (t , configPath )
333
- rc .configPath = configPath
340
+ case "//golangcitest:config_path" :
341
+ require .NotEmpty (t , after )
342
+ rc .configPath = after
334
343
continue
335
- }
336
344
337
- if strings .HasPrefix (line , "expected_linter: " ) {
338
- expectedLinter := strings .TrimPrefix (line , "expected_linter: " )
339
- require .NotEmpty (t , expectedLinter )
340
- rc .expectedLinter = expectedLinter
345
+ case "//golangcitest:expected_linter" :
346
+ require .NotEmpty (t , after )
347
+ rc .expectedLinter = after
341
348
continue
342
- }
343
349
344
- require .Fail (t , "invalid prefix of comment line %s" , line )
350
+ default :
351
+ require .Failf (t , "invalid prefix of comment line %s" , line )
352
+ }
345
353
}
346
354
347
355
// guess the expected linter if none is specified
348
356
if rc .expectedLinter == "" {
349
357
for _ , arg := range rc .args {
350
358
if strings .HasPrefix (arg , "-E" ) && ! strings .Contains (arg , "," ) {
351
- require .Empty (t , rc .expectedLinter , "could not infer expected linter for errors because multiple linters are enabled. Please use the `expected_linter: ` directive in your test to indicate the linter-under-test." ) //nolint:lll
359
+ require .Empty (t , rc .expectedLinter , "could not infer expected linter for errors because multiple linters are enabled. Please use the `//golangcitest:expected_linter ` directive in your test to indicate the linter-under-test." ) //nolint:lll
352
360
rc .expectedLinter = arg [2 :]
353
361
}
354
362
}
0 commit comments