assert

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 12 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

Overview

Package assert evaluates a case's expect sections against a target result.

The Evaluate entry point and the answer/sources/tools/limits/golden checks live in evaluate.go; the expect.json path matchers and the ParseAnswerJSON preprocessor live in json.go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseAnswerJSON

func ParseAnswerJSON(answer string) (string, bool)

ParseAnswerJSON extracts a JSON document from an answer that may be wrapped in a markdown code fence or surrounding prose. It returns the extracted JSON and whether it parses. The rules, applied in order:

  1. trim surrounding whitespace;
  2. if the text is a ```json … ``` (or bare ``` … ```) fence, strip it;
  3. if the result is valid JSON, use it;
  4. otherwise take the substring from the first '{' to the last '}' and try that;
  5. if nothing parses, return the processed text with ok=false.

It is exported so `bench record`/report can reuse the same preprocessor.

Types

type Result

type Result struct {
	Name    string `json:"name"`              // e.g. `answer contains "45 minutes"` or `json overall_status`
	Status  Status `json:"status"`            //
	Message string `json:"message,omitempty"` // failure/skip detail with expected vs got
}

Result is the outcome of one assertion.

func Evaluate

func Evaluate(exp spec.Expect, res *target.Result, golden *spec.Golden) []Result

Evaluate runs every assertion in exp against res. golden may be nil (the golden assertion then fails with a hint to run `bench record`). Absent sections produce no Result rows. The judge section is NOT evaluated here — the runner calls the judge package and appends its Result.

func EvaluateError

func EvaluateError(exp spec.Expect, se *target.ServerError, elapsed time.Duration) []Result

EvaluateError runs the expect.error section against a server-reported error (negative cases). limits.max_seconds is still checked when set, using the elapsed time until the error arrived.

func UnexpectedSuccess

func UnexpectedSuccess(answer string) Result

UnexpectedSuccess is the assertion recorded when expect.error is present but the server answered successfully.

type Status

type Status string

Status of a single assertion.

const (
	StatusPass Status = "pass"
	StatusFail Status = "fail"
	StatusSkip Status = "skip" // assertion not applicable (e.g. token limit off-v1)
)

Jump to

Keyboard shortcuts

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