CodeSampleX

サンプル

github.com/stretchr/testify v1.5.1

検証済みサンプル — golang github.com/stretchr/testify v1.5.1. go 1.26 · linux debian/x64 · docker で contract を実行し、成功しました: assert.Equal returns true and records no…

sha256:cd7b081e6b640c9c41791e2ff48b3085ea9d2a24cf6e248bf10239fd826adc7c

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 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-19

ケース

HOW
ゴール
verify pkg:golang/github.com/stretchr/testify@v1.5.1
パッケージ
環境
go 1.26.6
作成日
2026-09-17T21:07:26Z

コントラクト

  1. assert.Equal returns true and records no error on equal values, and returns false with error formatting on inequality or type mismatch
  2. assert.NotEqual returns true when comparing distinct values and returns false when values are identical
  3. assert.NoError returns true for nil errors, while assert.Error returns true and records failure when error is expected
  4. assert.True returns true for true condition and assert.False returns true for false condition
  5. assert.Panics returns true when target function triggers a panic and returns false when function completes normally
  6. assert.NotPanics returns true and records no error when executed function does not panic
  7. assert.ElementsMatch returns true when two slices contain identical elements regardless of ordering
  8. 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

ソースアーティファクトをダウンロード (tar.gz)

ソース

PROMPT.md
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.5.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/stretchr/testify@v1.5.1

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.
csx.json
{"case":{"caseId":"case:sha256:8b301925416a9e7c9eba956726e86f5357c1392d8fdc7ca02865c5aebb6279e2","contract":["assert.Equal returns true and records no error on equal values, and returns false with error formatting on inequality or type mismatch","assert.NotEqual returns true when comparing distinct values and returns false when values are identical","assert.NoError returns true for nil errors, while assert.Error returns true and records failure when error is expected","assert.True returns true for true condition and assert.False returns true for false condition","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.5.1","kind":"HOW","packages":["pkg:golang/github.com/stretchr/testify@v1.5.1"],"schemaVersion":1},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","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.5.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/stretchr/testify@v1.5.1","verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/stretchr/testify v1.5.1

require (
	github.com/davecgh/go-spew v1.1.0 // indirect
	github.com/pmezard/go-difflib v1.0.0 // indirect
	github.com/stretchr/objx v0.1.0 // indirect
	gopkg.in/yaml.v2 v2.2.2 // indirect
)
go.sum
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 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
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=
main.go
package main

import (
	"errors"
	"fmt"

	"github.com/stretchr/testify/assert"
)

// Reporter implements assert.TestingT to record assertion occurrences.
type Reporter struct {
	errors []string
	failed bool
}

func (r *Reporter) Errorf(format string, args ...interface{}) {
	r.failed = true
	r.errors = append(r.errors, fmt.Sprintf(format, args...))
}

func computeDiscount(price float64, discountRate float64) (float64, error) {
	if discountRate < 0 || discountRate > 1.0 {
		return 0, errors.New("discount rate must be between 0 and 1")
	}
	return price * (1.0 - discountRate), nil
}

func main() {
	r := &Reporter{}

	// Verify equal and not equal
	assert.Equal(r, 10, 10, "values should be equal")
	assert.NotEqual(r, 10, 20, "values should not be equal")

	// Verify boolean conditions
	assert.True(r, true, "condition should be true")
	assert.False(r, false, "condition should be false")

	// Verify error handling
	finalPrice, err := computeDiscount(100.0, 0.2)
	assert.NoError(r, err, "computeDiscount should succeed")
	assert.InDelta(r, 80.0, finalPrice, 0.001, "discount calculation should be accurate")

	_, errInvalid := computeDiscount(100.0, 1.5)
	assert.Error(r, errInvalid, "invalid discount should produce error")

	if !r.failed {
		fmt.Println("All assertions succeeded.")
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/stretchr/testify@v1.5.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/stretchr/testify@v1.5.1"
  ]
}
test/contract.go
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 with error formatting 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.NoError returns true for nil errors, while assert.Error returns true and records failure when error is expected
	{
		t := &contractTestingT{}
		if !assert.NoError(t, nil) || t.failed || len(t.errors) != 0 {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: NoError should succeed on nil error\n")
			os.Exit(1)
		}

		tErrFail := &contractTestingT{}
		sampleErr := errors.New("operation failed")
		if assert.NoError(tErrFail, sampleErr) || !tErrFail.failed || len(tErrFail.errors) == 0 {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: NoError should fail on non-nil error\n")
			os.Exit(1)
		}

		tErrExpected := &contractTestingT{}
		if !assert.Error(tErrExpected, sampleErr) || tErrExpected.failed || len(tErrExpected.errors) != 0 {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: Error should return true when error is present\n")
			os.Exit(1)
		}

		tNilErrExpected := &contractTestingT{}
		if assert.Error(tNilErrExpected, nil) || !tNilErrExpected.failed || len(tNilErrExpected.errors) == 0 {
			fmt.Fprintf(os.Stderr, "assertion 3 failed: Error should return false and report failure when error is nil\n")
			os.Exit(1)
		}
	}

	// Assertion 4: assert.True returns true for true condition and assert.False returns true for false condition
	{
		t := &contractTestingT{}
		if !assert.True(t, true) || t.failed || len(t.errors) != 0 {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: True should succeed on true condition\n")
			os.Exit(1)
		}

		tTrueFail := &contractTestingT{}
		if assert.True(tTrueFail, false) || !tTrueFail.failed || len(tTrueFail.errors) == 0 {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: True should fail on false condition\n")
			os.Exit(1)
		}

		tFalse := &contractTestingT{}
		if !assert.False(tFalse, false) || tFalse.failed || len(tFalse.errors) != 0 {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: False should succeed on false condition\n")
			os.Exit(1)
		}

		tFalseFail := &contractTestingT{}
		if assert.False(tFalseFail, true) || !tFalseFail.failed || len(tFalseFail.errors) == 0 {
			fmt.Fprintf(os.Stderr, "assertion 4 failed: False should fail on true condition\n")
			os.Exit(1)
		}
	}

	// Assertion 5: 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 5 failed: Panics should return true on panic\n")
			os.Exit(1)
		}

		tNoPanic := &contractTestingT{}
		didPanicClean := assert.Panics(tNoPanic, func() {
			// clean execution
		})
		if didPanicClean || !tNoPanic.failed || len(tNoPanic.errors) == 0 {
			fmt.Fprintf(os.Stderr, "assertion 5 failed: Panics should return false and report error on clean function\n")
			os.Exit(1)
		}
	}

	// Assertion 6: 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 6 failed: NotPanics should succeed when function completes cleanly\n")
			os.Exit(1)
		}

		tPanic := &contractTestingT{}
		noPanicOnCrash := assert.NotPanics(tPanic, func() {
			panic("unexpected crash")
		})
		if noPanicOnCrash || !tPanic.failed || len(tPanic.errors) == 0 {
			fmt.Fprintf(os.Stderr, "assertion 6 failed: NotPanics should return false and report error on panic\n")
			os.Exit(1)
		}
	}

	// Assertion 7: assert.ElementsMatch returns true when two slices contain identical elements regardless of ordering
	{
		t := &contractTestingT{}
		sliceA := []string{"alpha", "beta", "gamma"}
		sliceB := []string{"gamma", "alpha", "beta"}
		if !assert.ElementsMatch(t, sliceA, sliceB) || t.failed || len(t.errors) != 0 {
			fmt.Fprintf(os.Stderr, "assertion 7 failed: ElementsMatch should succeed on permutations\n")
			os.Exit(1)
		}

		tDiff := &contractTestingT{}
		sliceC := []string{"alpha", "beta", "delta"}
		if assert.ElementsMatch(tDiff, sliceA, sliceC) || !tDiff.failed || len(tDiff.errors) == 0 {
			fmt.Fprintf(os.Stderr, "assertion 7 failed: ElementsMatch should return false on mismatched elements\n")
			os.Exit(1)
		}
	}

	// Assertion 8: 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 8 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 8 failed: InDelta should return false when difference exceeds delta\n")
			os.Exit(1)
		}
	}

	fmt.Println("All contract assertions passed successfully.")
}

オリジンシーダー

匿名