• Stars
    star
    47
  • Rank 583,267 (Top 12 %)
  • Language
    Go
  • License
    BSD 3-Clause "New...
  • Created about 4 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cross-platform (Windows, Mac, Linux) integration testing for your terminals

termtest

GitHub Actions status

An automatable terminal session with send/expect controls.

This package leverages the go-expect package to test terminal applications on Linux, MacOS and Windows, which has been forked from Netflix/go-expect

It has been developed for CI testing of the ActiveState state tool

Example usage

import (
    "testing"

    "github.com/ActiveState/termtest"
    "github.com/stretchr/testify/suite"
)

func TestBash(t *testing.T) {
    opts := termtest.Options{
        CmdName: "/bin/bash",
    }
    cp, err := termtest.NewTest(t, opts)
    require.NoError(t, err, "create console process")
    defer cp.Close()

    cp.SendLine("echo hello world")
    cp.Expect("hello world")
    cp.SendLine("exit")
    cp.ExpectExitCode(0)
}

Multi-line matching

After each bytes termtest receives from the pseudo-terminal output, it updates the state of the virtual terminal like a terminal user would see it (including a scroll back buffer if necessary). The Expect() look for matches in this processed output. Of course, the terminal wraps its output after text gets longer than 80 columns (or whatever width you have configured for your terminal). As this makes it more difficult to match long string, the default Expect() removes all these automatic wraps.

Consider the following examples, that all assume a terminal width of 10 columns.

Programme sends a line with more than 10 characters

  • Programme sends string "0123456789012345".
  • Terminal output is "0123456789\n012345 \n".
cp.Expect("0123456789012345")  // this matches

Programme sends several lines separated by \n

  • Programme sends string "line 1\nline 2\n".
  • Terminal output is "line 1 \nline 2 \n".
  • The following does NOT match:
    cp.Expect("line 1\nline 2\n")  // this does NOT match
    
  • The following does MATCH:
    cp.Expect("line 1")
    cp.Expect("line 2")
    
  • The following does MATCH:
    cp.Expect("line 1    line 2    ")
    

Custom matchers

Custom matchers that match against either the raw / or processed pseudo-terminal output can be specified in the go-expect package. See expect_opt.go for examples.

More Repositories

1

code

ActiveState Code Recipes
Python
1,908
star
2

appdirs

A small Python module for determining appropriate platform-specific dirs, e.g. a "user data dir".
Python
993
star
3

OpenKomodoIDE

Open Komodo IDE is a fast and free multi-language code editor. Written in JS, Python, C++ and based on the Mozilla platform.
Python
500
star
4

neuroblast

NeuroBlast is a classic arcade space shooter with ML-powered AI.
Python
108
star
5

tdk

Tcl Dev Kit (TDK)
Tcl
62
star
6

teapot

Tcl TEApot
Tcl
44
star
7

gococo

Go CLI for using COCO object recognition models
Go
36
star
8

dockron

Schedule your 'docker run's without having to install cron on the host
Go
29
star
9

MalwareArchivist

Download archived malware from ActiveState's source code mirror
Python
28
star
10

cli

The Command Line Interface for managing language runtime environments built by the ActiveState Platform
Go
27
star
11

tensorflask

Simple example hosting TensorFlow model as Flask service
Python
20
star
12

go-ansi

Go package to convert ANSi art files to PNG
Go
18
star
13

ez_setup

ez_setup.py and distribute_setup.py
Python
18
star
14

pythonselect

A tool to set current Python version (currently MacOSX only)
Python
15
star
15

depgraph

Dependency resolution algorithms for Python packages (used in PyPM)
Python
15
star
16

applib

Cross-platform application utilities for Python. Originally implemented for PyPM.
Python
15
star
17

static-docker-registry

Experiments in making 'docker pull' reliable
Go
13
star
18

golang-gorilla-webapp

A sample web app in Go using Gorilla
Go
9
star
19

recipe-580811-uno-text-based

UNO (text-based)
Python
7
star
20

recipe-577504-compute-mem-footprint

Compute memory footprint of an object and its contents
Python
7
star
21

gogettable

Webapp to provide the manifest to make `go get` fetch source code for arbitrary import domains
Go
7
star
22

yaml-blog-post

YAML Blog Post
Perl
6
star
23

homework

5
star
24

activepython-docker

ActivePython Docker image
Shell
4
star
25

gometalinter-helper

Tools to check Go files for use with commit hooks and CI
Go
4
star
26

mk

a Python make replacement: write a `Task` subclass in "Makefile.py" called "foo", run `mk foo`
Python
3
star
27

perl-5.32

Home for the Perl-5.32 install scripts
Perl
3
star
28

rules_vendor

Bazel support for packaging Go vendored dependencies
Python
3
star
29

webinar-microservices-versions

Demonstrates two types of applications versioning - mutable and immutable using Stackato
Ruby
3
star
30

tcl-core-xxx

Unofficial Tcl core GIT repository.
C
2
star
31

filearchive

Python module to work with file archives
Python
2
star
32

sysinfo

Go package for detecting the current system's information
Go
2
star
33

documentation-public

HTML
2
star
34

product-roadmap

This is the new external Product Roadmap website
HTML
2
star
35

doozerconfig

Go package for managing json-encoded configuration in Doozer
Go
2
star
36

recipe-580793-tkinter-table-scroll

Tkinter with table scrollbars
Python
2
star
37

perl-activestate-utils

Various utility modules that we use in different context. Parts of it bundled with ActivePerl.
Perl
1
star
38

perl-activeperl-ppm

The ActivePerl::PPM module
Perl
1
star
39

AS-Notebook

Python
1
star
40

p532

SCSS
1
star
41

recipe-577968-log-watcher-tail-f-log

Log Watcher (tAIL -f *.log)
Python
1
star
42

ce-download-demo

Quick demo of Python CE Popup with /auto-fork and downlaod links
HTML
1
star
43

json-ordered-tidy

A fancy JSON tidier that can arbitrarily order object keys
Go
1
star
44

webdrain

Logyard drain as a web app
JavaScript
1
star
45

swampup

Demo Artitfactory
1
star
46

pycon2019

Getting Rid of Developer Pain Points Workshop β€” PyCon 2019
Dockerfile
1
star
47

activestate.github.com

1
star
48

langtools

Go packages and tools for working with language ecosystems
Go
1
star
49

APy

Python
1
star
50

go-env-log-spam

A simple app to simulate frequent log activity (per millisecond), especially for http://bugs.activestate.com/show_bug.cgi?id=99534
Go
1
star