CodeSampleX

示例

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

已验证示例 — golang github.com/stretchr/testify v1.11.1: suite.Suite. contract 在 go 1.26 · linux alpine/x64 · docker 上运行并通过: suite.Suite implements…

sha256:69581474d42bb34d77f88a55c2cee4735657641b68a28b9652a523feb45aeb92

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 linux 24 · ubuntu · glibc 2.39 x64 go

验证运行环境

环境 契约 阶段 运行日期
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

案例

HOW
目标
verify github.com/stretchr/testify/suite.Suite in pkg:golang/github.com/stretchr/testify@v1.11.1
包
符号
  • github.com/stretchr/testify/suite.Suite
创建时间
2026-08-23T06:12:28Z

契约

  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

文件

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

下载源代码构件 (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 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"
  ]
}

原始种子者

匿名