Пример
github.com/stretchr/testify v1.7.0: suite.Suite
Проверенный пример — golang github.com/stretchr/testify v1.7.0: suite.Suite. Контракт выполнен на go 1.26 · linux debian/x64 · docker и пройден.
sha256:2c18e083d87475a51aab28226fb02ab1f866ae91a9959382c65155692ad91142
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
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-06 |
Кейс
HOW- Цель
- verify github.com/stretchr/testify/suite.Suite in pkg:golang/github.com/stretchr/testify@v1.7.0
- Символы
-
- github.com/stretchr/testify/suite.Suite
- Окружение
- go 1.26.6
- Создан
- 2026-09-06T06:51:13Z
Контракт
- suite.Suite stores and returns the active testing context via SetT and T
- suite.Suite initializes assert and require helpers bound to the testing context upon SetT
- suite.Suite enables direct assertion calls through embedded assert.Assertions
- suite.Suite.Run executes a subtest with an isolated child context and restores the parent context
- suite.Run executes all exported Test methods on a type embedding suite.Suite
Файлы
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract_test.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/stretchr/testify/suite.Suite in pkg:golang/github.com/stretchr/testify@v1.7.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/stretchr/testify@v1.7.0
Demonstrate these symbols/APIs:
- github.com/stretchr/testify/suite.Suite
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:19013c199bf18a2447e1ff945e03c5aea99ae0671091af9e4cd2630a96d4c614","contract":["suite.Suite stores and returns the active testing context via SetT and T","suite.Suite initializes assert and require helpers bound to the testing context upon SetT","suite.Suite enables direct assertion calls through embedded assert.Assertions","suite.Suite.Run executes a subtest with an isolated child context and restores the parent context","suite.Run executes all exported Test methods on a type embedding suite.Suite"],"goal":"verify github.com/stretchr/testify/suite.Suite in pkg:golang/github.com/stretchr/testify@v1.7.0","kind":"HOW","packages":["pkg:golang/github.com/stretchr/testify@v1.7.0"],"schemaVersion":1,"symbols":["github.com/stretchr/testify/suite.Suite"]},"contractCommand":["go","test","-v","./..."],"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.7.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/stretchr/testify@v1.7.0","symbols":["github.com/stretchr/testify/suite.Suite"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require github.com/stretchr/testify v1.7.0
require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // 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.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
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.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
package main
import (
"fmt"
"github.com/stretchr/testify/suite"
)
// Counter manages a simple integer value with basic operations.
type Counter struct {
value int
}
// NewCounter creates a new Counter initialized with a base value.
func NewCounter(initial int) *Counter {
return &Counter{value: initial}
}
// Increment increments the counter by step.
func (c *Counter) Increment(step int) int {
c.value += step
return c.value
}
// Value returns the current counter value.
func (c *Counter) Value() int {
return c.value
}
// CounterSuite demonstrates test organization using testify's suite.Suite.
type CounterSuite struct {
suite.Suite
counter *Counter
}
// SetupTest prepares fresh state before each test in the suite.
func (s *CounterSuite) SetupTest() {
s.counter = NewCounter(10)
}
// TestIncrement verifies that Increment increases the stored value.
func (s *CounterSuite) TestIncrement() {
result := s.counter.Increment(5)
s.Equal(15, result)
s.Equal(15, s.counter.Value())
}
// TestAccessors verifies Assert and Require accessors on the embedded suite.Suite.
func (s *CounterSuite) TestAccessors() {
s.Assert().NotNil(s.counter)
s.Require().Equal(10, s.counter.Value())
}
func main() {
counter := NewCounter(0)
counter.Increment(1)
fmt.Printf("Counter initialized with value: %d\n", counter.Value())
}
{
"schemaVersion": 1,
"goal": "verify github.com/stretchr/testify/suite.Suite in pkg:golang/github.com/stretchr/testify@v1.7.0",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/stretchr/testify@v1.7.0"
],
"symbols": [
"github.com/stretchr/testify/suite.Suite"
]
}
package test
import (
"testing"
"github.com/stretchr/testify/suite"
)
type ExecutionSuite struct {
suite.Suite
firstRun bool
secondRun bool
helperRun bool
}
func (s *ExecutionSuite) TestFirst() {
s.firstRun = true
s.Equal("alpha", "alpha")
}
func (s *ExecutionSuite) TestSecond() {
s.secondRun = true
s.NotNil(s.T())
}
func (s *ExecutionSuite) HelperMethod() {
s.helperRun = true
}
func TestContract(t *testing.T) {
// Assertion 1: suite.Suite stores and returns the active testing context via SetT and T
{
s := new(suite.Suite)
if s.T() != nil {
t.Fatalf("assertion 1 failed: initial T() must be nil")
}
s.SetT(t)
if s.T() != t {
t.Fatalf("assertion 1 failed: T() must return context set by SetT")
}
s.SetT(nil)
if s.T() != nil {
t.Fatalf("assertion 1 failed: T() must return nil after SetT(nil)")
}
s.SetT(t)
}
// Assertion 2: suite.Suite initializes assert and require helpers bound to the testing context upon SetT
{
s := new(suite.Suite)
s.SetT(t)
if s.Assertions == nil {
t.Fatalf("assertion 2 failed: embedded Assertions must not be nil after SetT")
}
if s.Assert() == nil {
t.Fatalf("assertion 2 failed: Assert() must not be nil")
}
if s.Require() == nil {
t.Fatalf("assertion 2 failed: Require() must not be nil")
}
if !s.Assert().True(true) {
t.Fatalf("assertion 2 failed: Assert().True failed")
}
}
// Assertion 3: suite.Suite enables direct assertion calls through embedded assert.Assertions
{
s := new(suite.Suite)
s.SetT(t)
if !s.Equal(100, 100) {
t.Fatalf("assertion 3 failed: s.Equal failed")
}
if !s.NotEqual(100, 200) {
t.Fatalf("assertion 3 failed: s.NotEqual failed")
}
if !s.True(true) {
t.Fatalf("assertion 3 failed: s.True failed")
}
if !s.False(false) {
t.Fatalf("assertion 3 failed: s.False failed")
}
if !s.Nil(nil) {
t.Fatalf("assertion 3 failed: s.Nil failed")
}
if !s.NotNil(s.T()) {
t.Fatalf("assertion 3 failed: s.NotNil failed")
}
if !s.NoError(nil) {
t.Fatalf("assertion 3 failed: s.NoError failed")
}
if !s.Len([]int{1, 2, 3}, 3) {
t.Fatalf("assertion 3 failed: s.Len failed")
}
}
// Assertion 4: suite.Suite.Run executes a subtest with an isolated child context and restores the parent context
{
s := new(suite.Suite)
s.SetT(t)
parentT := s.T()
subtestExecuted := false
var childT *testing.T
ok := s.Run("ChildSubtest", func() {
subtestExecuted = true
childT = s.T()
if childT == nil {
t.Fatalf("assertion 4 failed: child context must not be nil")
}
if childT == parentT {
t.Fatalf("assertion 4 failed: child context must differ from parent context")
}
s.Equal("nested", "nested")
})
if !ok || !subtestExecuted {
t.Fatalf("assertion 4 failed: subtest execution did not complete successfully")
}
if s.T() != parentT {
t.Fatalf("assertion 4 failed: parent context must be restored after subtest completion")
}
}
// Assertion 5: suite.Run executes all exported Test methods on a type embedding suite.Suite
{
execSuite := new(ExecutionSuite)
suite.Run(t, execSuite)
if !execSuite.firstRun {
t.Fatalf("assertion 5 failed: TestFirst was not executed")
}
if !execSuite.secondRun {
t.Fatalf("assertion 5 failed: TestSecond was not executed")
}
if execSuite.helperRun {
t.Fatalf("assertion 5 failed: non-test HelperMethod should not be executed")
}
}
}
Исходный сидер
аноним