@@ -96,7 +96,7 @@ type Args struct {
96
96
// workspace. It is executed once and only once before the beginning of
97
97
// all tests. If SetUp returns a non-nil error, execution is halted and
98
98
// tests cases are not executed.
99
- SetUp func () error
99
+ SetUp func () error
100
100
}
101
101
102
102
// debug may be set to make the test print the test workspace path and stop
@@ -321,18 +321,19 @@ func setupWorkspace(args Args, files []string) (dir string, cleanup func() error
321
321
322
322
// Copy or link the files for the tested repository.
323
323
testedRepoDir := filepath .Join (execDir , "tested_repo" )
324
- var singleRepoPrefix string
324
+ var singleRepoName string
325
325
for _ , f := range files {
326
- if singleRepoPrefix == "" {
327
- singleRepoPrefix = f [:strings .Index (f , "/" )+ 1 ]
328
- } else if ! strings .HasPrefix (f , singleRepoPrefix ) {
329
- return "" , cleanup , fmt .Errorf ("data files from more than one repo are unsupported, got %s and %s" , singleRepoPrefix , f [:strings .Index (f , "/" )+ 1 ])
326
+ repoName , _ , _ := strings .Cut (f , "/" )
327
+ if singleRepoName == "" {
328
+ singleRepoName = repoName
329
+ } else if repoName != singleRepoName {
330
+ return "" , cleanup , fmt .Errorf ("data files from more than one repo are unsupported, got %s and %s" , singleRepoName , repoName )
330
331
}
331
332
srcPath , err := runfiles .Rlocation (f )
332
333
if err != nil {
333
334
return "" , cleanup , fmt .Errorf ("unknown runfile %s: %v" , f , err )
334
335
}
335
- dstPath := filepath .Join (testedRepoDir , strings .TrimPrefix (f , singleRepoPrefix ))
336
+ dstPath := filepath .Join (testedRepoDir , strings .TrimPrefix (f , singleRepoName + "/" ))
336
337
if err := copyOrLink (dstPath , srcPath ); err != nil {
337
338
return "" , cleanup , fmt .Errorf ("copying %s to %s: %v" , srcPath , dstPath , err )
338
339
}
@@ -441,7 +442,7 @@ func setupWorkspace(args Args, files []string) (dir string, cleanup func() error
441
442
TestedModuleName : testedModuleName ,
442
443
TestedModuleRepoName : testedModuleRepoName ,
443
444
TestedModulePath : strings .ReplaceAll (testedRepoDir , "\\ " , "\\ \\ " ),
444
- Suffix : args .ModuleFileSuffix ,
445
+ Suffix : args .ModuleFileSuffix ,
445
446
}
446
447
if err := defaultModuleBazelTpl .Execute (w , info ); err != nil {
447
448
return "" , cleanup , err
@@ -466,12 +467,14 @@ func extractTxtar(dir, txt string) error {
466
467
return nil
467
468
}
468
469
470
+ // Picks out the first "name = ..." attribute in a WORKSPACE or MODULE.bazel file.
471
+ var nameRe = regexp .MustCompile (`(?m)^(?:\s*|workspace\(|module\()name\s*=\s*("[^"]*"|'[^']*')\s*,?\s*\)?\s*$` )
472
+
469
473
func loadName (bazelFilePath string ) (string , error ) {
470
474
content , err := os .ReadFile (bazelFilePath )
471
475
if err != nil {
472
476
return "" , err
473
477
}
474
- nameRe := regexp .MustCompile (`(?m)^(?:\s*|workspace\()name\s*=\s*("[^"]*"|'[^']*')\s*,?\s*\)?\s*$` )
475
478
match := nameRe .FindSubmatchIndex (content )
476
479
if match == nil {
477
480
return "" , fmt .Errorf ("%s: name not set" , bazelFilePath )
@@ -486,12 +489,12 @@ func loadName(bazelFilePath string) (string, error) {
486
489
type workspaceTemplateInfo struct {
487
490
TestedModuleRepoName string
488
491
TestedModulePath string
489
- GoSDKPath string
490
- Nogo string
491
- NogoIncludes []string
492
- NogoExcludes []string
493
- Prefix string
494
- Suffix string
492
+ GoSDKPath string
493
+ Nogo string
494
+ NogoIncludes []string
495
+ NogoExcludes []string
496
+ Prefix string
497
+ Suffix string
495
498
}
496
499
497
500
var defaultWorkspaceTpl = template .Must (template .New ("" ).Parse (`
@@ -547,7 +550,7 @@ type moduleFileTemplateInfo struct {
547
550
TestedModuleName string
548
551
TestedModuleRepoName string
549
552
TestedModulePath string
550
- Suffix string
553
+ Suffix string
551
554
}
552
555
553
556
// TODO: Also reuse the current Go SDK as in the WORKSPACE file.
0 commit comments