CodeSampleX

Exemple

github.com/stretchr/testify v1.11.1: suite.Suite

Échantillon vérifié pour golang github.com/stretchr/testify v1.11.1: suite.Suite. Le contrat s'est exécuté sur go 1.26 · linux alpine/x64 · docker et a…

sha256:69581474d42bb34d77f88a55c2cee4735657641b68a28b9652a523feb45aeb92

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 go

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-23

Cas

HOW
Objectif
verify github.com/stretchr/testify/suite.Suite in pkg:golang/github.com/stretchr/testify@v1.11.1
Paquets
Symboles
  • github.com/stretchr/testify/suite.Suite
Créé
2026-08-23T06:12:28Z

Contrat

  1. suite.Suite implements suite.TestingSuite interface providing T(), SetT(), and SetS()
  2. suite.Run discovers and executes all exported Test methods on structs embedding suite.Suite
  3. suite lifecycle hooks (SetupSuite, SetupTest, BeforeTest, AfterTest, TearDownTest, TearDownSuite) execute in deterministic order
  4. s.Run executes hierarchical subtests with isolated test context and triggers SetupSubTest and TearDownSubTest hooks
  5. embedded assertion and requirement helpers (s.Equal, s.True, s.NotNil, s.Require) operate on the active testing context

Fichiers

  • PROMPT.md
  • contract_test.go
  • csx.json
  • go.mod
  • go.sum
  • spec.json

Télécharger l’artefact source (tar.gz)

Code source

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 github.com/stretchr/testify/suite.Suite in pkg:golang/github.com/stretchr/testify@v1.11.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/stretchr/testify@v1.11.1
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.
contract_test.go
package sample_test

