cmdtest

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 43 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 cmdtest is the command line's tests' shared harness: a world of a MacPorts checkout, an upstream, and a fork (NewWorld), each test's stand-ins for compose and the host (Stands, Hosted), command lines run through them (Dockhand, RunFor, JSONOf), and the fakes a test gives the engine. A test binary hands Main the root's RunWith; cmdtest never imports the root, so a verb's external tests and the root's own run the same command line (part 4, item 2).

Index

Constants

View Source
const Settle = testsupport.Settle

Settle bounds a wait for what a running serve or watch says (testsupport.Settle).

Variables

View Source
var YqMayBeOutdated = engine.OutdatedPort{Port: "yq", Current: "4.44.1", Newest: "5.0", Uncertain: []engine.SetAside{{Tag: "v5.0", Version: "5.0", Source: "5.0", Predates: "v4.44.1"}}}

YqMayBeOutdated is a port whose newest release is uncertain: v5.0 compares newer, but was tagged on a commit older than v4.44.1's.

Functions

func AsMaintainer

func AsMaintainer(t *testing.T, w World)

asMaintainer names the person as the fixture's maintainers lines do, for --mine.

func BumpOn

func BumpOn(t *testing.T, args ...string) (string, string, error)

BumpOn runs bump where a person could answer, to show it asks nothing.

func Cells

func Cells(results []model.TargetResult) []engine.Cell

cells are hand-built results as the evidence's cells: recorded, but for a result not run, whose cell is of that kind.

func Chdir

func Chdir(t testing.TB, dir string)

Chdir is the directory the test's command lines run in, as t.Chdir would make the process's.

func CleanupStamp

func CleanupStamp(t *testing.T, home string) string

cleanupStamp is the one checkout's cleanup stamp, kept for it beside the database.

func Dig

func Dig(t *testing.T, value any, path ...any) any

Dig walks a decoded result by keys and indexes.

func Dockhand

func Dockhand(t *testing.T, args ...string) (string, string, error)

func Flat

func Flat(text string) string

Flat is text with its wrapped lines joined, each break and the indent after it one space, and its first line's indent dropped, for a test to read words whose wrap moves with what the line holds, as a temporary directory's path.

func Getenv

func Getenv(t testing.TB, name string) string

Getenv is a variable as the test's command lines see it.

func Hosted

func Hosted(t testing.TB) *host.Host

Hosted is the test's host (testHost), which it changes as it needs.

func Main

func Main(m *testing.M, run Runner)

Main keeps a test binary's command tests out of the person's own dockhand: a fresh HOME, so ~/.dockhand/dockhand.db is the tests', and none of the variables that point dockhand at a real tree, database, configuration, upstream, or token. On a Mac with MACPORTS_TREE set, a bare dockhand otherwise registered the person's checkout in their real database. Nor a shell's Tart homes, caches, or proxy, as the acceptance stage's (the M1's run at 10aac0c3: serve's test read its DOCKHAND_UPSTREAM's neighbours into the agent). It runs the tests with run as their command line.

func Overwidth

func Overwidth(out string) []string

Overwidth are a command line's lines wider than the width that could have been wrapped (term.Wrapped): not a table's, whose cells a terminal cuts, nor one with no space to break at, as a path or a URL.

func RefusingSSH added in v0.8.0

func RefusingSSH(t *testing.T, w World, g *forgetest.GitHub)

RefusingSSH points the fork's push URL at GitHub over SSH and has ssh refuse this Mac's key, in ssh's own words, as a fork that refuses the key does.

func RunFor

func RunFor(t testing.TB, ctx context.Context, args []string, streams term.Streams) error

RunFor runs a command line in the test, with its stand-ins.

func SaidOnce

func SaidOnce(out string) []string

SaidOnce is what a command line's default output breaks of "said once" (part 5, item 3, from the output review's §2): a pull request's URL, a run, or a commit named more than once outside a table, and more than one Next:. A line in a table, its cells set apart by two spaces or more, names what it's about in a column.

func Setenv

func Setenv(t testing.TB, name, value string)

Setenv sets a variable in the environment the test's command lines run with, as t.Setenv would in the process's, which a parallel test can't.

func Stands

func Stands(t testing.TB) *compose.Dependencies

Stands are the test's stand-ins for what compose makes: the GitHub CLI isn't installed, so a test doesn't depend on the Mac running it.

func TestPlaces

func TestPlaces(t testing.TB) config.Places

TestPlaces are the test's home and working directory, as a command run in it reads them.

func TestSettings

func TestSettings(t testing.TB) *settings.Settings

TestSettings are a command's settings, with the test's stand-ins.

func UseDependents

func UseDependents(d *compose.Dependencies, reader engine.DependentReader)

UseDependents gives a command run in the test reader as what finds dependents, and as what names a directory's ports, which names none where the reader doesn't.

