Open timothy-king opened 3 months ago
Related Issues and Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
See #62484 (os.CopyFS) and #44158 (txtar fs.FS).
@earthboundkid Do you want to submit the CL you started for #44158? Or anything else I could do to help it get over the finish line? I think this would lead to a nice simplification to this proposal.
I have been too busy to work on #44158 and I'm not sure what the best way to implement ErrModified
is, so if you want to take over, feel free. 😄
Change https://go.dev/cl/598996 mentions this issue: internal/testfiles: consolidate API
Updated the proposal with the new consolidated API.
Updated July 30.
Proposal Details
The proposal is to move the existing internal
x/tools/internal/testfiles.CopyToTmp
function for testing Go code withgo.mod
files into a new exported packagex/tools/testfiles
. This function creates a temporary testing directory from anio/fs.FS
and then potentially renaming files.The potential renaming allows for populating the new directory with files names significant to Go, such as
go.mod
, without checking in files with special names. For example if we copy the directory testdata:using `dir := testfiles.CopyToTmp(t, os.DirFS("testdata"), "go.mod.test,go.mod"), the resulting files will be:
This package was originally created to support
x/tools/analysistest.Run
. From it's documentation:Adopting this proposal would resolve #37054, #46041, #53063, and #61336.
Note this proposal works well with both
testdata/
directories usingos.DirFS
, and txtar archives usingx/tools/txtar.FS
(#44158).