From 459293388ceb74d9cf61c930f02325645cd0cb7d Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Thu, 28 Oct 2021 20:54:45 -0400 Subject: [PATCH] cmd/go: document that tests must not write to their source modules Fixes #28386 Updates #48495 Change-Id: I76186077c7bbe3f8f608026ee1865de83fe169b4 Reviewed-on: https://go-review.googlesource.com/c/go/+/359574 Trust: Bryan C. Mills Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Go Bot --- src/cmd/go/alldocs.go | 6 +++++- src/cmd/go/internal/test/test.go | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go index 487a8f580b..0dcb317995 100644 --- a/src/cmd/go/alldocs.go +++ b/src/cmd/go/alldocs.go @@ -2951,7 +2951,11 @@ // When 'go test' runs a test binary, it does so from within the // corresponding package's source code directory. Depending on the test, // it may be necessary to do the same when invoking a generated test -// binary directly. +// binary directly. Because that directory may be located within the +// module cache, which may be read-only and is verified by checksums, the +// test must not write to it or any other directory within the module +// unless explicitly requested by the user (such as with the -fuzz flag, +// which writes failures to testdata/fuzz). // // The command-line package list, if present, must appear before any // flag not known to the go test command. Continuing the example above, diff --git a/src/cmd/go/internal/test/test.go b/src/cmd/go/internal/test/test.go index c435cc3fb2..cfb0a1465f 100644 --- a/src/cmd/go/internal/test/test.go +++ b/src/cmd/go/internal/test/test.go @@ -407,7 +407,11 @@ leave the test binary in pkg.test for use when analyzing the profiles. When 'go test' runs a test binary, it does so from within the corresponding package's source code directory. Depending on the test, it may be necessary to do the same when invoking a generated test -binary directly. +binary directly. Because that directory may be located within the +module cache, which may be read-only and is verified by checksums, the +test must not write to it or any other directory within the module +unless explicitly requested by the user (such as with the -fuzz flag, +which writes failures to testdata/fuzz). The command-line package list, if present, must appear before any flag not known to the go test command. Continuing the example above, -- 2.50.0