샘플
github.com/stretchr/testify v1.7.0: suite
검증된 샘플 — golang github.com/stretchr/testify v1.7.0: suite. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: suite.Run executes all exported test…
sha256:762956c30783c5e0bac92d690c4a636c8989249b6547bec977049ef8464e0e5f
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
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 suite in pkg:golang/github.com/stretchr/testify@v1.7.0
- 심벌
-
- suite
- 환경
- go 1.26.6
- 생성일
- 2026-09-06T06:09:35Z
컨트랙트
- suite.Run executes all exported test methods on the suite whose names begin with Test
- suite executes SetupSuite once before any tests run and TearDownSuite once after all tests complete
- suite executes SetupTest and BeforeTest before each test method and AfterTest and TearDownTest after each test method in order
- suite.Suite provides embedded assertions and Require provides fail-now assertions bound to the active test context
- suite.Run method enables nested subtest execution with fresh child test contexts
- suite implementing WithStats receives completed SuiteInformation with valid timings and test results via HandleStats
파일
- 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 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:
- 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:5e4acec195913b9cffb3d22369d4cb60947912da611c60cb87d3f8a61e984b3c","contract":["suite.Run executes all exported test methods on the suite whose names begin with Test","suite executes SetupSuite once before any tests run and TearDownSuite once after all tests complete","suite executes SetupTest and BeforeTest before each test method and AfterTest and TearDownTest after each test method in order","suite.Suite provides embedded assertions and Require provides fail-now assertions bound to the active test context","suite.Run method enables nested subtest execution with fresh child test contexts","suite implementing WithStats receives completed SuiteInformation with valid timings and test results via HandleStats"],"goal":"verify 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":["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":["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"
)
// ItemRepository defines operations on an in-memory item set.
type ItemRepository struct {
items map[string]int
}
// NewItemRepository initializes a repository with empty state.
func NewItemRepository() *ItemRepository {
return &ItemRepository{
items: make(map[string]int),
}
}
// Set adds or updates an item count.
func (r *ItemRepository) Set(name string, count int) {
r.items[name] = count
}
// Get retrieves an item count.
func (r *ItemRepository) Get(name string) (int, bool) {
val, ok := r.items[name]
return val, ok
}
// ItemRepositorySuite demonstrates using testify/suite to test ItemRepository.
type ItemRepositorySuite struct {
suite.Suite
repo *ItemRepository
}
// SetupTest prepares fresh state before each test.
func (s *ItemRepositorySuite) SetupTest() {
s.repo = NewItemRepository()
}
// TestSetAndGet verifies that stored values can be accurately retrieved.
func (s *ItemRepositorySuite) TestSetAndGet() {
s.repo.Set("widget", 42)
val, ok := s.repo.Get("widget")
s.True(ok)
s.Equal(42, val)
}
func main() {
repo := NewItemRepository()
repo.Set("example", 1)
val, _ := repo.Get("example")
fmt.Printf("Item repository initialized with %d item(s)\n", val)
}
{
"schemaVersion": 1,
"goal": "verify suite in pkg:golang/github.com/stretchr/testify@v1.7.0",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/stretchr/testify@v1.7.0"
],
"symbols": [
"suite"
]
}
package test
import (
"fmt"
"testing"
"github.com/stretchr/testify/suite"
)
// DiscoverySuite verifies method discovery and exclusion of non-test methods.
type DiscoverySuite struct {
suite.Suite
testOneRun bool
testTwoRun bool
helperRun bool
}
func (s *DiscoverySuite) TestOne() {
s.testOneRun = true
}
func (s *DiscoverySuite) TestTwo() {
s.testTwoRun = true
}
func (s *DiscoverySuite) HelperMethod() {
s.helperRun = true
}
// SuiteLifecycleSuite verifies SetupSuite and TearDownSuite invocation counts.
type SuiteLifecycleSuite struct {
suite.Suite
setupSuiteCount int
tearDownSuiteCount int
testsRun int
}
func (s *SuiteLifecycleSuite) SetupSuite() {
s.setupSuiteCount++
}
func (s *SuiteLifecycleSuite) TestAlpha() {
s.testsRun++
}
func (s *SuiteLifecycleSuite) TestBeta() {
s.testsRun++
}
func (s *SuiteLifecycleSuite) TearDownSuite() {
s.tearDownSuiteCount++
}
// MethodLifecycleSuite verifies per-test setup and teardown ordering.
type MethodLifecycleSuite struct {
suite.Suite
eventLog []string
}
func (s *MethodLifecycleSuite) SetupTest() {
s.eventLog = append(s.eventLog, "SetupTest")
}
func (s *MethodLifecycleSuite) BeforeTest(suiteName, testName string) {
s.eventLog = append(s.eventLog, fmt.Sprintf("BeforeTest:%s:%s", suiteName, testName))
}
func (s *MethodLifecycleSuite) TestFirst() {
s.eventLog = append(s.eventLog, "TestFirst")
}
func (s *MethodLifecycleSuite) TestSecond() {
s.eventLog = append(s.eventLog, "TestSecond")
}
func (s *MethodLifecycleSuite) AfterTest(suiteName, testName string) {
s.eventLog = append(s.eventLog, fmt.Sprintf("AfterTest:%s:%s", suiteName, testName))
}
func (s *MethodLifecycleSuite) TearDownTest() {
s.eventLog = append(s.eventLog, "TearDownTest")
}
// AssertionsBindingSuite verifies embedded assert methods and Require accessors.
type AssertionsBindingSuite struct {
suite.Suite
assertionsPassed bool
}
func (s *AssertionsBindingSuite) TestAssertions() {
if s.T() == nil {
return
}
s.Equal(100, 100)
s.True(true)
s.False(false)
s.NoError(nil)
req := s.Require()
if req == nil {
return
}
req.Equal("alpha", "alpha")
req.NotNil(s.T())
as := s.Assert()
if as == nil {
return
}
as.Equal(200, 200)
s.assertionsPassed = true
}
// SubtestExecutionSuite verifies nested subtest execution context management.
type SubtestExecutionSuite struct {
suite.Suite
subtestExecuted bool
parentContext *testing.T
childContext *testing.T
restoredContext *testing.T
}
func (s *SubtestExecutionSuite) TestSubtest() {
s.parentContext = s.T()
s.Run("child_subtest", func() {
s.childContext = s.T()
s.subtestExecuted = true
})
s.restoredContext = s.T()
}
// WithStatsSuite verifies WithStats interface implementation.
type WithStatsSuite struct {
suite.Suite
statsHandled bool
suiteName string
statsValid bool
}
func (s *WithStatsSuite) TestExecution() {
s.Equal("hello", "hello")
}
func (s *WithStatsSuite) HandleStats(suiteName string, stats *suite.SuiteInformation) {
s.statsHandled = true
s.suiteName = suiteName
if stats != nil && !stats.Start.IsZero() && !stats.End.IsZero() && stats.Passed() {
if testStat, exists := stats.TestStats["TestExecution"]; exists && testStat.Passed {
s.statsValid = true
}
}
}
func TestContract(t *testing.T) {
// Assertion 1: suite.Run executes all exported test methods on the suite whose names begin with Test
{
s := new(DiscoverySuite)
suite.Run(t, s)
if !s.testOneRun || !s.testTwoRun || s.helperRun {
t.Fatalf("assertion 1 failed: suite.Run did not execute expected Test methods or invoked non-Test method")
}
}
// Assertion 2: suite executes SetupSuite once before any tests run and TearDownSuite once after all tests complete
{
s := new(SuiteLifecycleSuite)
suite.Run(t, s)
if s.setupSuiteCount != 1 || s.tearDownSuiteCount != 1 || s.testsRun != 2 {
t.Fatalf("assertion 2 failed: SetupSuite and TearDownSuite call count mismatch")
}
}
// Assertion 3: suite executes SetupTest and BeforeTest before each test method and AfterTest and TearDownTest after each test method in order
{
s := new(MethodLifecycleSuite)
suite.Run(t, s)
expected := []string{
"SetupTest",
"BeforeTest:MethodLifecycleSuite:TestFirst",
"TestFirst",
"AfterTest:MethodLifecycleSuite:TestFirst",
"TearDownTest",
"SetupTest",
"BeforeTest:MethodLifecycleSuite:TestSecond",
"TestSecond",
"AfterTest:MethodLifecycleSuite:TestSecond",
"TearDownTest",
}
if len(s.eventLog) != len(expected) {
t.Fatalf("assertion 3 failed: event log length mismatch (%d vs %d)", len(s.eventLog), len(expected))
}
for i, exp := range expected {
if s.eventLog[i] != exp {
t.Fatalf("assertion 3 failed: step %d expected %s, got %s", i, exp, s.eventLog[i])
}
}
}
// Assertion 4: suite.Suite provides embedded assertions and Require provides fail-now assertions bound to the active test context
{
s := new(AssertionsBindingSuite)
suite.Run(t, s)
if !s.assertionsPassed {
t.Fatalf("assertion 4 failed: embedded assertions or Require did not pass")
}
}
// Assertion 5: suite.Run method enables nested subtest execution with fresh child test contexts
{
s := new(SubtestExecutionSuite)
suite.Run(t, s)
if !s.subtestExecuted || s.childContext == nil || s.childContext == s.parentContext || s.restoredContext != s.parentContext {
t.Fatalf("assertion 5 failed: subtest execution context handling mismatch")
}
}
// Assertion 6: suite implementing WithStats receives completed SuiteInformation with valid timings and test results via HandleStats
{
s := new(WithStatsSuite)
suite.Run(t, s)
if !s.statsHandled || s.suiteName != "WithStatsSuite" || !s.statsValid {
t.Fatalf("assertion 6 failed: WithStats HandleStats was not invoked with expected SuiteInformation")
}
}
}
오리진 시더
익명