scratchdir

package
v0.92.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package scratchdir owns where the app spec gate tests generate their scratch packages, and checks the naming contract that keeps those packages invisible to `go list ./...` and `go build ./...` while they exist.

The gates generate an app from an app spec and compile it. The generated code imports its own packages, so it has to sit inside the repo module for those imports to resolve without a go.mod, a replace directive, or a network fetch. Every gate generates under Root, one directory per gate.

Root's first element begins with "_". The gates create a directory and fill it a moment later; a `./...` expansion in another test binary during that window used to fail with "no Go files in". Go's tooling skips any directory whose name begins with "_" or ".", at every moment, while still resolving an explicit import path through it.

Root is tracked (its README keeps it in every checkout) and never removed, and only its children come and go. Go's test cache hashes the directory listings a test reads, entry mtimes included. When the gates generated beside each example (examples/<name>/_appspec*gen), every package that walks the repo saw examples/ and the example directory change during each sweep and re-ran on an unchanged tree. Now the only listing that moves is Root's own, and the walkers skip "_" directories the way Go does.

Index

Constants

View Source
const Root = "_scratch/appspecs"

Root is where the gates generate, relative to the module root.

Variables

This section is empty.

Functions

func AssertHiddenFromGoList

func AssertHiddenFromGoList(t testing.TB, parent, name string)

AssertHiddenFromGoList writes a Go package under parent/name, runs `go list ./...` in parent, and fails t if the package shows up. It removes its probe, and parent/name too when it created that directory and nothing else has written there since.

func ModuleRoot added in v0.91.0

func ModuleRoot(t testing.TB) string

ModuleRoot returns the nearest directory at or above the working directory that holds a go.mod.

func Package added in v0.91.0

func Package(t testing.TB, name string) (dir, importPath string)

Package clears the scratch package Root/name, creates it, and returns its absolute directory and import path. Cleanup removes it again, so a killed run is the only way one is left behind, and the next run clears it.

It never opens or stats Root itself. Go's test cache records those calls, and Root's listing changes whenever another gate's package comes or goes, so a gate that touched it would re-run on an unchanged tree. That rules out os.MkdirAll (it stats the parent) and os.RemoveAll (it opens it).

Types

This section is empty.

Jump to

Keyboard shortcuts

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