CodeSampleX

サンプル

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

検証済みサンプル — golang github.com/stretchr/testify v1.11.1: suite.Suite. go 1.26 · linux alpine/x64 · docker で contract を実行し、成功しました.

sha256:69581474d42bb34d77f88a55c2cee4735657641b68a28b9652a523feb45aeb92

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

オリジンシーダー

匿名