示例
github.com/frankban/quicktest v1.14.6: CmpEquals
已验证示例 — golang github.com/frankban/quicktest v1.14.6: CmpEquals. contract 在 go 1.26 · linux debian/x64 · docker 上运行并通过: qt.CmpEquals returns a Checker…
sha256:b97e5d76a427796f8a9fcba875e1257a44d7831a17692c353a1a87ca68b0a01b
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
linux 24 · ubuntu · glibc 2.39 x64 go
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-09-06 |
案例
HOW- 目标
- verify github.com/frankban/quicktest.CmpEquals in pkg:golang/github.com/frankban/quicktest@v1.14.6
- 符号
-
- github.com/frankban/quicktest.CmpEquals
- 创建时间
- 2026-09-06T18:30:59Z
契约
- qt.CmpEquals returns a Checker comparing arbitrary values with default deep equality when no options are provided
- qt.CmpEquals returns ErrSilent and reports diff notes when compared values differ
- qt.CmpEquals with cmpopts.IgnoreFields ignores designated struct fields during comparison
- qt.CmpEquals with cmpopts.SortSlices verifies slice equivalence irrespective of element ordering
- qt.CmpEquals with cmpopts.EquateApprox matches floating point numbers within specified tolerance
- qt.CmpEquals detects unexported struct fields and reports a BadCheck error unless unexported comparison options are supplied
- qt.CmpEquals conforms to the Checker interface with got and want argument names and integrates with quicktest.C Check and Assert
文件
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
源代码
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify github.com/frankban/quicktest.CmpEquals in pkg:golang/github.com/frankban/quicktest@v1.14.6
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/frankban/quicktest@v1.14.6
Demonstrate these symbols/APIs:
- github.com/frankban/quicktest.CmpEquals
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:85944487e9e657f6f5230c9cea60f4de886772b1f1cc81faa377a19b355079b6","contract":["qt.CmpEquals returns a Checker comparing arbitrary values with default deep equality when no options are provided","qt.CmpEquals returns ErrSilent and reports diff notes when compared values differ","qt.CmpEquals with cmpopts.IgnoreFields ignores designated struct fields during comparison","qt.CmpEquals with cmpopts.SortSlices verifies slice equivalence irrespective of element ordering","qt.CmpEquals with cmpopts.EquateApprox matches floating point numbers within specified tolerance","qt.CmpEquals detects unexported struct fields and reports a BadCheck error unless unexported comparison options are supplied","qt.CmpEquals conforms to the Checker interface with got and want argument names and integrates with quicktest.C Check and Assert"],"goal":"verify github.com/frankban/quicktest.CmpEquals in pkg:golang/github.com/frankban/quicktest@v1.14.6","kind":"HOW","packages":["pkg:golang/github.com/frankban/quicktest@v1.14.6"],"schemaVersion":1,"symbols":["github.com/frankban/quicktest.CmpEquals"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/frankban/quicktest@v1.14.6"],"schemaVersion":1,"subject":"pkg:golang/github.com/frankban/quicktest@v1.14.6","symbols":["github.com/frankban/quicktest.CmpEquals"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require (
github.com/frankban/quicktest v1.14.6
github.com/google/go-cmp v0.5.9
)
require (
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
)
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
package main
import (
"fmt"
"os"
"strings"
qt "github.com/frankban/quicktest"
"github.com/google/go-cmp/cmp/cmpopts"
)
// ServiceConfig holds service deployment parameters.
type ServiceConfig struct {
Name string
Port int
Endpoints []string
Revision int64 // internal revision number ignored in config equality
Throughput float64 // floating rate compared within tolerance
}
// CompareConfigs validates whether got matches want according to CmpEquals rules.
func CompareConfigs(got, want ServiceConfig) error {
checker := qt.CmpEquals(
cmpopts.IgnoreFields(ServiceConfig{}, "Revision"),
cmpopts.SortSlices(func(a, b string) bool { return a < b }),
cmpopts.EquateApprox(0, 0.01),
)
var notes []string
note := func(key string, value interface{}) {
notes = append(notes, fmt.Sprintf("%s: %v", key, value))
}
err := checker.Check(got, []interface{}{want}, note)
if err != nil {
return fmt.Errorf("configuration mismatch: %v (details: %s)", err, strings.Join(notes, "; "))
}
return nil
}
func main() {
primary := ServiceConfig{
Name: "api-gateway",
Port: 8080,
Endpoints: []string{"/healthz", "/metrics", "/v1"},
Revision: 101,
Throughput: 1500.005,
}
replica := ServiceConfig{
Name: "api-gateway",
Port: 8080,
Endpoints: []string{"/metrics", "/v1", "/healthz"}, // permuted order
Revision: 999, // different revision ignored
Throughput: 1500.000, // within approximate tolerance
}
if err := CompareConfigs(primary, replica); err != nil {
fmt.Fprintf(os.Stderr, "Verification failed: %v\n", err)
os.Exit(1)
}
fmt.Println("Service configurations matched successfully using quicktest.CmpEquals.")
}
{
"schemaVersion": 1,
"goal": "verify github.com/frankban/quicktest.CmpEquals in pkg:golang/github.com/frankban/quicktest@v1.14.6",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/frankban/quicktest@v1.14.6"
],
"symbols": [
"github.com/frankban/quicktest.CmpEquals"
]
}
package main
import (
"errors"
"flag"
"fmt"
"os"
"strings"
"testing"
qt "github.com/frankban/quicktest"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
)
type spyTB struct {
*testing.T
failed bool
fataled bool
messages []string
}
func (s *spyTB) Helper() {}
func (s *spyTB) Error(args ...any) {
s.failed = true
s.messages = append(s.messages, fmt.Sprint(args...))
}
func (s *spyTB) Fatal(args ...any) {
s.failed = true
s.fataled = true
s.messages = append(s.messages, fmt.Sprint(args...))
}
func init() {
testing.Init()
flag.Parse()
}
type sampleUser struct {
ID int
Name string
Roles []string
}
type unexportedRecord struct {
Public string
private int
}
func main() {
// Assertion 1: qt.CmpEquals returns a Checker comparing arbitrary values with default deep equality when no options are provided
{
checker := qt.CmpEquals()
noteMap := make(map[string]any)
noteFn := func(k string, v any) { noteMap[k] = v }
// Equal primitives
if err := checker.Check(42, []any{42}, noteFn); err != nil {
fmt.Fprintf(os.Stderr, "assertion 1 failed: primitive equality check failed: %v\n", err)
os.Exit(1)
}
// Equal structs
u1 := sampleUser{ID: 10, Name: "tester", Roles: []string{"admin", "user"}}
u2 := sampleUser{ID: 10, Name: "tester", Roles: []string{"admin", "user"}}
if err := checker.Check(u1, []any{u2}, noteFn); err != nil {
fmt.Fprintf(os.Stderr, "assertion 1 failed: struct equality check failed: %v\n", err)
os.Exit(1)
}
// Equal slices
s1 := []string{"alpha", "beta"}
s2 := []string{"alpha", "beta"}
if err := checker.Check(s1, []any{s2}, noteFn); err != nil {
fmt.Fprintf(os.Stderr, "assertion 1 failed: slice equality check failed: %v\n", err)
os.Exit(1)
}
}
// Assertion 2: qt.CmpEquals returns ErrSilent and reports diff notes when compared values differ
{
checker := qt.CmpEquals()
notes := make(map[string]any)
noteFn := func(k string, v any) { notes[k] = v }
err := checker.Check("expected-val", []any{"actual-val"}, noteFn)
if !errors.Is(err, qt.ErrSilent) {
fmt.Fprintf(os.Stderr, "assertion 2 failed: expected ErrSilent on mismatch, got %v\n", err)
os.Exit(1)
}
errNote, hasErr := notes["error"]
if !hasErr || fmt.Sprint(errNote) != "values are not deep equal" {
fmt.Fprintf(os.Stderr, "assertion 2 failed: missing or incorrect error note: %v\n", errNote)
os.Exit(1)
}
diffNote, hasDiff := notes["diff (-got +want)"]
if !hasDiff || !strings.Contains(fmt.Sprint(diffNote), "expected-val") {
fmt.Fprintf(os.Stderr, "assertion 2 failed: missing or incorrect diff note: %v\n", diffNote)
os.Exit(1)
}
}
// Assertion 3: qt.CmpEquals with cmpopts.IgnoreFields ignores designated struct fields during comparison
{
type itemWithMeta struct {
Key string
Payload string
CreatedAt int64
UpdatedAt int64
}
checker := qt.CmpEquals(cmpopts.IgnoreFields(itemWithMeta{}, "CreatedAt", "UpdatedAt"))
itemA := itemWithMeta{Key: "k1", Payload: "data", CreatedAt: 100, UpdatedAt: 200}
itemB := itemWithMeta{Key: "k1", Payload: "data", CreatedAt: 500, UpdatedAt: 900}
if err := checker.Check(itemA, []any{itemB}, nil); err != nil {
fmt.Fprintf(os.Stderr, "assertion 3 failed: ignored fields should evaluate as equal: %v\n", err)
os.Exit(1)
}
itemMismatch := itemWithMeta{Key: "k2", Payload: "data", CreatedAt: 100, UpdatedAt: 200}
if err := checker.Check(itemA, []any{itemMismatch}, nil); err == nil {
fmt.Fprintf(os.Stderr, "assertion 3 failed: differing unignored fields should fail check\n")
os.Exit(1)
}
}
// Assertion 4: qt.CmpEquals with cmpopts.SortSlices verifies slice equivalence irrespective of element ordering
{
checker := qt.CmpEquals(cmpopts.SortSlices(func(a, b int) bool { return a < b }))
slice1 := []int{5, 2, 8, 1, 9}
slice2 := []int{1, 9, 2, 5, 8}
if err := checker.Check(slice1, []any{slice2}, nil); err != nil {
fmt.Fprintf(os.Stderr, "assertion 4 failed: permuted slices should match with SortSlices: %v\n", err)
os.Exit(1)
}
sliceDiff := []int{1, 9, 2, 5, 7}
if err := checker.Check(slice1, []any{sliceDiff}, nil); err == nil {
fmt.Fprintf(os.Stderr, "assertion 4 failed: slices with different elements should fail check\n")
os.Exit(1)
}
}
// Assertion 5: qt.CmpEquals with cmpopts.EquateApprox matches floating point numbers within specified tolerance
{
checker := qt.CmpEquals(cmpopts.EquateApprox(0, 0.005))
// Within delta 0.005
if err := checker.Check(3.1415, []any{3.1419}, nil); err != nil {
fmt.Fprintf(os.Stderr, "assertion 5 failed: float values within tolerance should match: %v\n", err)
os.Exit(1)
}
// Exceeding delta 0.005
if err := checker.Check(3.1415, []any{3.1500}, nil); err == nil {
fmt.Fprintf(os.Stderr, "assertion 5 failed: float values exceeding tolerance should fail check\n")
os.Exit(1)
}
}
// Assertion 6: qt.CmpEquals detects unexported struct fields and reports a BadCheck error unless unexported comparison options are supplied
{
checkerDefault := qt.CmpEquals()
objA := unexportedRecord{Public: "hello", private: 123}
objB := unexportedRecord{Public: "hello", private: 123}
errBad := checkerDefault.Check(objA, []any{objB}, nil)
if errBad == nil || !qt.IsBadCheck(errBad) {
fmt.Fprintf(os.Stderr, "assertion 6 failed: comparing unexported fields without options should return BadCheck error, got %v\n", errBad)
os.Exit(1)
}
checkerAllowed := qt.CmpEquals(cmp.AllowUnexported(unexportedRecord{}))
if err := checkerAllowed.Check(objA, []any{objB}, nil); err != nil {
fmt.Fprintf(os.Stderr, "assertion 6 failed: AllowUnexported should allow comparison to succeed: %v\n", err)
os.Exit(1)
}
}
// Assertion 7: qt.CmpEquals conforms to the Checker interface with got and want argument names and integrates with quicktest.C Check and Assert
{
checker := qt.CmpEquals()
argNames := checker.ArgNames()
if len(argNames) != 2 || argNames[0] != "got" || argNames[1] != "want" {
fmt.Fprintf(os.Stderr, "assertion 7 failed: ArgNames should be [\"got\", \"want\"], got %v\n", argNames)
os.Exit(1)
}
spy := &spyTB{}
c := qt.New(spy)
// c.Check success
ok := c.Check("data", qt.CmpEquals(), "data")
if !ok || spy.failed {
fmt.Fprintf(os.Stderr, "assertion 7 failed: c.Check should return true without failure: %v\n", spy.messages)
os.Exit(1)
}
// c.Check failure records error without fatal
okFail := c.Check("dataA", qt.CmpEquals(), "dataB")
if okFail || !spy.failed || spy.fataled {
fmt.Fprintf(os.Stderr, "assertion 7 failed: c.Check should return false and record error: ok=%v failed=%v fataled=%v\n", okFail, spy.failed, spy.fataled)
os.Exit(1)
}
// c.Assert success
spyAssert := &spyTB{}
cAssert := qt.New(spyAssert)
assertOk := cAssert.Assert(100, qt.CmpEquals(), 100)
if !assertOk || spyAssert.fataled || spyAssert.failed {
fmt.Fprintf(os.Stderr, "assertion 7 failed: c.Assert should pass cleanly: %v\n", spyAssert.messages)
os.Exit(1)
}
}
fmt.Println("All contract assertions passed successfully.")
}
原始种子者
匿名