CodeSampleX

Exemplo

github.com/frankban/quicktest v1.14.6: PanicMatches

Amostra verificada para golang github.com/frankban/quicktest v1.14.6: PanicMatches. O contrato rodou em go 1.26 · linux debian/x64 · docker e passou.

sha256:4ac4e2c3f2fab262e86af9f8769f57879f57e7be82593aac103aacb3539121bf

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado linux 24 · ubuntu · glibc 2.39 x64 go

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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

Caso

HOW
Objetivo
verify github.com/frankban/quicktest.PanicMatches in pkg:golang/github.com/frankban/quicktest@v1.14.6
Pacotes
Símbolos
  • github.com/frankban/quicktest.PanicMatches
Criado
2026-09-06T18:42:46Z

Contrato

  1. qt.PanicMatches succeeds when a zero-argument function panics with a message matching a string pattern or regular expression
  2. qt.PanicMatches supports pre-compiled *regexp.Regexp pattern arguments
  3. qt.PanicMatches allows zero-argument functions that return values as long as they panic with a matching message
  4. qt.PanicMatches fails with a function did not panic error when the checked function terminates normally without panicking
  5. qt.PanicMatches fails with a panic value does not match regexp error when the panic message does not match the provided pattern
  6. qt.PanicMatches returns a bad check error when the first argument is not a function or when the function accepts arguments
  7. qt.PanicMatches returns a bad check error when the pattern argument is neither a string nor a compiled regular expression

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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/frankban/quicktest.PanicMatches in pkg:golang/github.com/frankban/quicktest@v1.14.6
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/frankban/quicktest@v1.14.6
Demonstrate these symbols/APIs:
  - github.com/frankban/quicktest.PanicMatches

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 (
	"fmt"
	"regexp"
	"strings"
	"testing"

	qt "github.com/frankban/quicktest"
)

// tbSpy captures Error and Fatal calls to verify assertion failure behavior without halting tests.
type tbSpy struct {
	testing.TB
	failed   bool
	fataled  bool
	errorBuf strings.Builder
	fatalBuf strings.Builder
}

func (s *tbSpy) Helper() {}

func (s *tbSpy) Error(args ...interface{}) {
	s.failed = true
	s.errorBuf.WriteString(fmt.Sprint(args...))
}

func (s *tbSpy) Fatal(args ...interface{}) {
	s.failed = true
	s.fataled = true
	s.fatalBuf.WriteString(fmt.Sprint(args...))
}

// Contract 1: qt.PanicMatches succeeds when a zero-argument function panics with a message matching a string pattern or regular expression
func TestPanicMatchesStringPattern(t *testing.T) {
	c := qt.New(t)

	// Exact string match
	c.Assert(func() {
		panic("connection lost: EOF")
	}, qt.PanicMatches, "connection lost: EOF")

	// Regex string match
	c.Assert(func() {
		panic("status code: 503 Service Unavailable")
	}, qt.PanicMatches, `status code: \d+ .*`)
}

// Contract 2: qt.PanicMatches supports pre-compiled *regexp.Regexp pattern arguments
func TestPanicMatchesCompiledRegexp(t *testing.T) {
	c := qt.New(t)

	compiled := regexp.MustCompile(`^(alpha|beta|gamma)-\d+$`)
	c.Assert(func() {
		panic("beta-42")
	}, qt.PanicMatches, compiled)
}

// Contract 3: qt.PanicMatches allows zero-argument functions that return values as long as they panic with a matching message
func TestPanicMatchesFuncWithReturn(t *testing.T) {
	c := qt.New(t)

	c.Assert(func() string {
		panic("returned function panicked")
	}, qt.PanicMatches, "returned function panicked")
}

// Contract 4: qt.PanicMatches fails with a function did not panic error when the checked function terminates normally without panicking
func TestPanicMatchesNoPanicFailure(t *testing.T) {
	spy := &tbSpy{TB: t}
	c := qt.New(spy)

	ok := c.Check(func() {
		// Normal completion without panic
	}, qt.PanicMatches, ".*")

	if ok {
		t.Fatal("expected c.Check to return false when checked function does not panic")
	}
	if !spy.failed {
		t.Fatal("expected TB.Error to be recorded on non-panicking function")
	}
	if !strings.Contains(spy.errorBuf.String(), "function did not panic") {
		t.Fatalf("expected error message to contain 'function did not panic', got: %s", spy.errorBuf.String())
	}
}

// Contract 5: qt.PanicMatches fails with a panic value does not match regexp error when the panic message does not match the provided pattern
func TestPanicMatchesMismatchFailure(t *testing.T) {
	spy := &tbSpy{TB: t}
	c := qt.New(spy)

	ok := c.Check(func() {
		panic("operation timed out")
	}, qt.PanicMatches, "^file not found$")

	if ok {
		t.Fatal("expected c.Check to return false on mismatched pattern")
	}
	if !spy.failed {
		t.Fatal("expected TB.Error to be recorded on pattern mismatch")
	}
	if !strings.Contains(spy.errorBuf.String(), "panic value does not match regexp") {
		t.Fatalf("expected error message to contain 'panic value does not match regexp', got: %s", spy.errorBuf.String())
	}
}

// Contract 6: qt.PanicMatches returns a bad check error when the first argument is not a function or when the function accepts arguments
func TestPanicMatchesInvalidFunctionArg(t *testing.T) {
	// Not a function
	spyNotFunc := &tbSpy{TB: t}
	cNotFunc := qt.New(spyNotFunc)
	ok := cNotFunc.Check("not-a-func", qt.PanicMatches, ".*")
	if ok || !spyNotFunc.failed {
		t.Fatal("expected failure when first argument is not a function")
	}
	if !strings.Contains(spyNotFunc.errorBuf.String(), "first argument is not a function") {
		t.Fatalf("expected 'first argument is not a function', got: %s", spyNotFunc.errorBuf.String())
	}

	// Function receiving arguments
	spyWithArgs := &tbSpy{TB: t}
	cWithArgs := qt.New(spyWithArgs)
	ok = cWithArgs.Check(func(code int) {
		panic("panic with code")
	}, qt.PanicMatches, ".*")
	if ok || !spyWithArgs.failed {
		t.Fatal("expected failure when function takes arguments")
	}
	if !strings.Contains(spyWithArgs.errorBuf.String(), "cannot use a function receiving arguments") {
		t.Fatalf("expected 'cannot use a function receiving arguments', got: %s", spyWithArgs.errorBuf.String())
	}
}

// Contract 7: qt.PanicMatches returns a bad check error when the pattern argument is neither a string nor a compiled regular expression
func TestPanicMatchesInvalidPatternArg(t *testing.T) {
	spy := &tbSpy{TB: t}
	c := qt.New(spy)

	ok := c.Check(func() {
		panic("some panic")
	}, qt.PanicMatches, 12345)

	if ok || !spy.failed {
		t.Fatal("expected failure when pattern argument is not a string or *regexp.Regexp")
	}
	if !strings.Contains(spy.errorBuf.String(), "regexp is not a string") {
		t.Fatalf("expected 'regexp is not a string', got: %s", spy.errorBuf.String())
	}
}
csx.json
{"case":{"caseId":"case:sha256:e37a1a8bf2683087957eeb9bdcbc36efcfd88c07d260b09327c0982d4413cc1c","contract":["qt.PanicMatches succeeds when a zero-argument function panics with a message matching a string pattern or regular expression","qt.PanicMatches supports pre-compiled *regexp.Regexp pattern arguments","qt.PanicMatches allows zero-argument functions that return values as long as they panic with a matching message","qt.PanicMatches fails with a function did not panic error when the checked function terminates normally without panicking","qt.PanicMatches fails with a panic value does not match regexp error when the panic message does not match the provided pattern","qt.PanicMatches returns a bad check error when the first argument is not a function or when the function accepts arguments","qt.PanicMatches returns a bad check error when the pattern argument is neither a string nor a compiled regular expression"],"goal":"verify github.com/frankban/quicktest.PanicMatches in pkg:golang/github.com/frankban/quicktest@v1.14.6","kind":"HOW","packages":["pkg:golang/github.com/frankban/quicktest@v1.14.6"],"schemaVersion":1,"symbols":["github.com/frankban/quicktest.PanicMatches"]},"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/frankban/quicktest@v1.14.6"],"schemaVersion":1,"subject":"pkg:golang/github.com/frankban/quicktest@v1.14.6","symbols":["github.com/frankban/quicktest.PanicMatches"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/frankban/quicktest v1.14.6

require (
	github.com/google/go-cmp v0.5.9 // indirect
	github.com/kr/pretty v0.3.1 // indirect
	github.com/kr/text v0.2.0 // indirect
	github.com/rogpeppe/go-internal v1.9.0 // indirect
)
go.sum
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/frankban/quicktest.PanicMatches in pkg:golang/github.com/frankban/quicktest@v1.14.6",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/frankban/quicktest@v1.14.6"
  ],
  "symbols": [
    "github.com/frankban/quicktest.PanicMatches"
  ]
}

Seeder de origem

anônimo