@@ -96,7 +96,7 @@ type Args struct {
9696 // workspace. It is executed once and only once before the beginning of
9797 // all tests. If SetUp returns a non-nil error, execution is halted and
9898 // tests cases are not executed.
99- SetUp func () error
99+ SetUp func () error
100100}
101101
102102// 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
321321
322322 // Copy or link the files for the tested repository.
323323 testedRepoDir := filepath .Join (execDir , "tested_repo" )
324- var singleRepoPrefix string
324+ var singleRepoName string
325325 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 )
330331 }
331332 srcPath , err := runfiles .Rlocation (f )
332333 if err != nil {
333334 return "" , cleanup , fmt .Errorf ("unknown runfile %s: %v" , f , err )
334335 }
335- dstPath := filepath .Join (testedRepoDir , strings .TrimPrefix (f , singleRepoPrefix ))
336+ dstPath := filepath .Join (testedRepoDir , strings .TrimPrefix (f , singleRepoName + "/" ))
336337 if err := copyOrLink (dstPath , srcPath ); err != nil {
337338 return "" , cleanup , fmt .Errorf ("copying %s to %s: %v" , srcPath , dstPath , err )
338339 }
@@ -441,7 +442,7 @@ func setupWorkspace(args Args, files []string) (dir string, cleanup func() error
441442 TestedModuleName : testedModuleName ,
442443 TestedModuleRepoName : testedModuleRepoName ,
443444 TestedModulePath : strings .ReplaceAll (testedRepoDir , "\\ " , "\\ \\ " ),
444- Suffix : args .ModuleFileSuffix ,
445+ Suffix : args .ModuleFileSuffix ,
445446 }
446447 if err := defaultModuleBazelTpl .Execute (w , info ); err != nil {
447448 return "" , cleanup , err
@@ -466,12 +467,14 @@ func extractTxtar(dir, txt string) error {
466467 return nil
467468}
468469
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+
469473func loadName (bazelFilePath string ) (string , error ) {
470474 content , err := os .ReadFile (bazelFilePath )
471475 if err != nil {
472476 return "" , err
473477 }
474- nameRe := regexp .MustCompile (`(?m)^(?:\s*|workspace\()name\s*=\s*("[^"]*"|'[^']*')\s*,?\s*\)?\s*$` )
475478 match := nameRe .FindSubmatchIndex (content )
476479 if match == nil {
477480 return "" , fmt .Errorf ("%s: name not set" , bazelFilePath )
@@ -486,12 +489,12 @@ func loadName(bazelFilePath string) (string, error) {
486489type workspaceTemplateInfo struct {
487490 TestedModuleRepoName string
488491 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
495498}
496499
497500var defaultWorkspaceTpl = template .Must (template .New ("" ).Parse (`
@@ -547,7 +550,7 @@ type moduleFileTemplateInfo struct {
547550 TestedModuleName string
548551 TestedModuleRepoName string
549552 TestedModulePath string
550- Suffix string
553+ Suffix string
551554}
552555
553556// TODO: Also reuse the current Go SDK as in the WORKSPACE file.
0 commit comments