tester_utils

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 11 Imported by: 0

README

BootCS Tester Utils

BootCS 课程测试工具的共享框架模块。

基于: codecrafters-io/tester-utils

主要改进:

  1. 灵活的运行模式 - 支持三种模式:

    • 完整 JSON 格式(平台调度)
    • 单个 stage 测试(开发调试)
    • 运行全部测试(本地自测,默认)
  2. CLI 参数支持 - 新增命令行参数解析:

    • 位置参数:./tester hello
    • 标志参数:./tester -s hello -d ~/work
    • 帮助/版本:--help, --version
  3. 可选配置文件 - bootcs.yml 为可选(有合理默认值),而非强制要求

  4. 默认工作目录 - BOOTCS_REPOSITORY_DIR 默认为当前目录 .,无需显式设置

  5. 新增 SubmissionDir - TestCaseHarness 暴露学员提交目录,方便访问相对路径

  6. 改进的 Runner API - 增强的程序测试 API,支持本地可执行文件自动检测


快速开始

package main

import (
    "os"
    tester_utils "github.com/bootcs-cn/tester-utils"
)

func main() {
    definition := GetDefinition() // 你的测试定义
    os.Exit(tester_utils.Run(os.Args[1:], definition))
}

CLI 使用

# 运行所有测试
./tester

# 运行指定 stage
./tester hello
./tester -s hello
./tester --stage hello

# 指定工作目录
./tester -d ./my-solution hello

# 查看帮助
./tester --help

Runner 包

流式 API 用于测试程序(类似 check50):

import "github.com/bootcs-cn/tester-utils/runner"

// 基本用法
err := runner.Run("./hello").
    Stdin("Alice").
    Stdout("hello, Alice").
    Exit(0)

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

// 测试输入拒绝
err := runner.Run("./mario").
    Stdin("-1").
    Reject()

文档

详细 API 文档请查看 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