clitest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 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 clitest runs a tree made with cli in a test: one call gives the exit code, stdout and stderr of a command, and Lines gives the log lines it wrote.

exit, stdout, stderr := clitest.Run(t, root, "", "messages", "search", "--format", "jsonl", "deploy")

The runner gets the test's ctx, not one from lifecycle.Run: a runner that calls lifecycle.OnStop, Stop or Go panics here (an internal failure in the result). Commands rarely need them (contract.md section 9.1); one that does is tested as lifecycle tests itself, in a child process.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lines

func Lines(t testing.TB) []map[string]any

Lines returns every log line the test's runs wrote so far, each decoded as a JSON object, in order.

func Raw

func Raw(t testing.TB) [][]byte

Raw returns every log line the test's runs wrote so far, as written, each with its newline; for contracttest.Check.

func Run

func Run(t testing.TB, root *cobra.Command, stdin string, args ...string) (exit int, stdout, stderr string)

Run runs the tree as cli.Execute does, with stdin as the input, and returns the exit code lifecycle.Run would use with stdout and stderr. The log lines go to a buffer Lines reads, at level debug. root must come from cli.Root.

func RunContext

func RunContext(ctx context.Context, t testing.TB, root *cobra.Command, stdin string, args ...string) (exit int, stdout, stderr string)

RunContext is Run with the caller's ctx, for a test that cancels the command.

Types

This section is empty.

Jump to

Keyboard shortcuts

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