]> Cypherpunks.ru repositories - gostls13.git/commit
io/fs: add Sub
authorRuss Cox <rsc@golang.org>
Wed, 2 Dec 2020 17:49:20 +0000 (12:49 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 4 Dec 2020 16:49:30 +0000 (16:49 +0000)
commit478bde3a4388997924a02ee9296864866d8ba3ba
treef474d0ffa817826e9d07f79a0df463da23060a32
parent5d4569197eeef42862b8ea87a7e8ccda1cd061a0
io/fs: add Sub

Sub provides a convenient way to refer to a subdirectory
automatically in future operations, like Unix's chdir(2).

The CL also includes updates to fstest to check Sub implementations.

As part of updating fstest, I changed the meaning of TestFS's
expected list to introduce a special case: if you list no expected files,
that means the FS must be empty. In general it's OK not to list all
the expected files, but if you list none, that's almost certainly a
mistake - if your FS were broken and empty, you wouldn't find out.
Making no expected files mean "must be empty" makes the mistake
less likely - if your file system ever worked, then your test will keep
it working.

That change found a testing bug: embedtest was making exactly
that mistake.

Fixes #42322.

Change-Id: I63fd4aa866b30061a0e51ca9a1927e576d6ec41e
Reviewed-on: https://go-review.googlesource.com/c/go/+/274856
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
doc/go1.16.html
src/embed/internal/embedtest/embed_test.go
src/io/fs/readdir_test.go
src/io/fs/readfile_test.go
src/io/fs/sub.go [new file with mode: 0644]
src/io/fs/sub_test.go [new file with mode: 0644]
src/os/file.go
src/testing/fstest/mapfs.go
src/testing/fstest/testfs.go