package testutilimport ()// TestDir creates a temporary directory for testing. It returns the path of the// temporary directory and a cleanup function to remove the temporary directory.// The path has symlinks resolved with filepath.EvalSymlinks.//// It panics if the test directory cannot be created or symlinks cannot be// resolved. It is only suitable for use in tests.func () (string, func()) { , := ioutil.TempDir("", "elvishtest.")if != nil {panic() } , = filepath.EvalSymlinks()if != nil {panic() }return , func() { := os.RemoveAll()if != nil {fmt.Fprintf(os.Stderr, "failed to remove temp dir %s: %v\n", , ) } }}// InTestDir is like TestDir, but also changes into the test directory, and the// cleanup function also changes back to the original working directory.//// It panics if it could not get the working directory or change directory. It// is only suitable for use in tests.func () (string, func()) { , := os.Getwd()if != nil {panic() } , := TestDir()Must(os.Chdir())return , func() {Must(os.Chdir()) () }}// InTempHome is like InTestDir, but it also sets HOME to the temporary// directory and restores the original HOME in cleanup.func () (string, func()) { := os.Getenv(env.HOME) , := InTestDir()os.Setenv(env.HOME, )return , func() {os.Setenv(env.HOME, ) () }}// Dir describes the layout of a directory. The keys of the map represent// filenames. Each value is either a string (for the content of a regular file// with permission 0644), a File, or a Dir.typeDirmap[string]interface{}// Symlink defines the target path of a symlink to be created.typeSymlinkstruct{ Targetstring }// File describes a file to create.typeFilestruct {Permos.FileModeContentstring}// ApplyDir creates the given filesystem layout in the current directory.func ( Dir) {applyDir(, "")}func ( Dir, string) {for , := range { := filepath.Join(, )switch file := .(type) {casestring:Must(ioutil.WriteFile(, []byte(), 0644))caseFile:Must(ioutil.WriteFile(, []byte(.Content), .Perm))caseDir:Must(os.Mkdir(, 0755)) (, )caseSymlink:Must(os.Symlink(.Target, ))default:panic(fmt.Sprintf("file is neither string, Dir, or Symlink: %v", )) } }}
The pages are generated with Goldsv0.2.8-preview. (GOOS=darwin GOARCH=arm64)