aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2021-04-19 16:05:01 -0700
committerIan Lance Taylor <iant@golang.org>2021-04-21 16:46:52 +0000
commit35806efda21242df2c56ca276a842481acf6fea0 (patch)
tree3a54fc827fce7a521288540afd59c6b292396a75 /src/testing
parentb8a359d984b9b16a405fa66011078a477c6e2da4 (diff)
downloadgo-35806efda21242df2c56ca276a842481acf6fea0.tar.xz
io/fs: document that caller can modify slice returned by ReadFile
Also add a test to testing/fstest. Fixes #45186 Change-Id: I00e5f46ccd5269dbc266a8f2ebc9a62ebb1297b8 Reviewed-on: https://go-review.googlesource.com/c/go/+/311649 Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/fstest/testfs.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/testing/fstest/testfs.go b/src/testing/fstest/testfs.go
index 80ca0e9a1d..5c4f30af16 100644
--- a/src/testing/fstest/testfs.go
+++ b/src/testing/fstest/testfs.go
@@ -537,6 +537,18 @@ func (t *fsTester) checkFile(file string) {
}
t.checkFileRead(file, "ReadAll vs fsys.ReadFile", data, data2)
+ // Modify the data and check it again. Modifying the
+ // returned byte slice should not affect the next call.
+ for i := range data2 {
+ data2[i]++
+ }
+ data2, err = fsys.ReadFile(file)
+ if err != nil {
+ t.errorf("%s: second call to fsys.ReadFile: %v", file, err)
+ return
+ }
+ t.checkFileRead(file, "Readall vs second fsys.ReadFile", data, data2)
+
t.checkBadPath(file, "ReadFile",
func(name string) error { _, err := fsys.ReadFile(name); return err })
}