diff options
Diffstat (limited to 'src/testing/testing.go')
| -rw-r--r-- | src/testing/testing.go | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go index 34b45b41b9..bf95f1cfbb 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -1363,6 +1363,21 @@ func (c *common) makeArtifactDir() (string, error) { return c.makeTempDir() } + artifactBase := filepath.Join(artifactDir, c.relativeArtifactBase()) + if err := os.MkdirAll(artifactBase, 0o777); err != nil { + return "", err + } + dir, err := os.MkdirTemp(artifactBase, "") + if err != nil { + return "", err + } + if c.chatty != nil { + c.chatty.Updatef(c.name, "=== ARTIFACTS %s %v\n", c.name, dir) + } + return dir, nil +} + +func (c *common) relativeArtifactBase() string { // If the test name is longer than maxNameSize, truncate it and replace the last // hashSize bytes with a hash of the full name. const maxNameSize = 64 @@ -1373,11 +1388,17 @@ func (c *common) makeArtifactDir() (string, error) { } // Remove the module path prefix from the import path. - pkg := strings.TrimPrefix(c.importPath, c.modulePath+"/") + // If this is the root package, pkg will be empty. + pkg := strings.TrimPrefix(c.importPath, c.modulePath) + // Remove the leading slash. + pkg = strings.TrimPrefix(pkg, "/") - // Join with /, not filepath.Join: the import path is /-separated, - // and we don't want removeSymbolsExcept to strip \ separators on Windows. - base := "/" + pkg + "/" + name + base := name + if pkg != "" { + // Join with /, not filepath.Join: the import path is /-separated, + // and we don't want removeSymbolsExcept to strip \ separators on Windows. + base = pkg + "/" + name + } base = removeSymbolsExcept(base, "!#$%&()+,-.=@^_{}~ /") base, err := filepath.Localize(base) if err != nil { @@ -1386,18 +1407,7 @@ func (c *common) makeArtifactDir() (string, error) { base = "" } - artifactBase := filepath.Join(artifactDir, base) - if err := os.MkdirAll(artifactBase, 0o777); err != nil { - return "", err - } - dir, err := os.MkdirTemp(artifactBase, "") - if err != nil { - return "", err - } - if c.chatty != nil { - c.chatty.Updatef(c.name, "=== ARTIFACTS %s %v\n", c.name, dir) - } - return dir, nil + return base } func removeSymbolsExcept(s, allowed string) string { |