func UsePorts

func UsePorts(d *compose.Dependencies, reader checks.PortReader)

UsePorts gives a command run in the test reader as its port reader, with each capability the reader has, leaving any other given apart, as engine's usePorts does.

func Versioned

func Versioned(t *testing.T, w World)

func WithAuth

func WithAuth(t *testing.T, flow credential.DeviceFlow) memoryStore

func WithBumper

func WithBumper(t *testing.T)

func WithGitHub

func WithGitHub(t *testing.T, w World) *forgetest.GitHub

func WithOutcomeScript

func WithOutcomeScript(t *testing.T, w World, config string) func(string)

withOutcomeScript configures a command provider that reports jq as ~/outcome says, "passed", or "failed" and the phase, install unless named, so a test can change what the next build does.

func WithOutdated

func WithOutdated(t *testing.T) *jqIsOutdated

func WithScript

func WithScript(t *testing.T, w World, outcome string)

WithScript configures a command provider that reports jq with the given outcome.

Types

type BuildHistories added in v0.8.0

type BuildHistories map[string]buildhistory.History

BuildHistories stand in for ports.macports.org's build history, by port: a port it holds has that history, and one it doesn't, no answer, so no test asks the network. It's an engine's BuilderHistory.

func (BuildHistories) History added in v0.8.0

type Bumper

type Bumper struct{ Repo *git.Repository }

Bumper stands in for MacPorts: a bump rewrites the version line, and a checksum refresh adds a checksums line.

func (Bumper) Prepare

func (b Bumper) Prepare(ctx context.Context, r editprep.Request) (editprep.Result, error)

func (Bumper) ResolveRelease

func (b Bumper) ResolveRelease(ctx context.Context, r editprep.Request) (model.Release, error)

type Decoded

type Decoded struct {
	Version  int            `json:"version"`
	Command  string         `json:"command"`
	ExitCode int            `json:"exit_code"`
	Error    *string        `json:"error"`
	Result   map[string]any `json:"result"`
	// GitHubRequests is a pointer, so an envelope without it is told
	// from one that sent none.
	GitHubRequests *int64 `json:"github_requests"`
}

Decoded is a --json envelope, read back loosely.

func JSONOf

func JSONOf(t *testing.T, args ...string) (Decoded, error)

JsonOf runs a command line with --json and decodes all of standard output as its one envelope.

type JqDependents

type JqDependents struct{ Under bool }

jqDependents stands in for the port index: two ports depend on jq. jqDependents are jq's dependents, as the index has them; where under, jo links it under its +jq variant too, as variantDependents finds.

func (JqDependents) Dependents

type OnePort

type OnePort struct{}

OnePort stands in for MacPorts: every directory defines one port, named after it.

func (OnePort) Directory

func (OnePort) Ports

func (OnePort) Ports(_ context.Context, _ model.Source, directory string, _ model.Environment, variants map[string]bool) ([]macports.PortInfo, error)

type Refuser

type Refuser struct{}

refuser stands in for MacPorts with a Portfile dockhand won't edit.

func (Refuser) Prepare

func (Refuser) ResolveRelease

func (Refuser) ResolveRelease(context.Context, editprep.Request) (model.Release, error)

type Runner

Runner runs a command line, as the command line's root does (command.RunWith), which a test binary hands Main: cmdtest is below the root and never imports it, so a verb's external tests and the root's own run the same command line.

type SignedIn

type SignedIn struct {
	Account string
	Readied *[]int
}

SignedIn stands in for the GitHub CLI: signed in as Account, it records what it marks ready; with no login, it isn't installed.

func (SignedIn) Login

func (c SignedIn) Login(context.Context) (string, error)

func (SignedIn) MarkDraft added in v0.7.0

func (SignedIn) MarkReady

func (c SignedIn) MarkReady(_ context.Context, ref forge.PullRequestRef) error

type SyncBuffer

type SyncBuffer struct {
	Mu sync.Mutex
	B  bytes.Buffer
}

SyncBuffer is a buffer two goroutines may share.

func (*SyncBuffer) String

func (s *SyncBuffer) String() string

func (*SyncBuffer) Write

func (s *SyncBuffer) Write(p []byte) (int, error)

type UnfetchedPrevious

type UnfetchedPrevious struct{ Bumper }

unfetchedPrevious is the bumper, where the current version's archives couldn't be fetched to compare with the new one's.

func (UnfetchedPrevious) Prepare

type World

type World struct{ Home, Upstream, Clone string }

World is a home directory, an upstream standing in for macports/macports-ports, and the person's clone of it at ~/src.

func CheckedBranch

func CheckedBranch(t *testing.T) World

func NewWorld

func NewWorld(t *testing.T) World

Jump to

Keyboard shortcuts

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