Standard library / testing
testing.B.TempDir()
Create a temporary directory owned by the testing scope and remove it after cleanup. Do not rely on the generated name. Expected process exit: 0; output contains ['PASS', 'directory true']. Run as a _test.go file using the Go test harness.
Formal Syntax & Structure
go syntaxgo
func (c *B) TempDir() stringReturn Value
string
Result of the operation described above.
Working Example
Example Snippetgo
package main
import ( "fmt" "os" "testing")
func BenchmarkReference(b *testing.B) { d := b.TempDir() info, err := os.Stat(d) fmt.Println("directory", err == nil && info.IsDir())}