import (
	"reflect"
	"testing"

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

// LifecycleTestSuite verifies suite lifecycle hooks, execution order, and subtests
type LifecycleTestSuite struct {
	suite.Suite
	events []string
}

func (s *LifecycleTestSuite) SetupSuite() {
	s.events = append(s.events, "SetupSuite")
}

func (s *LifecycleTestSuite) TearDownSuite() {
	s.events = append(s.events, "TearDownSuite")
}

func (s *LifecycleTestSuite) SetupTest() {
	s.events = append(s.events, "SetupTest")
}

func (s *LifecycleTestSuite) TearDownTest() {
	s.events = append(s.events, "TearDownTest")
}

func (s *LifecycleTestSuite) BeforeTest(suiteName, testName string) {
	s.events = append(s.events, "BeforeTest:"+testName)
}

func (s *LifecycleTestSuite) AfterTest(suiteName, testName string) {
	s.events = append(s.events, "AfterTest:"+testName)
}

func (s *LifecycleTestSuite) SetupSubTest() {
	s.events = append(s.events, "SetupSubTest")
}

func (s *LifecycleTestSuite) TearDownSubTest() {
	s.events = append(s.events, "TearDownSubTest")
}

func (s *LifecycleTestSuite) HelperNonTestMethod() {
	s.events = append(s.events, "HelperNonTestMethod")
}

func (s *LifecycleTestSuite) TestFirst() {
	s.events = append(s.events, "TestFirst")
	s.NotNil(s.T())
	s.Equal("TestLifecycleTestSuite/TestFirst", s.T().Name())
}

func (s *LifecycleTestSuite) TestSecondWithSubtests() {
	s.events = append(s.events, "TestSecondWithSubtests")

	executedSubtest := s.Run("nested_step", func() {
		s.events = append(s.events, "InsideSubtest")
		s.True(true)
		s.Contains(s.T().Name(), "TestSecondWithSubtests/nested_step")
	})
	s.True(executedSubtest)
}

func TestLifecycleTestSuite(t *testing.T) {
	s := new(LifecycleTestSuite)

	// Verify suite.Suite implements suite.TestingSuite
	var _ suite.TestingSuite = s

	suite.Run(t, s)

	expectedEvents := []string{
		"SetupSuite",
		"SetupTest", "BeforeTest:TestFirst", "TestFirst", "AfterTest:TestFirst", "TearDownTest",
		"SetupTest", "BeforeTest:TestSecondWithSubtests", "TestSecondWithSubtests", "SetupSubTest", "InsideSubtest", "TearDownSubTest", "AfterTest:TestSecondWithSubtests", "TearDownTest",
		"TearDownSuite",
	}

	if !reflect.DeepEqual(s.events, expectedEvents) {
		t.Fatalf("unexpected lifecycle event sequence:\ngot:  %+v\nwant: %+v", s.events, expectedEvents)
	}
}

// AssertionTestSuite verifies direct and helper assertions provided by suite.Suite
type AssertionTestSuite struct {
	suite.Suite
}

func (s *AssertionTestSuite) TestDirectAssertions() {
	s.Equal(42, 42)
	s.NotEqual("apple", "banana")
	s.True(10 > 5)
	s.False(2+2 == 5)
	s.Nil(nil)
	s.NotNil(s.T())
	s.Len([]string{"a", "b", "c"}, 3)
	s.Contains("hello world", "world")
	s.ElementsMatch([]int{1, 2, 3}, []int{3, 1, 2})
	s.NoError(nil)
	s.Empty("")
	s.NotEmpty("content")

	assertHelper := s.Assert()
	if assertHelper == nil {
		s.T().Fatal("s.Assert() returned nil")
	}
	assertHelper.Equal("foo", "foo")

	reqHelper := s.Require()
	if reqHelper == nil {
		s.T().Fatal("s.Require() returned nil")
	}
	reqHelper.True(true)
}

func (s *AssertionTestSuite) TestSetTContextBinding() {
	originalT := s.T()
	s.NotNil(originalT)

	customT := new(testing.T)
	s.SetT(customT)
	s.Equal(customT, s.T())

	s.SetT(originalT)
	s.Equal(originalT, s.T())
}

func TestAssertionTestSuite(t *testing.T) {
	suite.Run(t, new(AssertionTestSuite))
}
csx.json
{"case":{"caseId":"case:sha256:582e0efb876810ff99ac7a4f7e90a5817b4eaa924fe0c0a4b46550fe0194231f","contract":["suite.Suite implements suite.TestingSuite interface providing T(), SetT(), and SetS()","suite.Run discovers and executes all exported Test methods on structs embedding suite.Suite","suite lifecycle hooks (SetupSuite, SetupTest, BeforeTest, AfterTest, TearDownTest, TearDownSuite) execute in deterministic order","s.Run executes hierarchical subtests with isolated test context and triggers SetupSubTest and TearDownSubTest hooks","embedded assertion and requirement helpers (s.Equal, s.True, s.NotNil, s.Require) operate on the active testing context"],"goal":"verify github.com/stretchr/testify/suite.Suite in pkg:golang/github.com/stretchr/testify@v1.11.1","kind":"HOW","packages":["pkg:golang/github.com/stretchr/testify@v1.11.1"],"schemaVersion":1,"symbols":["github.com/stretchr/testify/suite.Suite"]},"contractCommand":["go","test","-v","./..."],"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/stretchr/testify@v1.11.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/stretchr/testify@v1.11.1","symbols":["github.com/stretchr/testify/suite.Suite"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.22

require github.com/stretchr/testify v1.11.1

require (
	github.com/davecgh/go-spew v1.1.1 // indirect
	github.com/pmezard/go-difflib v1.0.0 // indirect
	gopkg.in/yaml.v3 v3.0.1 // indirect
)
go.sum
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/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/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
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.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/stretchr/testify/suite.Suite in pkg:golang/github.com/stretchr/testify@v1.11.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/stretchr/testify@v1.11.1"
  ],
  "symbols": [
    "github.com/stretchr/testify/suite.Suite"
  ]
}

Seeder d'origine

anonyme