stubcmd

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package stubcmd stands in for command-line programs (gh, winget, git) in tests, alike on every OS: Install copies the test binary under the program's name next to a file of rules, and Main, run first by the test binary's TestMain, makes that copy answer by them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Install

func Install(t testing.TB, dir, name string, rules ...Rule) string

Install puts the stub program name (name.exe on Windows) answering by rules into dir and returns its path. The test binary must run Main.

func Main

func Main(m *testing.M)

Main runs tests by m, unless this process is a stub: then it answers by its rules (the first matching; none: "unexpected" and exit 1) and exits.

Types

type Call added in v0.19.0

type Call struct {
	Args []string `json:"args"`
	Env  []string `json:"env"`
}

Call is one call a stub logged (Rule.Log).

func Calls added in v0.19.0

func Calls(t testing.TB, path string) []Call

Calls are the calls logged to the file path (Rule.Log), oldest first; none when there is no such file.

type Rule

type Rule struct {
	// Args matches the arguments joined by spaces, as sh's case "$*" does:
	// '*' matches any run of characters, anything else itself.
	Args   string
	Stdout string
	Stderr string
	Exit   int
	// Await, when set, is a file the stub waits for before answering: one
	// never made is a program that hangs until it is killed.
	Await string
	// Exec, when set, is a program the stub then runs with its own
	// arguments, standard streams and environment, exiting as it does
	// (Stdout, Stderr and Exit unused): the real program behind a stub
	// that only stands in for some calls.
	Exec string
	// Log, when set, is a file the stub appends the call to (its arguments
	// and environment, see Calls) before answering.
	Log string
}

Rule is one answer of a stub.

Jump to

Keyboard shortcuts

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