Skip to content

alt-gnome/capytest

Repository files navigation

capytest

capytest logo: a cute cartoon capybara sitting upright holding a terminal icon with '>_' and the text 'capytest' below in a modern rounded font

capytest is a simple, friendly library for E2E testing CLI applications in Go.
It lets you write clear, step-by-step scenarios for both interactive and non-interactive command-line programs.

Go Reference License

Features

  • Simple step-by-step scenarios
  • Supports interactive and non-interactive CLIs
  • Simulate interrupts and signals
  • Check stdout, stderr, exit codes
  • Pluggable providers (local, Podman or your own)

Installation

# Install the core
go get -u go.alt-gnome.ru/capytest

# Install the necessary provider(s)
go get -u go.alt-gnome.ru/capytest/providers/local

Example

package main

import (
	"testing"

	"go.alt-gnome.ru/capytest"
	"go.alt-gnome.ru/capytest/providers/local"
)

func TestExample(t *testing.T) {
	ts := capytest.NewTestSuite(t, local.Provider())

	// Interactive scenario
	ts.Run("bc is works", func(t *testing.T, r capytest.Runner) {
		r.Command("bc").
			Do().SendLine("2+2").ExpectOutputContains("4").
			Then().SendLine("2*3").ExpectOutputContains("6").
			Then().Send([]byte{4}). // Ctrl-D
			Done().ExpectExitCode(0).
			Run(t)
	})

	// Non-interactive scenario
	ts.Run("bash --version contains GNU", func(t *testing.T, r capytest.Runner) {
		r.Command("bash", "--version").
			ExpectStdoutContains("GNU").
			ExpectStdoutMatchesSnapshot().
			ExpectStderrEmpty().
			Run(t)
	})
}

License

MIT License © 2025 Maxim Slipenko

About

A lightweight Go library for end-to-end testing of CLI apps. Read-only mirror of https://altlinux.space/alt-gnome/capytest

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages