testing: fix construction of the testing artifacts path
The existing implementation constructs a path which starts with a forward
slash, which is then immediately rejected by filepath.Localize() as
invalid. This change simple removes the first forward slash.
Fixes #77763
diff --git a/src/testing/testing.go b/src/testing/testing.go
index 34b45b4..0c85540 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -1377,7 +1377,7 @@
// 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 := pkg + "/" + name
base = removeSymbolsExcept(base, "!#$%&()+,-.=@^_{}~ /")
base, err := filepath.Localize(base)
if err != nil {
diff --git a/src/testing/testing_test.go b/src/testing/testing_test.go
index 167f4a0..2760e31 100644
--- a/src/testing/testing_test.go
+++ b/src/testing/testing_test.go
@@ -1142,6 +1142,12 @@
t.Fatalf("want artifact directory contained in %q, got %q", outputDir, artifactDir)
}
+ slashDir := filepath.ToSlash(relDir)
+ parts := strings.Split(slashDir, "/")
+ if len(parts) < 4 || parts[0] != "_artifacts" {
+ t.Errorf("expected artifact directory to have structure _artifacts/<pkg>/<name>/<random>, got %q", slashDir)
+ }
+
for _, part := range strings.Split(relDir, string(os.PathSeparator)) {
const maxSize = 64
if len(part) > maxSize {
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Congratulations on opening your first change. Thank you for your contribution!
Next steps:
A maintainer will review your change and provide feedback. See
https://go.dev/doc/contribute#review for more info and tips to get your
patch through code review.
Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.
During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11 or adds a tag like "wait-release", it means that this CL will be
reviewed as part of the next development cycle. See https://go.dev/s/release
for more details.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
I intentionally left the new assertion pretty lenient...it still doesn't enforce the exact format of the constructed path. But I don't think that is sufficient. While debugging this, I found an additional bug in the derivation of the path when the test is in the root of a module.
I think I need to add an assertion about the exact derived path prefix.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Auto-Submit | +1 |
| Code-Review | +2 |
| Commit-Queue | +1 |
Thanks.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
I intentionally left the new assertion pretty lenient...it still doesn't enforce the exact format of the constructed path. But I don't think that is sufficient. While debugging this, I found an additional bug in the derivation of the path when the test is in the root of a module.
I think I need to add an assertion about the exact derived path prefix.
Would you rather fix the additional problem in a followup CL, or in this one? Either seems fine to me.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Damien NeilI intentionally left the new assertion pretty lenient...it still doesn't enforce the exact format of the constructed path. But I don't think that is sufficient. While debugging this, I found an additional bug in the derivation of the path when the test is in the root of a module.
I think I need to add an assertion about the exact derived path prefix.
Would you rather fix the additional problem in a followup CL, or in this one? Either seems fine to me.
I'll fix it here...working on it now.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |