샘플
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c: check.ErrorMatches
검증된 샘플 — golang gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c: check.ErrorMatches. go 1.26 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다.
sha256:8cd64b1a1d4c59b4118070ae469183ae43b02dc2a620a6f6e700010f8fa37583
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
linux 24 · ubuntu · glibc 2.39 x64 go
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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-03 |
케이스
HOW- 목표
- verify pkg:golang/gopkg.in/check.v1@v1.0.0-20201130134442-10cb98267c6c
- 심벌
-
- check.ErrorMatches
- 생성일
- 2026-09-03T05:40:51Z
컨트랙트
- check.ErrorMatches verifies that a non-nil error matches an expected regular expression pattern
- check.ErrorMatches fails when the obtained error is nil or does not match the pattern
- check.ErrorMatches fails when the obtained value is not an error type
- check.ErrorMatches fails when the regular expression cannot be compiled
- check.ErrorMatches exposes CheckerInfo naming ErrorMatches with value and regex parameters
- check.ErrorMatches integrates with check.C Assert and Check to validate errors in test suites
파일
- PROMPT.md
- csx.json
- go.mod
- go.sum
- sample.go
- spec.json
- test/contract.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 pkg:golang/gopkg.in/check.v1@v1.0.0-20201130134442-10cb98267c6c
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/gopkg.in/check.v1@v1.0.0-20201130134442-10cb98267c6c
Demonstrate these symbols/APIs:
- check.ErrorMatches
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:00ef37c0042ddb3fd48aa662555d529597794e9d9805f7a4b4aa1d615ab95f87","contract":["check.ErrorMatches verifies that a non-nil error matches an expected regular expression pattern","check.ErrorMatches fails when the obtained error is nil or does not match the pattern","check.ErrorMatches fails when the obtained value is not an error type","check.ErrorMatches fails when the regular expression cannot be compiled","check.ErrorMatches exposes CheckerInfo naming ErrorMatches with value and regex parameters","check.ErrorMatches integrates with check.C Assert and Check to validate errors in test suites"],"goal":"verify pkg:golang/gopkg.in/check.v1@v1.0.0-20201130134442-10cb98267c6c","kind":"HOW","packages":["pkg:golang/gopkg.in/check.v1@v1.0.0-20201130134442-10cb98267c6c"],"schemaVersion":1,"symbols":["check.ErrorMatches"]},"contractCommand":["go","run","./test"],"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/gopkg.in/check.v1@v1.0.0-20201130134442-10cb98267c6c"],"schemaVersion":1,"subject":"pkg:golang/gopkg.in/check.v1@v1.0.0-20201130134442-10cb98267c6c","symbols":["check.ErrorMatches"],"verifierAdapter":"golang@1"}
module sample
go 1.26.6
require gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
require (
github.com/kr/pretty v0.2.1 // indirect
github.com/kr/text v0.1.0 // indirect
)
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
package sample
import (
"errors"
"fmt"
"strings"
"gopkg.in/check.v1"
)
// ConfigValidator validates system configuration parameters.
type ConfigValidator struct{}
// ValidateUsername checks username syntax and returns descriptive errors on failure.
func (v *ConfigValidator) ValidateUsername(username string) error {
if username == "" {
return errors.New("invalid username: username cannot be empty")
}
if len(username) < 3 {
return fmt.Errorf("invalid username: length %d is less than minimum 3", len(username))
}
if strings.Contains(username, " ") {
return errors.New("invalid username: contains forbidden whitespace")
}
return nil
}
// ValidatePort validates network port range.
func (v *ConfigValidator) ValidatePort(port int) error {
if port < 1 || port > 65535 {
return fmt.Errorf("invalid port: %d out of range [1, 65535]", port)
}
return nil
}
// ConfigValidatorSuite tests ConfigValidator using gopkg.in/check.v1 ErrorMatches.
type ConfigValidatorSuite struct {
Validator *ConfigValidator
}
// SetUpSuite initializes the test suite fixture.
func (s *ConfigValidatorSuite) SetUpSuite(c *check.C) {
s.Validator = &ConfigValidator{}
}
// TestEmptyUsername tests empty username validation error using check.ErrorMatches.
func (s *ConfigValidatorSuite) TestEmptyUsername(c *check.C) {
err := s.Validator.ValidateUsername("")
c.Assert(err, check.ErrorMatches, "invalid username:.*cannot be empty")
}
// TestShortUsername tests short username validation error using check.ErrorMatches.
func (s *ConfigValidatorSuite) TestShortUsername(c *check.C) {
err := s.Validator.ValidateUsername("ab")
c.Check(err, check.ErrorMatches, "invalid username: length [0-9]+ is less than minimum 3")
}
// TestWhitespaceUsername tests whitespace error using check.ErrorMatches.
func (s *ConfigValidatorSuite) TestWhitespaceUsername(c *check.C) {
err := s.Validator.ValidateUsername("user name")
c.Assert(err, check.ErrorMatches, "invalid username: contains forbidden whitespace")
}
// TestInvalidPort tests port range validation error using check.ErrorMatches.
func (s *ConfigValidatorSuite) TestInvalidPort(c *check.C) {
err := s.Validator.ValidatePort(70000)
c.Assert(err, check.ErrorMatches, "invalid port: [0-9]+ out of range .*")
}
{
"schemaVersion": 1,
"goal": "verify pkg:golang/gopkg.in/check.v1@v1.0.0-20201130134442-10cb98267c6c",
"kind": "HOW",
"packages": [
"pkg:golang/gopkg.in/check.v1@v1.0.0-20201130134442-10cb98267c6c"
],
"symbols": [
"check.ErrorMatches"
]
}
package main
import (
"errors"
"fmt"
"os"
"gopkg.in/check.v1"
"sample"
)
func main() {
// 1. check.ErrorMatches verifies that a non-nil error matches an expected regular expression pattern
testErr := errors.New("connection failed: timeout after 5000ms")
matched, errStr := check.ErrorMatches.Check([]interface{}{testErr, "connection failed: timeout after [0-9]+ms"}, []string{"value", "regex"})
if !matched || errStr != "" {
fmt.Fprintf(os.Stderr, "ErrorMatches failed on matching error: %s\n", errStr)
os.Exit(1)
}
// 2. check.ErrorMatches fails when the obtained error is nil or does not match the pattern
nilMatched, nilErrStr := check.ErrorMatches.Check([]interface{}{nil, ".*"}, []string{"value", "regex"})
if nilMatched || nilErrStr != "Error value is nil" {
fmt.Fprintf(os.Stderr, "ErrorMatches should fail on nil error, got matched=%v err=%s\n", nilMatched, nilErrStr)
os.Exit(1)
}
mismatchMatched, mismatchErrStr := check.ErrorMatches.Check([]interface{}{testErr, "^completely different error$"}, []string{"value", "regex"})
if mismatchMatched || mismatchErrStr != "" {
fmt.Fprintf(os.Stderr, "ErrorMatches should not match differing pattern, got matched=%v\n", mismatchMatched)
os.Exit(1)
}
// 3. check.ErrorMatches fails when the obtained value is not an error type
nonErrorMatched, nonErrorErrStr := check.ErrorMatches.Check([]interface{}{"not an error string", ".*"}, []string{"value", "regex"})
if nonErrorMatched || nonErrorErrStr != "Value is not an error" {
fmt.Fprintf(os.Stderr, "ErrorMatches should fail when value is not an error, got matched=%v err=%s\n", nonErrorMatched, nonErrorErrStr)
os.Exit(1)
}
// 4. check.ErrorMatches fails when the regular expression cannot be compiled
badRegexMatched, badRegexErrStr := check.ErrorMatches.Check([]interface{}{testErr, "[invalid(regex"}, []string{"value", "regex"})
if badRegexMatched || badRegexErrStr == "" {
fmt.Fprintf(os.Stderr, "ErrorMatches should fail on malformed regex, got matched=%v err=%s\n", badRegexMatched, badRegexErrStr)
os.Exit(1)
}
// 5. check.ErrorMatches exposes CheckerInfo naming ErrorMatches with value and regex parameters
info := check.ErrorMatches.Info()
if info == nil {
fmt.Fprintf(os.Stderr, "expected non-nil CheckerInfo from ErrorMatches\n")
os.Exit(1)
}
if info.Name != "ErrorMatches" {
fmt.Fprintf(os.Stderr, "expected checker name ErrorMatches, got %s\n", info.Name)
os.Exit(1)
}
if len(info.Params) != 2 || info.Params[0] != "value" || info.Params[1] != "regex" {
fmt.Fprintf(os.Stderr, "unexpected params in CheckerInfo: %v\n", info.Params)
os.Exit(1)
}
// 6. check.ErrorMatches integrates with check.C Assert and Check to validate errors in test suites
suite := &sample.ConfigValidatorSuite{}
check.Suite(suite)
result := check.Run(suite, &check.RunConf{})
if result == nil {
fmt.Fprintf(os.Stderr, "expected non-nil run result\n")
os.Exit(1)
}
if !result.Passed() {
fmt.Fprintf(os.Stderr, "suite run failed: %s\n", result.String())
os.Exit(1)
}
if result.Succeeded < 4 {
fmt.Fprintf(os.Stderr, "expected at least 4 succeeded tests, got %d\n", result.Succeeded)
os.Exit(1)
}
fmt.Println("All gopkg.in/check.v1 ErrorMatches contract assertions passed.")
}
오리진 시더
익명