샘플
github.com/stretchr/testify v1.4.0
검증된 샘플 — golang github.com/stretchr/testify v1.4.0. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: assert.Equal returns true and records no…
sha256:d678717cca9686bf5abee3892e8d119101a0c62609ef9ce03ce0cdddd0e8f025
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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-04 |
케이스
HOW- 목표
- verify pkg:golang/github.com/stretchr/testify@v1.4.0
- 환경
- go 1.26.6
- 생성일
- 2026-09-04T19:20:28Z
컨트랙트
- assert.Equal returns true and records no error on equal values, and returns false on inequality or type mismatch
- assert.NotEqual returns true when comparing distinct values and returns false when values are identical
- assert.Nil returns true for nil pointers and interfaces, and returns false for non-nil references
- assert.NotNil returns true for non-nil references and returns false for nil references
- assert.NoError returns true for nil errors, while assert.Error returns true on non-nil error and false on nil error
- assert.Panics returns true when target function triggers a panic and returns false when function completes normally
- assert.NotPanics returns true and records no error when executed function does not panic
- assert.ElementsMatch returns true when two slices contain identical elements regardless of ordering
- assert.InDelta returns true when numeric difference is within delta threshold and returns false when exceeding threshold
파일
- 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 pkg:golang/github.com/stretchr/testify@v1.4.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/stretchr/testify@v1.4.0
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:4fc893f8c18575e4878c810f21cc00063423c94110cbd75ea66323bb20a6e94a","contract":["assert.Equal returns true and records no error on equal values, and returns false on inequality or type mismatch","assert.NotEqual returns true when comparing distinct values and returns false when values are identical","assert.Nil returns true for nil pointers and interfaces, and returns false for non-nil references","assert.NotNil returns true for non-nil references and returns false for nil references","assert.NoError returns true for nil errors, while assert.Error returns true on non-nil error and false on nil error","assert.Panics returns true when target function triggers a panic and returns false when function completes normally","assert.NotPanics returns true and records no error when executed function does not panic","assert.ElementsMatch returns true when two slices contain identical elements regardless of ordering","assert.InDelta returns true when numeric difference is within delta threshold and returns false when exceeding threshold"],"goal":"verify pkg:golang/github.com/stretchr/testify@v1.4.0","kind":"HOW","packages":["pkg:golang/github.com/stretchr/testify@v1.4.0"],"schemaVersion":1},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/stretchr/testify@v1.4.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/stretchr/testify@v1.4.0","verifierAdapter":"golang@1"}
module sample
go 1.26.6
require github.com/stretchr/testify v1.4.0
require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
)
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
package main
import (
"errors"
"fmt"
"github.com/stretchr/testify/assert"
)
// Reporter collects assertion failures without halting execution.
type Reporter struct {
errors []string
}
func (r *Reporter) Errorf(format string, args ...interface{}) {
r.errors = append(r.errors, fmt.Sprintf(format, args...))
}
// Config represents application configuration to validate.
type Config struct {
Host string
Port int
Tags []string
Timeout float64
}
// ValidateConfig validates config values using testify assertions.
func ValidateConfig(t assert.TestingT, cfg *Config) bool {
if !assert.NotNil(t, cfg, "config must not be nil") {
return false
}
ok := true
ok = assert.NotEmpty(t, cfg.Host, "host should not be empty") && ok
ok = assert.True(t, cfg.Port > 0 && cfg.Port <= 65535, "port should be valid") && ok
ok = assert.Contains(t, cfg.Tags, "service", "tags should contain service") && ok
ok = assert.InDelta(t, 5.0, cfg.Timeout, 1.0, "timeout should be approximately 5.0s") && ok
return ok
}
// Process processes the configuration.
func Process(cfg *Config) error {
if cfg == nil {
return errors.New("nil config")
}
return nil
}
func main() {
r := &Reporter{}
cfg := &Config{
Host: "localhost",
Port: 8080,
Tags: []string{"web", "service"},
Timeout: 5.2,
}
valid := ValidateConfig(r, cfg)
if !valid || len(r.errors) > 0 {
fmt.Printf("Validation failed with %d errors\n", len(r.errors))
return
}
err := Process(cfg)
assert.NoError(r, err, "Process should succeed without error")
fmt.Println("Config validated and processed successfully.")
}
{
"schemaVersion": 1,
"goal": "verify pkg:golang/github.com/stretchr/testify@v1.4.0",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/stretchr/testify@v1.4.0"
]
}
package main
import (
"errors"
"fmt"
"os"
"github.com/stretchr/testify/assert"
)
type contractTestingT struct {
errors []string
failed bool
}
func (t *contractTestingT) Errorf(format string, args ...interface{}) {
t.failed = true
t.errors = append(t.errors, fmt.Sprintf(format, args...))
}
func main() {
// Assertion 1: assert.Equal returns true and records no error on equal values, and returns false on inequality or type mismatch
{
t := &contractTestingT{}
if !assert.Equal(t, "expected-string", "expected-string") || t.failed || len(t.errors) != 0 {
fmt.Fprintf(os.Stderr, "assertion 1 failed: Equal should succeed on matching strings\n")
os.Exit(1)
}
tMismatch := &contractTestingT{}
if assert.Equal(tMismatch, "value1", "value2") || !tMismatch.failed || len(tMismatch.errors) == 0 {
fmt.Fprintf(os.Stderr, "assertion 1 failed: Equal should return false on mismatched values\n")
os.Exit(1)
}
tTypeMismatch := &contractTestingT{}
if assert.Equal(tTypeMismatch, int(42), int64(42)) || !tTypeMismatch.failed || len(tTypeMismatch.errors) == 0 {
fmt.Fprintf(os.Stderr, "assertion 1 failed: Equal should return false on type mismatch\n")
os.Exit(1)
}
}
// Assertion 2: assert.NotEqual returns true when comparing distinct values and returns false when values are identical
{
t := &contractTestingT{}
if !assert.NotEqual(t, 10, 20) || t.failed || len(t.errors) != 0 {
fmt.Fprintf(os.Stderr, "assertion 2 failed: NotEqual should succeed on distinct values\n")
os.Exit(1)
}
tEqual := &contractTestingT{}
if assert.NotEqual(tEqual, 10, 10) || !tEqual.failed || len(tEqual.errors) == 0 {
fmt.Fprintf(os.Stderr, "assertion 2 failed: NotEqual should return false on identical values\n")
os.Exit(1)
}
}
// Assertion 3: assert.Nil returns true for nil pointers and interfaces, and returns false for non-nil references
{
t := &contractTestingT{}
var ptr *int = nil
if !assert.Nil(t, ptr) || t.failed || len(t.errors) != 0 {
fmt.Fprintf(os.Stderr, "assertion 3 failed: Nil should succeed on nil pointer\n")
os.Exit(1)
}
val := 42
tNotNil := &contractTestingT{}
if assert.Nil(tNotNil, &val) || !tNotNil.failed || len(tNotNil.errors) == 0 {
fmt.Fprintf(os.Stderr, "assertion 3 failed: Nil should return false on non-nil pointer\n")
os.Exit(1)
}
}
// Assertion 4: assert.NotNil returns true for non-nil references and returns false for nil references
{
t := &contractTestingT{}
val := "sample"
if !assert.NotNil(t, &val) || t.failed || len(t.errors) != 0 {
fmt.Fprintf(os.Stderr, "assertion 4 failed: NotNil should succeed on non-nil value\n")
os.Exit(1)
}
tNil := &contractTestingT{}
var ptr *string = nil
if assert.NotNil(tNil, ptr) || !tNil.failed || len(tNil.errors) == 0 {
fmt.Fprintf(os.Stderr, "assertion 4 failed: NotNil should return false on nil reference\n")
os.Exit(1)
}
}
// Assertion 5: assert.NoError returns true for nil errors, while assert.Error returns true on non-nil error and false on nil error
{
t := &contractTestingT{}
if !assert.NoError(t, nil) || t.failed || len(t.errors) != 0 {
fmt.Fprintf(os.Stderr, "assertion 5 failed: NoError should succeed on nil error\n")
os.Exit(1)
}
sampleErr := errors.New("operation failed")
tErr := &contractTestingT{}
if assert.NoError(tErr, sampleErr) || !tErr.failed || len(tErr.errors) == 0 {
fmt.Fprintf(os.Stderr, "assertion 5 failed: NoError should fail on non-nil error\n")
os.Exit(1)
}
tErrorSuccess := &contractTestingT{}
if !assert.Error(tErrorSuccess, sampleErr) || tErrorSuccess.failed || len(tErrorSuccess.errors) != 0 {
fmt.Fprintf(os.Stderr, "assertion 5 failed: Error should return true on non-nil error\n")
os.Exit(1)
}
tErrorFail := &contractTestingT{}
if assert.Error(tErrorFail, nil) || !tErrorFail.failed || len(tErrorFail.errors) == 0 {
fmt.Fprintf(os.Stderr, "assertion 5 failed: Error should return false on nil error\n")
os.Exit(1)
}
}
// Assertion 6: assert.Panics returns true when target function triggers a panic and returns false when function completes normally
{
t := &contractTestingT{}
didPanic := assert.Panics(t, func() {
panic("critical failure")
})
if !didPanic || t.failed || len(t.errors) != 0 {
fmt.Fprintf(os.Stderr, "assertion 6 failed: Panics should return true on panic\n")
os.Exit(1)
}
tNoPanic := &contractTestingT{}
didPanicClean := assert.Panics(tNoPanic, func() {
// clean function
})
if didPanicClean || !tNoPanic.failed || len(tNoPanic.errors) == 0 {
fmt.Fprintf(os.Stderr, "assertion 6 failed: Panics should return false on clean function\n")
os.Exit(1)
}
}
// Assertion 7: assert.NotPanics returns true and records no error when executed function does not panic
{
t := &contractTestingT{}
noPanic := assert.NotPanics(t, func() {
_ = 1 + 1
})
if !noPanic || t.failed || len(t.errors) != 0 {
fmt.Fprintf(os.Stderr, "assertion 7 failed: NotPanics should succeed when function does not panic\n")
os.Exit(1)
}
tPanic := &contractTestingT{}
noPanicOnCrash := assert.NotPanics(tPanic, func() {
panic("crash")
})
if noPanicOnCrash || !tPanic.failed || len(tPanic.errors) == 0 {
fmt.Fprintf(os.Stderr, "assertion 7 failed: NotPanics should return false when function panics\n")
os.Exit(1)
}
}
// Assertion 8: assert.ElementsMatch returns true when two slices contain identical elements regardless of ordering
{
t := &contractTestingT{}
sliceA := []string{"apple", "banana", "cherry"}
sliceB := []string{"cherry", "apple", "banana"}
if !assert.ElementsMatch(t, sliceA, sliceB) || t.failed || len(t.errors) != 0 {
fmt.Fprintf(os.Stderr, "assertion 8 failed: ElementsMatch should succeed on permutations\n")
os.Exit(1)
}
tDiff := &contractTestingT{}
sliceC := []string{"apple", "cherry", "date"}
if assert.ElementsMatch(tDiff, sliceA, sliceC) || !tDiff.failed || len(tDiff.errors) == 0 {
fmt.Fprintf(os.Stderr, "assertion 8 failed: ElementsMatch should return false on mismatched elements\n")
os.Exit(1)
}
}
// Assertion 9: assert.InDelta returns true when numeric difference is within delta threshold and returns false when exceeding threshold
{
t := &contractTestingT{}
if !assert.InDelta(t, 3.14159, 3.14, 0.01) || t.failed || len(t.errors) != 0 {
fmt.Fprintf(os.Stderr, "assertion 9 failed: InDelta should succeed within threshold\n")
os.Exit(1)
}
tExceed := &contractTestingT{}
if assert.InDelta(tExceed, 3.14159, 3.10, 0.01) || !tExceed.failed || len(tExceed.errors) == 0 {
fmt.Fprintf(os.Stderr, "assertion 9 failed: InDelta should return false when difference exceeds delta\n")
os.Exit(1)
}
}
fmt.Println("All contract assertions passed successfully.")
}
오리진 시더
익명