testutil

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package testutil provides shared test helpers for builtin command tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FuzzIterDir

func FuzzIterDir(t testing.TB, baseDir string, counter *atomic.Int64) (string, func())

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

func FuzzRunScriptCtx(ctx context.Context, t testing.TB, script, dir string) (string, string, int)

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

func NewRepeatReader(line string) io.Reader

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

func RunScript(t testing.TB, script, dir string, opts ...interp.RunnerOption) (string, string, int)

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

func RunScriptDiscard(t testing.TB, script, dir string, opts ...interp.RunnerOption) (string, int)

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.

func RunScriptDiscardCtx

func RunScriptDiscardCtx(ctx context.Context, t testing.TB, script, dir string, opts ...interp.RunnerOption) (string, int)

RunScriptDiscardCtx is RunScriptDiscard with an explicit context.

Types

This section is empty.

Jump to

Keyboard shortcuts

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