tester_utils

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 12 Imported by: 0

README

BootLab Tester Utils

A shared framework module for BootLab course testing tools.

Based on: codecrafters-io/tester-utils

Key improvements:

  1. Flexible run modes - Three execution modes:

    • Full JSON format (platform-dispatched)
    • Single stage test (development/debugging)
    • Run all tests (local self-test, default)
  2. CLI argument support - Command-line argument parsing:

    • Positional: ./tester hello
    • Flags: ./tester -s hello -d ~/work
    • Help/version: --help, --version
  3. Optional config file - bootlab.yml is optional (with sensible defaults), not mandatory

  4. Default working directory - BOOTLAB_REPOSITORY_DIR defaults to current directory ., no explicit setup needed

  5. New SubmissionDir - TestCaseHarness exposes the student submission directory for easy relative path access

  6. Improved Runner API - Enhanced program testing API with automatic local executable detection


Quick Start

package main

import (
    "os"
    tester_utils "github.com/bootlab-dev/tester-utils"
)

func main() {
    definition := GetDefinition() // your test definition
    os.Exit(tester_utils.Run(os.Args[1:], definition))
}

CLI Usage

# Run all tests
./tester

# Run a specific stage
./tester hello
./tester -s hello
./tester --stage hello

# Specify working directory
./tester -d ./my-solution hello

# Show help
./tester --help

Runner Package

Fluent API for testing programs (similar to check50):

import "github.com/bootlab-dev/tester-utils/runner"

// Basic usage
err := runner.Run("./hello").
    Stdin("Alice").
    Stdout("hello, Alice").
    Exit(0)

// PTY support
err := runner.Run("./mario").
    WithPty().
    Stdin("5").
    Stdout("#####").
    Exit(0)

// Test input rejection
err := runner.Run("./mario").
    Stdin("-1").
    Reject()

Environment Variables

Streaming log support (Worker integration):

  • BOOTLAB_STREAM_LOGS=1 - Disables colors and redirects stdout to stderr, enabling the Worker to capture real-time log streams

Documentation

For detailed API documentation, see GoDoc.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MergeArgsIntoEnv

func MergeArgsIntoEnv(args CLIArgs, env map[string]string) map[string]string

MergeArgsIntoEnv merges CLI args into env map (CLI args take precedence)

func Run

func Run(args []string, definition tester_definition.TesterDefinition) int

Run executes the tester with command-line arguments and environment This is the recommended entry point for tester main functions

Usage:

os.Exit(tester_utils.Run(os.Args[1:], definition))

func RunCLI

func RunCLI(env map[string]string, definition tester_definition.TesterDefinition) int

RunCLI executes the tester based on user-provided env vars Deprecated: Use Run() instead for command-line argument support

Types

type CLIArgs

type CLIArgs struct {
	Stage   string // Stage slug to run (empty = run all)
	Dir     string // Working directory (empty = current dir)
	Help    bool   // Show help
	Version bool   // Show version
}

CLIArgs holds parsed command-line arguments

func ParseArgs

func ParseArgs(args []string) CLIArgs

ParseArgs parses command-line arguments Supports:

  • ./tester [stage] # positional argument
  • ./tester --stage <slug> # flag
  • ./tester -d <dir> # specify directory

type Tester

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

Jump to

Keyboard shortcuts

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