...

Package testfiles

import "golang.org/x/tools/internal/testfiles"
Overview
Index

Overview ▾

Package testfiles provides utilities for writing Go tests with files in testdata.

func CopyDirToTmp

func CopyDirToTmp(t testing.TB, srcdir string) string

CopyDirToTmp copies dir to a temporary test directory using CopyTestFiles and returns the path to the test directory.

func CopyFS

func CopyFS(dstdir string, src fs.FS) error

CopyFS copies the files and directories in src to a destination directory dst. Paths to files and directories ending in a ".test" extension have the ".test" extension removed. This allows tests to hide files whose names have special meaning, such as "go.mod" files or "testdata" directories from the go command, or ill-formed Go source files from gofmt.

For example if we copy the directory testdata:

testdata/
    go.mod.test
    a/a.go
    b/b.go

The resulting files will be:

dst/
    go.mod
    a/a.go
    b/b.go

func ExtractTxtar

func ExtractTxtar(dstdir string, ar *txtar.Archive) error

ExtractTxtar writes each archive file to the corresponding location beneath dir.

TODO(adonovan): move this to txtar package, we need it all the time (#61386).

func ExtractTxtarToTmp

func ExtractTxtarToTmp(t testing.TB, archive string) string

ExtractTxtarToTmp read a txtar archive on a given path, extracts it to a temporary directory, and returns the temporary directory.