gotest

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: MIT Imports: 12 Imported by: 0

README

gotest

Project Badges

A smart, automated Go testing tool that runs standard tests, race detection, coverage analysis, and WebAssembly tests with zero configuration.

Features

  • Zero Configuration: No flags or setup required - just run gotest
  • Automatic WASM Detection: Detects and runs WebAssembly tests automatically
  • Intelligent Test Selection: Runs stdlib tests, WASM tests, or both based on your project
  • Race Detection: Automatically runs race detection on stdlib tests
  • Coverage Analysis: Calculates and reports test coverage
  • Minimal Output: Clean, single-line summary in quiet mode
  • Badge Generation: Automatically updates README badges with test results
  • Go Vet Integration: Runs go vet before tests

Installation

go install github.com/cdvelop/gotest/cmd/gotest@latest

Usage

Simply run gotest in your project directory:

gotest
Verbose Mode

For detailed output including all test logs:

gotest -v

Output Examples

Project with stdlib tests only
✅ vet passed, ✅ tests stdlib passed, ✅ race detection passed, ✅ coverage: 81%
Project with WASM tests only
✅ vet passed, ✅ tests wasm passed, ✅ coverage: 92%
Project with both stdlib and WASM tests
✅ vet passed, ✅ tests stdlib passed, ✅ race detection passed, ✅ coverage: 100%, ✅ tests wasm passed
When tests fail
=== RUN   TestToJS
=== RUN   TestToJS/int16
    jsvalue_test.go:83: ToJS validation failed for int16
=== RUN   TestToJS/uint
    jsvalue_test.go:83: ToJS validation failed for uint
exit with status 1
✅ vet passed, ❌ tests wasm failed

Note: When tests fail, gotest shows:

  • Which tests failed (e.g., TestToJS/int16, TestToJS/uint)
  • Error messages with file and line numbers
  • Clear failure indicators (❌)
  • Filters out passing test output for clarity

How It Works

  1. Detects test files: Scans for *_test.go files in your project
  2. Identifies WASM tests: Automatically detects WASM-specific test files (e.g., *Wasm*_test.go)
  3. Runs go vet: Validates code quality before running tests
  4. Executes stdlib tests: Runs standard Go tests with go test ./...
  5. Race detection: Runs go test -race ./... on stdlib tests
  6. Coverage analysis: Calculates test coverage from stdlib or WASM tests
  7. WASM tests: Automatically runs WASM tests using wasmbrowsertest if detected
  8. Badge updates: Updates README.md with test status badges

WASM Test Auto-Detection

gotest automatically detects and runs WASM tests when:

  • Files matching *Wasm*_test.go or *wasm*_test.go are found
  • Standard tests return "matched no packages" (indicating WASM-only tests)

No manual flags or configuration needed!

Auto-Installation of wasmbrowsertest

If WASM tests are detected but wasmbrowsertest is not installed, gotest will automatically:

  1. Clone the latest version from github.com/tinywasm/wasmbrowsertest
  2. Install it to your $GOPATH/bin
  3. Run your WASM tests

Benefits

For Developers
  • Save Time: One command instead of multiple go test, go vet, go test -race commands
  • Consistency: Same testing workflow across all projects
  • No Flags: Automatic detection means no need to remember flags
  • Clean Output: Minimal, token-efficient output perfect for LLM contexts
For CI/CD
  • Single Command: Replace multiple test commands with one
  • Automatic Badge Updates: README badges stay up-to-date automatically
  • Exit Codes: Returns non-zero exit code on test failures
For WASM Projects
  • Seamless WASM Testing: No need to manually set GOOS=js GOARCH=wasm
  • Auto-Install Dependencies: wasmbrowsertest installed automatically if needed
  • Dual Testing: Run both stdlib and WASM tests in one command

Integration with devscripts

gotest integrates seamlessly with the devscripts workflow:

# In your project directory
./gotest.sh

This will execute gotest with proper directory detection and argument forwarding.

Quiet Mode (Default)

By default, gotest runs in quiet mode, filtering out:

  • Passing test output (=== RUN, --- PASS)
  • Test log messages (t.Log() output)
  • Go warnings about matched packages
  • Verbose wasmbrowsertest output

Only failures and the final summary are shown, making output ideal for:

  • LLM token efficiency
  • Quick CI/CD feedback
  • Clean terminal output

Badge Integration

gotest automatically updates your README.md with badges for:

  • License
  • Go version
  • Test status (Passing/Failed)
  • Coverage percentage
  • Race detection status
  • Vet status

Badges are inserted in the BADGES_SECTION of your README.md.

Requirements

  • Go 1.18 or later
  • For WASM tests: A browser (Chrome, Firefox, or Safari)

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(args ...string)

Run executes the test suite for the project in the current directory (or detected module root)

Types

type ConsoleFilter added in v0.0.3

type ConsoleFilter struct {
	// contains filtered or unexported fields
}

ConsoleFilter buffers console output and filters out passing tests when in quiet mode.

func NewConsoleFilter added in v0.0.3

func NewConsoleFilter(quiet bool, output func(string)) *ConsoleFilter

func (*ConsoleFilter) Add added in v0.0.3

func (cf *ConsoleFilter) Add(input string)

func (*ConsoleFilter) Flush added in v0.0.3

func (cf *ConsoleFilter) Flush()

Directories

Path Synopsis
cmd
gotest command

Jump to

Keyboard shortcuts

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