Beispiel
github.com/google/go-cmp v0.6.0: cmp.Equal
Verifiziertes Beispiel für golang github.com/google/go-cmp v0.6.0: cmp.Equal. Der Vertrag lief auf go 1.26 · linux debian/x64 · docker und bestand.
sha256:d9d673b97405c07240c87bc9567e9bf7be2c7cece1a883396dd9f51fdfe16b9e
Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen.
Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen.
MIT-0
Ausführungsbelege
Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.
- Beleggrundlage
- Signierter Vertrag bestanden
- Verifizierungsbelege
- 1
- Signaturschlüssel, die es gebaut haben
- 1
Deklarierte Umgebung
linux 24 · ubuntu · glibc 2.39 x64 go go
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| 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-15 |
Fall
HOW- Ziel
- verify github.com/google/go-cmp/cmp.Equal in pkg:golang/github.com/google/go-cmp@v0.6.0
- Symbole
-
- github.com/google/go-cmp/cmp.Equal
- Erstellt
- 2026-09-15T04:05:56Z
Contract
- cmp.Equal returns true for identical primitive, slice, and map values and false for differences
- cmp.Equal returns true for identical structs with exported fields and false for struct field differences
- cmp.Equal supports cmp.Comparer for custom equality predicates
- cmpopts.IgnoreFields excludes specified struct fields from comparison in cmp.Equal
- cmpopts.SortSlices compares unordered slices in cmp.Equal
- cmpopts.IgnoreUnexported and cmp.AllowUnexported handle structs with unexported fields in cmp.Equal
- cmp.Transformer applies value transformations before comparison in cmp.Equal
- cmpopts.EquateEmpty treats nil and empty slices or maps as equal in cmp.Equal
Dateien
- PROMPT.md
- csx.json
- go.mod
- go.sum
- spec.json
- test/contract.go
Quelltext
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/google/go-cmp/cmp.Equal in pkg:golang/github.com/google/go-cmp@v0.6.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/google/go-cmp@v0.6.0
Demonstrate these symbols/APIs:
- github.com/google/go-cmp/cmp.Equal
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:3a266bded0b61bd554db800ac28d8ad706e7fa66eb68614cce151ecff2fc70d8","contract":["cmp.Equal returns true for identical primitive, slice, and map values and false for differences","cmp.Equal returns true for identical structs with exported fields and false for struct field differences","cmp.Equal supports cmp.Comparer for custom equality predicates","cmpopts.IgnoreFields excludes specified struct fields from comparison in cmp.Equal","cmpopts.SortSlices compares unordered slices in cmp.Equal","cmpopts.IgnoreUnexported and cmp.AllowUnexported handle structs with unexported fields in cmp.Equal","cmp.Transformer applies value transformations before comparison in cmp.Equal","cmpopts.EquateEmpty treats nil and empty slices or maps as equal in cmp.Equal"],"goal":"verify github.com/google/go-cmp/cmp.Equal in pkg:golang/github.com/google/go-cmp@v0.6.0","kind":"HOW","packages":["pkg:golang/github.com/google/go-cmp@v0.6.0"],"schemaVersion":1,"symbols":["github.com/google/go-cmp/cmp.Equal"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/google/go-cmp@v0.6.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/google/go-cmp@v0.6.0","symbols":["github.com/google/go-cmp/cmp.Equal"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require github.com/google/go-cmp v0.6.0
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
{
"schemaVersion": 1,
"goal": "verify github.com/google/go-cmp/cmp.Equal in pkg:golang/github.com/google/go-cmp@v0.6.0",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/google/go-cmp@v0.6.0"
],
"symbols": [
"github.com/google/go-cmp/cmp.Equal"
]
}
package main
import (
"fmt"
"os"
"strings"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
)
type userAccount struct {
ID int
Username string
CreatedAt string
}
type internalState struct {
Name string
secret string
}
func main() {
if err := runContractTests(); err != nil {
fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
os.Exit(1)
}
fmt.Println("All contract tests passed successfully.")
}
func runContractTests() error {
// 1. cmp.Equal returns true for identical primitive, slice, and map values and false for differences
if !cmp.Equal(42, 42) {
return fmt.Errorf("expected 42 == 42")
}
if cmp.Equal(42, 43) {
return fmt.Errorf("expected 42 != 43")
}
if !cmp.Equal([]string{"alpha", "beta"}, []string{"alpha", "beta"}) {
return fmt.Errorf("expected slice match")
}
if cmp.Equal([]string{"alpha", "beta"}, []string{"beta", "alpha"}) {
return fmt.Errorf("expected ordered slices to differ without options")
}
if !cmp.Equal(map[string]int{"a": 1, "b": 2}, map[string]int{"b": 2, "a": 1}) {
return fmt.Errorf("expected map key/value equality")
}
// 2. cmp.Equal returns true for identical structs with exported fields and false for struct field differences
u1 := userAccount{ID: 1, Username: "user-alpha", CreatedAt: "2026-01-01"}
u2 := userAccount{ID: 1, Username: "user-alpha", CreatedAt: "2026-01-01"}
u3 := userAccount{ID: 1, Username: "user-beta", CreatedAt: "2026-01-01"}
if !cmp.Equal(u1, u2) {
return fmt.Errorf("expected identical structs to be equal")
}
if cmp.Equal(u1, u3) {
return fmt.Errorf("expected structs with different fields to be unequal")
}
// 3. cmp.Equal supports cmp.Comparer for custom equality predicates
approxEqual := cmp.Comparer(func(x, y float64) bool {
delta := x - y
if delta < 0 {
delta = -delta
}
return delta < 0.001
})
if !cmp.Equal(1.0001, 1.0002, approxEqual) {
return fmt.Errorf("expected custom comparer to treat close floats as equal")
}
if cmp.Equal(1.0, 2.0, approxEqual) {
return fmt.Errorf("expected custom comparer to treat distinct floats as unequal")
}
// 4. cmpopts.IgnoreFields excludes specified struct fields from comparison in cmp.Equal
u4 := userAccount{ID: 2, Username: "user-gamma", CreatedAt: "2026-01-01"}
u5 := userAccount{ID: 2, Username: "user-gamma", CreatedAt: "2026-08-28"}
if cmp.Equal(u4, u5) {
return fmt.Errorf("expected structs to differ without IgnoreFields")
}
if !cmp.Equal(u4, u5, cmpopts.IgnoreFields(userAccount{}, "CreatedAt")) {
return fmt.Errorf("expected structs to match with CreatedAt ignored")
}
// 5. cmpopts.SortSlices compares unordered slices in cmp.Equal
s1 := []int{5, 2, 8, 1}
s2 := []int{1, 2, 5, 8}
lessInt := func(a, b int) bool { return a < b }
if cmp.Equal(s1, s2) {
return fmt.Errorf("expected unordered slices to differ by default")
}
if !cmp.Equal(s1, s2, cmpopts.SortSlices(lessInt)) {
return fmt.Errorf("expected SortSlices to match elements regardless of order")
}
// 6. cmpopts.IgnoreUnexported and cmp.AllowUnexported handle structs with unexported fields in cmp.Equal
st1 := internalState{Name: "core", secret: "val-a"}
st2 := internalState{Name: "core", secret: "val-b"}
if !cmp.Equal(st1, st2, cmpopts.IgnoreUnexported(internalState{})) {
return fmt.Errorf("expected IgnoreUnexported to match structs differing only in unexported fields")
}
st3 := internalState{Name: "core", secret: "val-a"}
if !cmp.Equal(st1, st3, cmp.AllowUnexported(internalState{})) {
return fmt.Errorf("expected AllowUnexported to match identical structs with private fields")
}
// 7. cmp.Transformer applies value transformations before comparison in cmp.Equal
caseInsensitive := cmp.Transformer("ToLower", strings.ToLower)
if !cmp.Equal("HelloWorld", "helloworld", caseInsensitive) {
return fmt.Errorf("expected transformer to normalize casing")
}
// 8. cmpopts.EquateEmpty treats nil and empty slices or maps as equal in cmp.Equal
var nilSlice []string
emptySlice := []string{}
if cmp.Equal(nilSlice, emptySlice) {
return fmt.Errorf("expected nil slice and empty slice to differ by default")
}
if !cmp.Equal(nilSlice, emptySlice, cmpopts.EquateEmpty()) {
return fmt.Errorf("expected EquateEmpty to treat nil and empty slice as equal")
}
return nil
}
Ursprungs-Seeder
anonym