tinsel

command module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 1 Imported by: 0

README

tinsel 🎄 GoDoc

(sounds like "test console")

tinsel is testing library for golang targeted at console applications. Through the clever use of file pipes, go-routines, and channels, this module aims to provide programmatic methods to submit input to stdin and read output from stdout for use in automated testing.

Basic Usage

The following is an example of a basic test case using the StdioPipe:

import (
    "github.com/binarysoupdev/tinsel/pipe"
    "github.com/binarysoupdev/tinsel/rand"
	"github.com/stretchr/testify/assert"
)

func TestStdioPipeBasicExample(t *testing.T) {
	// create rand object with constant seed
	const SEED = 42
	r := rand.New(SEED)

	// create new random input string
	INPUT := r.ASCII(15)

	// open the pipe with buffer sizes of 1 and echo enabled
	io := pipe.OpenStdio(1, 1, true)
	defer io.Close()

	// queue the input with the expected prompt and mark the input sequence as complete
	io.Queue("prompt: ", INPUT)
	io.EndQueue()

	// read the input from stdin
	fmt.Print("prompt: ")
	res, _ := bufio.NewReader(os.Stdin).ReadString('\n')

	// assert the result matches the input (with newline stripped)
	assert.Equal(t, INPUT, res[:len(res)-1])

	// assert the next line of the output contains the prompt string and its input
	assert.Equal(t, fmt.Sprintf("prompt: %s", INPUT), io.ReadLine())
}

Documentation

Overview

The tinsel module provides several packages to assist in testing console-based applications.

The github.com/binarysoupdev/tinsel/pipe package provides the StdioPipe for reading/writing from stdin/stdout.

The github.com/binarysoupdev/tinsel/rand package provides helpers for utilizing random generated values.

The github.com/binarysoupdev/tinsel/file package provides helpers for creating temporary files.

Directories

Path Synopsis
The file package provides helpers for creating temporary files in automated test cases.
The file package provides helpers for creating temporary files in automated test cases.
The pipe package provides the StdioPipe for reading/writing from stdin/stdout in automated testing.
The pipe package provides the StdioPipe for reading/writing from stdin/stdout in automated testing.
The rand package provides helpers for utilizing random generated values in automated test cases.
The rand package provides helpers for utilizing random generated values in automated test cases.

Jump to

Keyboard shortcuts

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