Documentation
¶
Overview ¶
Package testutil provides shared test helpers for builtin command tests.
Index ¶
- func FuzzIterDir(t testing.TB, baseDir string, counter *atomic.Int64) (string, func())
- func FuzzRunScriptCtx(ctx context.Context, t testing.TB, script, dir string) (string, string, int)
- func NewRepeatReader(line string) io.Reader
- func RunScript(t testing.TB, script, dir string, opts ...interp.RunnerOption) (string, string, int)
- func RunScriptCtx(ctx context.Context, t testing.TB, script, dir string, ...) (string, string, int)
- func RunScriptDiscard(t testing.TB, script, dir string, opts ...interp.RunnerOption) (string, int)
- func RunScriptDiscardCtx(ctx context.Context, t testing.TB, script, dir string, ...) (string, int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FuzzIterDir ¶
FuzzIterDir creates an isolated per-iteration subdirectory under baseDir, using counter to generate a unique name. It returns the directory path and a cleanup function that removes the directory. This replaces the ~12-line boilerplate pattern (atomic counter + MkdirAll + defer RemoveAll) that was previously duplicated across 30+ fuzz functions.
func FuzzRunScriptCtx ¶
FuzzRunScriptCtx runs a script in fuzz mode with AllowedPaths set to [dir]. This ensures fuzz iterations can actually read/write files inside their iteration directory rather than silently failing with permission errors.
func NewRepeatReader ¶
NewRepeatReader returns an io.Reader that yields the given line pattern indefinitely. Use io.LimitReader to cap the total bytes produced. It is intended for benchmark setup — generating large synthetic files without keeping the full content in memory.
func RunScript ¶
RunScript runs a shell script and returns stdout, stderr, and the exit code. It accepts testing.TB so it can be used in both tests and benchmarks.
func RunScriptCtx ¶
func RunScriptCtx(ctx context.Context, t testing.TB, script, dir string, opts ...interp.RunnerOption) (string, string, int)
RunScriptCtx runs a shell script with a context and returns stdout, stderr, and the exit code. It accepts testing.TB so it can be used in both tests and benchmarks.
func RunScriptDiscard ¶
RunScriptDiscard runs a shell script and returns stderr and the exit code. Stdout is discarded (io.Discard). Use this in memory-allocation tests to prevent output buffering from dominating the AllocedBytesPerOp measurement.
Types ¶
This section is empty.