@@ -248,7 +248,7 @@ type runContext struct {
248248
249249func buildConfigFromShortRepr (t * testing.T , repr string , config map [string ]interface {}) {
250250 kv := strings .Split (repr , "=" )
251- require .Len (t , kv , 2 )
251+ require .Len (t , kv , 2 , "repr: %s" , repr )
252252
253253 keyParts := strings .Split (kv [0 ], "." )
254254 require .True (t , len (keyParts ) >= 2 , len (keyParts ))
@@ -308,47 +308,50 @@ func extractRunContextFromComments(t *testing.T, sourcePath string) *runContext
308308 continue
309309 }
310310
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+ before , after , found := strings .Cut (line , " " )
316+ require .Truef (t , found , "invalid prefix of comment line %s" , line )
317+
318+ after = strings .TrimSpace (after )
319+
320+ switch before {
321+ case "//golangcitest:args" :
313322 require .Nil (t , rc .args )
314- args := strings .TrimPrefix (line , "args: " )
315- require .NotEmpty (t , args )
316- rc .args = strings .Split (args , " " )
323+ require .NotEmpty (t , after )
324+ rc .args = strings .Split (after , " " )
317325 continue
318- }
319326
320- if strings .HasPrefix (line , "config: " ) {
321- repr := strings .TrimPrefix (line , "config: " )
322- require .NotEmpty (t , repr )
327+ case "//golangcitest:config" :
328+ require .NotEmpty (t , after )
323329 if rc .config == nil {
324330 rc .config = map [string ]interface {}{}
325331 }
326- buildConfigFromShortRepr (t , repr , rc .config )
332+ buildConfigFromShortRepr (t , after , rc .config )
327333 continue
328- }
329334
330- if strings .HasPrefix (line , "config_path: " ) {
331- configPath := strings .TrimPrefix (line , "config_path: " )
332- require .NotEmpty (t , configPath )
333- rc .configPath = configPath
335+ case "//golangcitest:config_path" :
336+ require .NotEmpty (t , after )
337+ rc .configPath = after
334338 continue
335- }
336339
337- if strings .HasPrefix (line , "expected_linter: " ) {
338- expectedLinter := strings .TrimPrefix (line , "expected_linter: " )
339- require .NotEmpty (t , expectedLinter )
340- rc .expectedLinter = expectedLinter
340+ case "//golangcitest:expected_linter" :
341+ require .NotEmpty (t , after )
342+ rc .expectedLinter = after
341343 continue
342- }
343344
344- require .Fail (t , "invalid prefix of comment line %s" , line )
345+ default :
346+ require .Failf (t , "invalid prefix of comment line %s" , line )
347+ }
345348 }
346349
347350 // guess the expected linter if none is specified
348351 if rc .expectedLinter == "" {
349352 for _ , arg := range rc .args {
350353 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
354+ 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
352355 rc .expectedLinter = arg [2 :]
353356 }
354357 }
0 commit comments