runner

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompileC

func CompileC(workDir, source, output string, flags ...string) error

CompileC 编译 C 文件

Types

type CompileError

type CompileError struct {
	Source string
	Output string
	Err    error
}

CompileError 表示编译错误

func (*CompileError) Error

func (e *CompileError) Error() string

type ExitCodeMismatch

type ExitCodeMismatch struct {
	Expected int
	Actual   int
	Stdout   string
	Stderr   string
}

ExitCodeMismatch 表示退出码不匹配

func (*ExitCodeMismatch) Error

func (e *ExitCodeMismatch) Error() string

type Mismatch

type Mismatch struct {
	Expected string
	Actual   string
	Message  string
	Help     string
}

Mismatch 表示期望值与实际值不匹配

func (*Mismatch) Error

func (m *Mismatch) Error() string

type RejectError

type RejectError struct {
	Message string
}

RejectError 表示程序未能正确拒绝无效输入

func (*RejectError) Error

func (e *RejectError) Error() string

type Runner

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

Runner 提供类似 check50 的链式 API 来运行和测试程序 支持两种模式: 1. 阻塞模式: Stdin("input") 发送输入并等待程序结束 2. 交互模式: Start() 启动程序,SendLine() 发送输入,Reject() 检查程序是否拒绝输入

用法示例:

// 阻塞模式
runner.Run("./mario").Stdin("4").Stdout(expected).Exit(0)

// 交互模式 (用于测试输入拒绝)
runner.Run("./mario").Start().SendLine("-1").Reject().SendLine("4").Stdout(expected).Exit(0)

func Run

func Run(workDir string, command string, args ...string) *Runner

Run 创建一个新的 Runner 实例

func (*Runner) Error

func (r *Runner) Error() error

Error 返回链式调用中累积的错误

func (*Runner) Execute

func (r *Runner) Execute() *Runner

Execute 不带输入运行程序

func (*Runner) Exit

func (r *Runner) Exit(code int) *Runner

Exit 检查退出码

func (*Runner) GetStdout

func (r *Runner) GetStdout() string

GetStdout 返回标准输出内容

func (*Runner) Kill

func (r *Runner) Kill() *Runner

Kill 终止程序

func (*Runner) Reject

func (r *Runner) Reject(rejectTimeout ...time.Duration) *Runner

Reject 检查程序是否拒绝输入(继续等待而不是退出) 类似 check50 的 reject(),检查程序在收到输入后是否继续运行等待更多输入

func (*Runner) Result

func (r *Runner) Result() *executable.ExecutableResult

Result 返回执行结果

func (*Runner) SendLine

func (r *Runner) SendLine(input string) *Runner

SendLine 发送一行输入(交互模式,需要先调用 Start)

func (*Runner) Start

func (r *Runner) Start() *Runner

Start 启动程序但不等待结束(交互模式)

func (*Runner) Stdin

func (r *Runner) Stdin(input string) *Runner

Stdin 发送输入并运行程序(阻塞式)

func (*Runner) Stdout

func (r *Runner) Stdout(expected string) *Runner

Stdout 检查标准输出是否包含期望内容

func (*Runner) StdoutExact

func (r *Runner) StdoutExact(expected string) *Runner

StdoutExact 检查标准输出是否完全匹配

func (*Runner) StdoutRegex

func (r *Runner) StdoutRegex(pattern string) *Runner

StdoutRegex 使用正则表达式检查标准输出

func (*Runner) WaitForExit

func (r *Runner) WaitForExit() *Runner

WaitForExit 等待程序结束(交互模式)

func (*Runner) WithEnv

func (r *Runner) WithEnv(env ...string) *Runner

WithEnv 设置环境变量

func (*Runner) WithLogger

func (r *Runner) WithLogger(l *logger.Logger) *Runner

WithLogger 设置 logger

func (*Runner) WithPty

func (r *Runner) WithPty() *Runner

WithPty 启用 PTY 模式(用于交互式测试)

func (*Runner) WithTimeout

func (r *Runner) WithTimeout(t time.Duration) *Runner

WithTimeout 设置超时时间

Jump to

Keyboard shortcuts

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