proxy.golang.org : github.com/tmc/scripttestutil
Package scripttestutil provides tools for testing command-line programs using the rsc.io/script package. Scripttestutil is designed to simplify testing of command-line applications by allowing you to write tests as executable scripts with expected outputs. The tests are written as plain text files with commands and assertions, making them easy to understand and maintain. The primary interface to scripttestutil is the 'scripttest' command-line tool, which: A scripttest test file is a plain text file typically stored in a 'testdata' directory. The file contains a series of commands to run, along with assertions about their output. ## Basic Test Structure A basic test file contains commands followed by assertions: ## Available Commands and Assertions Commands: Assertions: ## Multiline Output Matching For multiline output, use stdout/stderr with multiline strings: ## Embedding Files Test files can include embedded files using the -- markers: ## Environment Variables Set environment variables using the env command: ## Conditional Tests Run tests conditionally based on platform: ## Docker Support Run tests inside Docker containers using one of these approaches: Embedding a Dockerfile in your test file: ``` # Test in Docker echo "Running in container" -- Dockerfile -- FROM alpine:latest RUN apk add bash WORKDIR /app COPY . . CMD ["bash"] ``` Using platform-specific Dockerfiles: ``` -- Dockerfile -- # Linux-specific Dockerfile FROM ubuntu:22.04 RUN apt-get update && apt-get install -y nodejs -- Dockerfile.windows -- # Windows-specific Dockerfile FROM mcr.microsoft.com/windows/servercore:ltsc2022 RUN powershell -Command "Install-PackageProvider -Name NuGet -Force" ``` The Docker container will: - Mount your test directory as /app in the container - Pass through environment variables like UPDATE_SNAPSHOTS - Automatically clean up after test completion - Support snapshot creation and verification ## Snapshots and Recording ### Basic Snapshots Record and verify command output: Update snapshots by setting environment variable: ### Asciicast Recording Record and play back terminal sessions as asciicast files: Asciicast recordings can be shared and embedded in documentation, providing interactive terminal playback with timing information. ## Setting Command Info Create a .scripttest_info file to define available commands: ## Example 1: Testing a CLI Tool ## Example 2: Testing with Environment Variables ## Example 3: Testing a Web Server ## Example 4: Testing with Docker ## Example 5: Testing Go Programs Installation: Common commands: For more information, run:
Registry
-
Source
- Documentation
- JSON
purl: pkg:golang/github.com/tmc/scripttestutil
License: MIT
Latest release: 5 days ago
Namespace: github.com/tmc
Stars: 0 on GitHub
Forks: 0 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 5 days ago