testfiles

package
v0.0.0-...-395a15b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyToTmp

func CopyToTmp(t testing.TB, src fs.FS, rename ...string) string

CopyToTmp copies the files and directories in src to a new temporary testing directory dst, and returns dst on success.

After copying the files, it processes each of the 'old,new,' rename directives in order. Each rename directive moves the relative path "old" to the relative path "new" within the directory.

Renaming 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

with the rename "go.mod.test,go.mod", the resulting files will be:

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

func ExtractTxtarFileToTmp

func ExtractTxtarFileToTmp(t testing.TB, file string) string

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

func LoadPackages

func LoadPackages(t testing.TB, ar *txtar.Archive, patterns ...string) []*packages.Package

LoadPackages loads typed syntax for all packages that match the patterns, interpreted relative to the archive root.

The packages must be error-free.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL