Documentation
¶
Overview ¶
Package sztest provides a self-contained test helper library built entirely on the Go standard library. It is designed to make tests cleaner, more readable, and more reliable, while offering features that go beyond the default testing framework.
Core features include:
- Uniform assertions across all built-in types, with consistent reporting.
- Automatic diffs on failure, rendered with ANSI colors for clarity. Diff behavior is configurable, including character- and line-window sizes.
- Flow control with FailFast, allowing tests to stop on the first error or continue gathering results.
- String helpers (Str, Strf) for concise assertions on string values.
- Support for slice comparisons and interval checks (bounded and unbounded).
- Error and panic assertions for verifying expected failures.
- Output capture of stdout, stderr, and package logs, with diffs against expected results.
- Temporary resource and environment variable helpers to isolate tests.
- I/O interface shims (io.Reader, io.Writer, io.Seeker, io.Closer) for simulating success and failure modes in code under test.
- Clock utilities to capture and format test timestamps in multiple layouts.
- Full integration with testing.T through a minimal internal interface, enabling sztest to be tested itself with complete coverage.
- The library executes with negligible overhead making it practical for continuous test driven development without breaking flow.
The library emphasizes a minimal usage pattern:
chk := sztest.CaptureNothing(t) defer chk.Release() chk.Str(got, wnt)
By keeping the API uniform and predictable, sztest helps reduce boilerplate and highlight only what matters in a test: the behavior being verified.
---
## Dedication
This project is dedicated to Reem. Your brilliance, courage, and quiet strength continue to inspire me. Every line is written in gratitude for the light and hope you brought into my life.
---
NOTE: Documentation reviewed and polished with the assistance of ChatGPT from OpenAI.
Index ¶
- Constants
- Variables
- func IsFloat32Similar(num1, num2, tolerance float32) bool
- func IsFloat64Similar(num1, num2, tolerance float64) bool
- func ReloadSettings()
- func SettingBufferSize() int
- func SettingDiffChars() int
- func SettingDiffSlice() int
- func SettingFailFast() bool
- func SettingMarkChgOff() string
- func SettingMarkChgOn() string
- func SettingMarkDelOff() string
- func SettingMarkDelOn() string
- func SettingMarkGotOff() string
- func SettingMarkGotOn() string
- func SettingMarkInsOff() string
- func SettingMarkInsOn() string
- func SettingMarkMsgOff() string
- func SettingMarkMsgOn() string
- func SettingMarkSepOff() string
- func SettingMarkSepOn() string
- func SettingMarkWntOff() string
- func SettingMarkWntOn() string
- func SettingPermDir() os.FileMode
- func SettingPermExe() os.FileMode
- func SettingPermFile() os.FileMode
- func SettingTmpDir() string
- type BoundedOption
- type Chk
- func CaptureLog(t testingT) *Chk
- func CaptureLogAndStderr(t testingT) *Chk
- func CaptureLogAndStderrAndStdout(t testingT) *Chk
- func CaptureLogAndStdout(t testingT) *Chk
- func CaptureLogWithStderr(t testingT) *Chk
- func CaptureLogWithStderrAndStdout(t testingT) *Chk
- func CaptureNothing(t testingT) *Chk
- func CaptureStderr(t testingT) *Chk
- func CaptureStderrAndStdout(t testingT) *Chk
- func CaptureStdout(t testingT) *Chk
- func (chk *Chk) AddSub(expr, subStr string)
- func (chk *Chk) Bool(got, want bool, msg ...any) bool
- func (chk *Chk) BoolSlice(got, want []bool, msg ...any) bool
- func (chk *Chk) BoolSlicef(got, want []bool, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Boolf(got, want bool, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Byte(got, want byte, msg ...any) bool
- func (chk *Chk) ByteBounded(got byte, option BoundedOption, minV, maxV byte, msg ...any) bool
- func (chk *Chk) ByteBoundedf(got byte, option BoundedOption, minV, maxV byte, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) ByteSlice(got, want []byte, msg ...any) bool
- func (chk *Chk) ByteSlicef(got, want []byte, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) ByteUnbounded(got byte, option UnboundedOption, bound byte, msg ...any) bool
- func (chk *Chk) ByteUnboundedf(got byte, option UnboundedOption, bound byte, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Bytef(got, want byte, msgFmt string, msgArgs ...any) bool
- func (*Chk) CaptureFlagUsage(flagSet *flag.FlagSet) string
- func (chk *Chk) ClockAddSub(clkFmt ClkFmt)
- func (chk *Chk) ClockLast() time.Time
- func (chk *Chk) ClockLastFmtCusA() string
- func (chk *Chk) ClockLastFmtCusB() string
- func (chk *Chk) ClockLastFmtCusC() string
- func (chk *Chk) ClockLastFmtDate() string
- func (chk *Chk) ClockLastFmtNano() string
- func (chk *Chk) ClockLastFmtTS() string
- func (chk *Chk) ClockLastFmtTime() string
- func (chk *Chk) ClockNext() time.Time
- func (chk *Chk) ClockNextFmtCusA() string
- func (chk *Chk) ClockNextFmtCusB() string
- func (chk *Chk) ClockNextFmtCusC() string
- func (chk *Chk) ClockNextFmtDate() string
- func (chk *Chk) ClockNextFmtNano() string
- func (chk *Chk) ClockNextFmtTS() string
- func (chk *Chk) ClockNextFmtTime() string
- func (chk *Chk) ClockOffset(d time.Duration, inc ...time.Duration) func()
- func (chk *Chk) ClockOffsetDay(dayOffset int, inc ...time.Duration) func()
- func (chk *Chk) ClockRemoveSub(clkFmt ClkFmt)
- func (chk *Chk) ClockSet(newTime time.Time, inc ...time.Duration) func()
- func (chk *Chk) ClockSetCusA(f string)
- func (chk *Chk) ClockSetCusB(f string)
- func (chk *Chk) ClockSetCusC(f string)
- func (chk *Chk) ClockSetSub(clkFmt ClkFmt)
- func (chk *Chk) ClockTick(i int) time.Time
- func (chk *Chk) Close() error
- func (chk *Chk) Complex64(got, want complex64, msg ...any) bool
- func (chk *Chk) Complex64Slice(got, want []complex64, msg ...any) bool
- func (chk *Chk) Complex64Slicef(got, want []complex64, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Complex64f(got, want complex64, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Complex128(got, want complex128, msg ...any) bool
- func (chk *Chk) Complex128Slice(got, want []complex128, msg ...any) bool
- func (chk *Chk) Complex128Slicef(got, want []complex128, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Complex128f(got, want complex128, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) CreateTmpDir() string
- func (chk *Chk) CreateTmpFile(data []byte) string
- func (chk *Chk) CreateTmpFileAs(path, fName string, data []byte) string
- func (chk *Chk) CreateTmpFileIn(path string, data []byte) string
- func (chk *Chk) CreateTmpSubDir(subDirs ...string) string
- func (chk *Chk) CreateTmpUnixScript(lines []string) string
- func (chk *Chk) CreateTmpUnixScriptAs(path, fName string, lines []string) string
- func (chk *Chk) CreateTmpUnixScriptIn(path string, lines []string) string
- func (chk *Chk) DelEnv(name string)
- func (chk *Chk) Dur(got, want time.Duration, msg ...any) bool
- func (chk *Chk) DurBounded(got time.Duration, option BoundedOption, minV, maxV time.Duration, msg ...any) bool
- func (chk *Chk) DurBoundedf(got time.Duration, option BoundedOption, minV, maxV time.Duration, ...) bool
- func (chk *Chk) DurSlice(got, want []time.Duration, msg ...any) bool
- func (chk *Chk) DurSlicef(got, want []time.Duration, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) DurUnbounded(got time.Duration, option UnboundedOption, bound time.Duration, msg ...any) bool
- func (chk *Chk) DurUnboundedf(got time.Duration, option UnboundedOption, bound time.Duration, msgFmt string, ...) bool
- func (chk *Chk) Durf(got, want time.Duration, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Err(got error, want string, msg ...any) bool
- func (chk *Chk) ErrChain(first any, rest ...any) string
- func (chk *Chk) ErrSlice(got []error, want []string, msg ...any) bool
- func (chk *Chk) ErrSlicef(got []error, want []string, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Errf(got error, want string, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Error(args ...any)
- func (chk *Chk) Errorf(msgFmt string, msgArgs ...any)
- func (chk *Chk) FailFast(failFast bool) bool
- func (chk *Chk) False(got bool, msg ...any) bool
- func (chk *Chk) Falsef(got bool, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Fatalf(msgFmt string, msgArgs ...any)
- func (chk *Chk) Float32(got, want, tolerance float32, msg ...any) bool
- func (chk *Chk) Float32Bounded(got float32, option BoundedOption, minV, maxV float32, msg ...any) bool
- func (chk *Chk) Float32Boundedf(got float32, option BoundedOption, minV, maxV float32, msgFmt string, ...) bool
- func (chk *Chk) Float32Slice(got, want []float32, tolerance float32, msg ...any) bool
- func (chk *Chk) Float32Slicef(got, want []float32, tolerance float32, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Float32Unbounded(got float32, option UnboundedOption, bound float32, msg ...any) bool
- func (chk *Chk) Float32Unboundedf(got float32, option UnboundedOption, bound float32, msgFmt string, ...) bool
- func (chk *Chk) Float32f(got, want, tolerance float32, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Float64(got, want, tolerance float64, msg ...any) bool
- func (chk *Chk) Float64Bounded(got float64, option BoundedOption, minV, maxV float64, msg ...any) bool
- func (chk *Chk) Float64Boundedf(got float64, option BoundedOption, minV, maxV float64, msgFmt string, ...) bool
- func (chk *Chk) Float64Slice(got, want []float64, tolerance float64, msg ...any) bool
- func (chk *Chk) Float64Slicef(got, want []float64, tolerance float64, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Float64Unbounded(got float64, option UnboundedOption, bound float64, msg ...any) bool
- func (chk *Chk) Float64Unboundedf(got float64, option UnboundedOption, bound float64, msgFmt string, ...) bool
- func (chk *Chk) Float64f(got, want, tolerance float64, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) GetIOWriterData() []byte
- func (chk *Chk) Int(got, want int, msg ...any) bool
- func (chk *Chk) Int8(got, want int8, msg ...any) bool
- func (chk *Chk) Int8Bounded(got int8, option BoundedOption, minV, maxV int8, msg ...any) bool
- func (chk *Chk) Int8Boundedf(got int8, option BoundedOption, minV, maxV int8, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Int8Slice(got, want []int8, msg ...any) bool
- func (chk *Chk) Int8Slicef(got, want []int8, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Int8Unbounded(got int8, option UnboundedOption, bound int8, msg ...any) bool
- func (chk *Chk) Int8Unboundedf(got int8, option UnboundedOption, bound int8, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Int8f(got, want int8, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Int16(got, want int16, msg ...any) bool
- func (chk *Chk) Int16Bounded(got int16, option BoundedOption, minV, maxV int16, msg ...any) bool
- func (chk *Chk) Int16Boundedf(got int16, option BoundedOption, minV, maxV int16, msgFmt string, ...) bool
- func (chk *Chk) Int16Slice(got, want []int16, msg ...any) bool
- func (chk *Chk) Int16Slicef(got, want []int16, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Int16Unbounded(got int16, option UnboundedOption, bound int16, msg ...any) bool
- func (chk *Chk) Int16Unboundedf(got int16, option UnboundedOption, bound int16, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Int16f(got, want int16, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Int32(got, want int32, msg ...any) bool
- func (chk *Chk) Int32Bounded(got int32, option BoundedOption, minV, maxV int32, msg ...any) bool
- func (chk *Chk) Int32Boundedf(got int32, option BoundedOption, minV, maxV int32, msgFmt string, ...) bool
- func (chk *Chk) Int32Slice(got, want []int32, msg ...any) bool
- func (chk *Chk) Int32Slicef(got, want []int32, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Int32Unbounded(got int32, option UnboundedOption, bound int32, msg ...any) bool
- func (chk *Chk) Int32Unboundedf(got int32, option UnboundedOption, bound int32, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Int32f(got, want int32, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Int64(got, want int64, msg ...any) bool
- func (chk *Chk) Int64Bounded(got int64, option BoundedOption, minV, maxV int64, msg ...any) bool
- func (chk *Chk) Int64Boundedf(got int64, option BoundedOption, minV, maxV int64, msgFmt string, ...) bool
- func (chk *Chk) Int64Slice(got, want []int64, msg ...any) bool
- func (chk *Chk) Int64Slicef(got, want []int64, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Int64Unbounded(got int64, option UnboundedOption, bound int64, msg ...any) bool
- func (chk *Chk) Int64Unboundedf(got int64, option UnboundedOption, bound int64, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Int64f(got, want int64, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) IntBounded(got int, option BoundedOption, minV, maxV int, msg ...any) bool
- func (chk *Chk) IntBoundedf(got int, option BoundedOption, minV, maxV int, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) IntSlice(got, want []int, msg ...any) bool
- func (chk *Chk) IntSlicef(got, want []int, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) IntUnbounded(got int, option UnboundedOption, bound int, msg ...any) bool
- func (chk *Chk) IntUnboundedf(got int, option UnboundedOption, bound int, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Intf(got, want int, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) KeepTmpFiles()
- func (*Chk) LastErr(args ...any) error
- func (chk *Chk) Log(wantLines ...string) bool
- func (chk *Chk) Logf(msgFmt string, msgArgs ...any)
- func (chk *Chk) Name() string
- func (chk *Chk) Nil(got any, msg ...any) bool
- func (chk *Chk) Nilf(got any, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) NoErr(got error, msg ...any) bool
- func (chk *Chk) NoErrf(got error, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) NoPanic(gotF func(), msg ...any) bool
- func (chk *Chk) NoPanicf(gotF func(), msgFmt string, msgArgs ...any) bool
- func (chk *Chk) NotNil(got any, msg ...any) bool
- func (chk *Chk) NotNilf(got any, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Panic(gotF func(), want string, msg ...any) bool
- func (chk *Chk) Panicf(gotF func(), want string, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) PushPostReleaseFunc(newFunc func() error)
- func (chk *Chk) PushPreReleaseFunc(newFunc func() error)
- func (chk *Chk) Read(dataBuf []byte) (int, error)
- func (chk *Chk) Release()
- func (chk *Chk) Rune(got, want rune, msg ...any) bool
- func (chk *Chk) RuneBounded(got rune, option BoundedOption, minV, maxV rune, msg ...any) bool
- func (chk *Chk) RuneBoundedf(got rune, option BoundedOption, minV, maxV rune, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) RuneSlice(got, want []rune, msg ...any) bool
- func (chk *Chk) RuneSlicef(got, want []rune, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) RuneUnbounded(got rune, option UnboundedOption, bound rune, msg ...any) bool
- func (chk *Chk) RuneUnboundedf(got rune, option UnboundedOption, bound rune, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Runef(got, want rune, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Seek(_ int64, _ int) (int64, error)
- func (chk *Chk) SetArgs(progName string, args ...string)
- func (chk *Chk) SetCloseError(err error)
- func (chk *Chk) SetEnv(name, value string)
- func (chk *Chk) SetIOReaderData(d ...string)
- func (chk *Chk) SetIOReaderError(byteCount int, err error)
- func (chk *Chk) SetIOWriterError(n int, err error)
- func (chk *Chk) SetPermDir(p os.FileMode) os.FileMode
- func (chk *Chk) SetPermExe(p os.FileMode) os.FileMode
- func (chk *Chk) SetPermFile(p os.FileMode) os.FileMode
- func (chk *Chk) SetReadError(pos int, err error)
- func (chk *Chk) SetSeekError(pos int64, err error)
- func (chk *Chk) SetStdinData(lines ...string)
- func (chk *Chk) SetTmpDir(dir string) string
- func (chk *Chk) SetWriteError(pos int, err error)
- func (chk *Chk) Stderr(wantLines ...string) bool
- func (chk *Chk) Stdout(wantLines ...string) bool
- func (chk *Chk) Str(got, want string, msg ...any) bool
- func (chk *Chk) StrBounded(got string, option BoundedOption, minV, maxV string, msg ...any) bool
- func (chk *Chk) StrBoundedf(got string, option BoundedOption, minV, maxV string, msgFmt string, ...) bool
- func (chk *Chk) StrSlice(got, want []string, msg ...any) bool
- func (chk *Chk) StrSlicef(got, want []string, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) StrUnbounded(got string, option UnboundedOption, bound string, msg ...any) bool
- func (chk *Chk) StrUnboundedf(got string, option UnboundedOption, bound string, msgFmt string, ...) bool
- func (chk *Chk) Strf(got, want string, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) T() testingT
- func (chk *Chk) TrimAll(str string) string
- func (chk *Chk) True(got bool, msg ...any) bool
- func (chk *Chk) Truef(got bool, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Uint(got, want uint, msg ...any) bool
- func (chk *Chk) Uint8(got, want uint8, msg ...any) bool
- func (chk *Chk) Uint8Bounded(got uint8, option BoundedOption, minV, maxV uint8, msg ...any) bool
- func (chk *Chk) Uint8Boundedf(got uint8, option BoundedOption, minV, maxV uint8, msgFmt string, ...) bool
- func (chk *Chk) Uint8Slice(got, want []uint8, msg ...any) bool
- func (chk *Chk) Uint8Slicef(got, want []uint8, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Uint8Unbounded(got uint8, option UnboundedOption, bound uint8, msg ...any) bool
- func (chk *Chk) Uint8Unboundedf(got uint8, option UnboundedOption, bound uint8, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Uint8f(got, want uint8, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Uint16(got, want uint16, msg ...any) bool
- func (chk *Chk) Uint16Bounded(got uint16, option BoundedOption, minV, maxV uint16, msg ...any) bool
- func (chk *Chk) Uint16Boundedf(got uint16, option BoundedOption, minV, maxV uint16, msgFmt string, ...) bool
- func (chk *Chk) Uint16Slice(got, want []uint16, msg ...any) bool
- func (chk *Chk) Uint16Slicef(got, want []uint16, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Uint16Unbounded(got uint16, option UnboundedOption, bound uint16, msg ...any) bool
- func (chk *Chk) Uint16Unboundedf(got uint16, option UnboundedOption, bound uint16, msgFmt string, ...) bool
- func (chk *Chk) Uint16f(got, want uint16, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Uint32(got, want uint32, msg ...any) bool
- func (chk *Chk) Uint32Bounded(got uint32, option BoundedOption, minV, maxV uint32, msg ...any) bool
- func (chk *Chk) Uint32Boundedf(got uint32, option BoundedOption, minV, maxV uint32, msgFmt string, ...) bool
- func (chk *Chk) Uint32Slice(got, want []uint32, msg ...any) bool
- func (chk *Chk) Uint32Slicef(got, want []uint32, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Uint32Unbounded(got uint32, option UnboundedOption, bound uint32, msg ...any) bool
- func (chk *Chk) Uint32Unboundedf(got uint32, option UnboundedOption, bound uint32, msgFmt string, ...) bool
- func (chk *Chk) Uint32f(got, want uint32, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Uint64(got, want uint64, msg ...any) bool
- func (chk *Chk) Uint64Bounded(got uint64, option BoundedOption, minV, maxV uint64, msg ...any) bool
- func (chk *Chk) Uint64Boundedf(got uint64, option BoundedOption, minV, maxV uint64, msgFmt string, ...) bool
- func (chk *Chk) Uint64Slice(got, want []uint64, msg ...any) bool
- func (chk *Chk) Uint64Slicef(got, want []uint64, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Uint64Unbounded(got uint64, option UnboundedOption, bound uint64, msg ...any) bool
- func (chk *Chk) Uint64Unboundedf(got uint64, option UnboundedOption, bound uint64, msgFmt string, ...) bool
- func (chk *Chk) Uint64f(got, want uint64, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) UintBounded(got uint, option BoundedOption, minV, maxV uint, msg ...any) bool
- func (chk *Chk) UintBoundedf(got uint, option BoundedOption, minV, maxV uint, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) UintSlice(got, want []uint, msg ...any) bool
- func (chk *Chk) UintSlicef(got, want []uint, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) UintUnbounded(got uint, option UnboundedOption, bound uint, msg ...any) bool
- func (chk *Chk) UintUnboundedf(got uint, option UnboundedOption, bound uint, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Uintf(got, want uint, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Uintptr(got, want uintptr, msg ...any) bool
- func (chk *Chk) UintptrSlice(got, want []uintptr, msg ...any) bool
- func (chk *Chk) UintptrSlicef(got, want []uintptr, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Uintptrf(got, want uintptr, msgFmt string, msgArgs ...any) bool
- func (chk *Chk) Write(data []byte) (int, error)
- type ClkFmt
- type UnboundedOption
Constants ¶
const ( EnvFailFast = "SZTEST_FAIL_FAST" EnvBufferSize = "SZTEST_BUFFER_SIZE" EnvPermDir = "SZTEST_PERM_DIR" EnvPermFile = "SZTEST_PERM_FILE" EnvPermExe = "SZTEST_PERM_EXE" EnvTmpDir = "SZTEST_TMP_DIR" EnvDiffChars = "SZTEST_DIFF_CHARS" EnvDiffSlice = "SZTEST_DIFF_SLICE" EnvMarkWntOn = "SZTEST_MARK_WNT_ON" EnvMarkWntOff = "SZTEST_MARK_WNT_OFF" EnvMarkGotOn = "SZTEST_MARK_GOT_ON" EnvMarkGotOff = "SZTEST_MARK_GOT_OFF" EnvMarkMsgOn = "SZTEST_MARK_MSG_ON" EnvMarkMsgOff = "SZTEST_MARK_MSG_OFF" EnvMarkInsOn = "SZTEST_MARK_INS_ON" EnvMarkInsOff = "SZTEST_MARK_INS_OFF" EnvMarkDelOn = "SZTEST_MARK_DEL_ON" EnvMarkDelOff = "SZTEST_MARK_DEL_OFF" EnvMarkChgOn = "SZTEST_MARK_CHG_ON" EnvMarkChgOff = "SZTEST_MARK_CHG_OFF" EnvMarkSepOn = "SZTEST_MARK_SEP_ON" EnvMarkSepOff = "SZTEST_MARK_SEP_OFF" )
Environment variable identifiers.
const ( SubTimestamp = `\d?\d:\d?\d:\d?\d(?:\.?\d{1,9})?` SubDuration = `\d+(?:\.?\d+)?(?:ns|us|µs|ms|s|m|h)` )
Builtin replacement regular expressions.
const BlankErrorMessage = "sztest.BlankErrorMessage"
BlankErrorMessage represents an empty panic message received.
const BlankPanicMessage = "sztest.BlankPanicMessage"
BlankPanicMessage represents an empty panic message received.
Variables ¶
var ( ErrInvalidLastArg = errors.New("invalid last arg error") ErrInvalidDirectory = errors.New("invalid directory") ErrInvalidFile = errors.New("invalid file") ErrReadPastEndOfData = errors.New("read past end of data") ErrForcedOutOfSpace = errors.New("forced out of space") )
Exported errors.
Functions ¶
func IsFloat32Similar ¶
IsFloat32Similar compares two floats to see if they match within the specified tolerance.
func IsFloat64Similar ¶
IsFloat64Similar compares two floats to see if they match within the specified tolerance.
func ReloadSettings ¶
func ReloadSettings()
ReloadSettings re-initializes the settings maintaining global configuration that control defaults such as permissions, temporary directories, diff granularity, and ANSI markup styles. Each setting can be overridden by environment variables, or falls back to a built-in default if unset. Tests can reload the settings explicitly with ReloadSettings().
Most of these values are surfaced through accessor functions (e.g., SettingPermFile(), SettingDiffChars(), SettingMarkWntOn()) so that code and tests always consult the resolved value rather than reading environment variables directly. This makes behavior deterministic and consistent across environments.
func SettingBufferSize ¶
func SettingBufferSize() int
SettingBufferSize returns the default setting overridden by env settings.
func SettingDiffChars ¶
func SettingDiffChars() int
SettingDiffChars returns the minimum number of consecutive matching characters required within a line for sztest to treat regions of `got` and `wnt` strings as identical when computing diffs. In effect, this defines the size of the "diff window" horizontally across a line. Smaller values increase sensitivity but may produce noisier diffs.
func SettingDiffSlice ¶
func SettingDiffSlice() int
SettingDiffSlice returns the minimum number of consecutive matching lines required within two slices for sztest to treat regions as identical when computing diffs. This is the vertical "diff window" size. Lower values highlight finer-grained changes, higher values collapse noise and make large blocks of similarity clearer.
func SettingFailFast ¶
func SettingFailFast() bool
SettingFailFast returns the default setting overridden by env settings.
func SettingMarkChgOff ¶
func SettingMarkChgOff() string
SettingMarkChgOff returns the resolved "wanted value end" marker string. This complements SettingMarkChgOn(), delimiting where the highlight decoration stops.
func SettingMarkChgOn ¶
func SettingMarkChgOn() string
SettingMarkChgOn returns the resolved "wanted value start" marker string. This may be an ANSI escape sequence or plain text decoration, and is used when highlighting differences in test output. A blank string disables markup for this element.
func SettingMarkDelOff ¶
func SettingMarkDelOff() string
SettingMarkDelOff returns the resolved "wanted value end" marker string. This complements SettingMarkDelOn(), delimiting where the highlight decoration stops.
func SettingMarkDelOn ¶
func SettingMarkDelOn() string
SettingMarkDelOn returns the resolved "wanted value start" marker string. This may be an ANSI escape sequence or plain text decoration, and is used when highlighting differences in test output. A blank string disables markup for this element.
func SettingMarkGotOff ¶
func SettingMarkGotOff() string
SettingMarkGotOff returns the resolved "wanted value end" marker string. This complements SettingMarkGotOn(), delimiting where the highlight decoration stops.
func SettingMarkGotOn ¶
func SettingMarkGotOn() string
SettingMarkGotOn returns the resolved "wanted value start" marker string. This may be an ANSI escape sequence or plain text decoration, and is used when highlighting differences in test output. A blank string disables markup for this element.
func SettingMarkInsOff ¶
func SettingMarkInsOff() string
SettingMarkInsOff returns the resolved "wanted value end" marker string. This complements SettingMarkInsOn(), delimiting where the highlight decoration stops.
func SettingMarkInsOn ¶
func SettingMarkInsOn() string
SettingMarkInsOn returns the resolved "wanted value start" marker string. This may be an ANSI escape sequence or plain text decoration, and is used when highlighting differences in test output. A blank string disables markup for this element.
func SettingMarkMsgOff ¶
func SettingMarkMsgOff() string
SettingMarkMsgOff returns the resolved "wanted value end" marker string. This complements SettingMarkMsgOn(), delimiting where the highlight decoration stops.
func SettingMarkMsgOn ¶
func SettingMarkMsgOn() string
SettingMarkMsgOn returns the resolved "wanted value start" marker string. This may be an ANSI escape sequence or plain text decoration, and is used when highlighting differences in test output. A blank string disables markup for this element.
func SettingMarkSepOff ¶
func SettingMarkSepOff() string
SettingMarkSepOff returns the resolved "wanted value end" marker string. This complements SettingMarkSepOn(), delimiting where the highlight decoration stops.
func SettingMarkSepOn ¶
func SettingMarkSepOn() string
SettingMarkSepOn returns the resolved "wanted value start" marker string. This may be an ANSI escape sequence or plain text decoration, and is used when highlighting differences in test output. A blank string disables markup for this element.
func SettingMarkWntOff ¶
func SettingMarkWntOff() string
SettingMarkWntOff returns the resolved "wanted value end" marker string. This complements SettingMarkWntOn(), delimiting where the highlight decoration stops.
func SettingMarkWntOn ¶
func SettingMarkWntOn() string
SettingMarkWntOn returns the resolved "wanted value start" marker string. This may be an ANSI escape sequence or plain text decoration, and is used when highlighting differences in test output. A blank string disables markup for this element.
func SettingPermDir ¶
SettingPermDir returns the default setting overridden by env settings.
func SettingPermExe ¶
SettingPermExe returns the default setting overridden by env settings.
func SettingPermFile ¶
SettingPermFile returns the default setting overridden by env settings.
func SettingTmpDir ¶
func SettingTmpDir() string
SettingTmpDir returns the default setting overridden by env settings.
Types ¶
type BoundedOption ¶
type BoundedOption int
BoundedOption specifies the inclusivity of bounds in a closed interval check.
const ( // BoundedOpen checks (a,b) = { x | a < x < b }. BoundedOpen BoundedOption = iota // BoundedClosed checks [a,b] = { x | a <= x <= b }. BoundedClosed // BoundedMinOpen checks (a,b] = { x | a < x <= b }. // Alias of BoundedMaxClosed. BoundedMinOpen // BoundedMaxClosed checks (a,b] = { x | a < x <= b }. // Alias of BoundedMinOpen. BoundedMaxClosed // BoundedMaxOpen checks [a,b) = { x | a <= x < b }. // Alias of BoundedMinClosed. BoundedMaxOpen // BoundedMinClosed checks [a,b) = { x | a <= x < b }. // Alias of BoundedMaxOpen. BoundedMinClosed )
type Chk ¶
type Chk struct {
// contains filtered or unexported fields
}
Chk provides the core test harness used by sztest.
It holds selectors and captured data (stdout, stderr, package log output, temp resources, environment changes, deterministic clock state, and other helpers) that the assertion helpers operate against.
Create a *Chk with one of the Capture* constructors and always defer chk.Release() to restore global state and clean up resources.
Example:
chk := sztest.CaptureNothing(t) defer chk.Release() chk.Str(got, want)
The concrete fields are intentionally unexported; use the provided constructors and methods to interact with a Chk instance.
func CaptureLog ¶
func CaptureLog(t testingT) *Chk
CaptureLog returns a *Chk that captures the package logger (log.Writer()).
Call (*Chk).Log(wantLines...) to assert captured log output before calling chk.Release().
func CaptureLogAndStderr ¶
func CaptureLogAndStderr(t testingT) *Chk
CaptureLogAndStderr returns a *Chk that captures log.Writer() and os.Stderr.
Use (*Chk).Log(...) to assert the logger output and (*Chk).Stderr(...) to assert stderr. Perform these checks before calling chk.Release().
func CaptureLogAndStderrAndStdout ¶
func CaptureLogAndStderrAndStdout(t testingT) *Chk
CaptureLogAndStderrAndStdout returns a *Chk that captures the package logger, os.Stderr and os.Stdout.
Assert the captured streams with the corresponding methods ((*Chk).Log(...), (*Chk).Stdout(...) and (*Chk).Stderr(...)) before calling chk.Release().
func CaptureLogAndStdout ¶
func CaptureLogAndStdout(t testingT) *Chk
CaptureLogAndStdout returns a *Chk that captures both log.Writer() and os.Stdout.
Use (*Chk).Log(...) to assert the logger output and (*Chk).Stdout(...) to assert stdout. Perform these checks before calling chk.Release().
func CaptureLogWithStderr ¶
func CaptureLogWithStderr(t testingT) *Chk
CaptureLogWithStderr returns a *Chk that combines the package logger output and os.Stderr into a single capture buffer.
In this combined mode the same underlying data may be inspected by either (*Chk).Log(...) or (*Chk).Stderr(...). Call exactly one of those two methods to assert the combined contents, and do so before calling chk.Release().
func CaptureLogWithStderrAndStdout ¶
func CaptureLogWithStderrAndStdout(t testingT) *Chk
CaptureLogWithStderrAndStdout returns a *Chk that combines the package logger and os.Stderr into one capture buffer and also captures os.Stdout.
Assert the combined logger/stderr with either (*Chk).Log(...) or (*Chk).Stderr(...), and assert stdout with (*Chk).Stdout(...). Do all assertions before calling chk.Release().
func CaptureNothing ¶
func CaptureNothing(t testingT) *Chk
CaptureNothing returns a *Chk that performs no output capturing.
Use this when a test needs the sztest helper object but does not need to capture stdout, stderr, or the package logger. The supplied t must be a testing helper (*testing.T).
Always defer chk.Release() to ensure any modified global state is restored and temporary resources are cleaned up.
func CaptureStderr ¶
func CaptureStderr(t testingT) *Chk
CaptureStderr returns a *Chk that captures os.Stderr.
Call (*Chk).Stderr(wantLines...) to assert the captured stderr before invoking chk.Release().
func CaptureStderrAndStdout ¶
func CaptureStderrAndStdout(t testingT) *Chk
CaptureStderrAndStdout returns a *Chk that captures both stderr and stdout.
Call the corresponding assertion helpers ((*Chk).Stdout(...) and (*Chk).Stderr(...)) before calling chk.Release().
func CaptureStdout ¶
func CaptureStdout(t testingT) *Chk
CaptureStdout returns a *Chk that captures os.Stdout.
Call (*Chk).Stdout(wantLines...) to assert the captured stdout before calling chk.Release(). After Release the captured data is no longer available.
func (*Chk) AddSub ¶
AddSub registers a regexp pattern and its replacement string to normalize variable output before assertions.
Each AddSub call compiles expr and stores it with subStr for later use. During comparison, substitutions are applied recursively across captured output and string assertions (e.g., Str, Err, Panic, Stdout, Stderr, Log) until no further matches remain.
This is useful for masking nondeterministic values such as timestamps, memory addresses, or counters. Compilation failures cause an immediate fatal error. Currently subStr does not support regexp submatches, but this is planned for future versions.
func (*Chk) Bool ¶
Bool compares the got bool against want.
If they differ, the failure is reported via the underlying testingT and the optional msg values are formatted and appended to the report. Returns true if got == want.
func (*Chk) BoolSlice ¶
BoolSlice compares two bool slices for equality.
A mismatch in length or element values is reported to the underlying test. Optional msg values are included in the failure output. Returns true if slices are exactly equal.
func (*Chk) BoolSlicef ¶
BoolSlicef compares two bool slices for equality.
A mismatch is reported to the underlying test with a formatted message built from msgFmt and msgArgs. Returns true if slices are exactly equal.
func (*Chk) Boolf ¶
Boolf compares the got bool against want.
If they differ, the failure is reported with a formatted message built from msgFmt and msgArgs. Returns true if got == want.
func (*Chk) Byte ¶
Byte compares the got byte against want.
If they differ, the failure is reported via the underlying testingT and the optional msg values are formatted and appended to the report. Returns true if got == want.
func (*Chk) ByteBounded ¶
ByteBounded checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with the optional msg values appended. Returns true if got is within bounds.
func (*Chk) ByteBoundedf ¶
func (chk *Chk) ByteBoundedf( got byte, option BoundedOption, minV, maxV byte, msgFmt string, msgArgs ...any, ) bool
ByteBoundedf checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) ByteSlice ¶
ByteSlice compares two byte slices for equality.
A mismatch in length or element values is reported to the underlying test. Optional msg values are included in the failure output. Returns true if slices are exactly equal.
func (*Chk) ByteSlicef ¶
ByteSlicef compares two byte slices for equality.
A mismatch is reported to the underlying test with a formatted message built from msgFmt and msgArgs. Returns true if slices are exactly equal.
func (*Chk) ByteUnbounded ¶
ByteUnbounded checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with optional msg values appended. Returns true if got is within bounds.
func (*Chk) ByteUnboundedf ¶
func (chk *Chk) ByteUnboundedf( got byte, option UnboundedOption, bound byte, msgFmt string, msgArgs ...any, ) bool
ByteUnboundedf checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Bytef ¶
Bytef compares the got byte against want.
If they differ, the failure is reported with a formatted message built from msgFmt and msgArgs. Returns true if got == want.
func (*Chk) CaptureFlagUsage ¶
CaptureFlagUsage captures and returns the usage output of the supplied *flag.FlagSet as a string. This is useful for verifying custom flag definitions and usage messages in tests.
func (*Chk) ClockAddSub ¶
ClockAddSub enables an additional substitution format.
func (*Chk) ClockLastFmtCusA ¶
ClockLastFmtCusA returns the most recent clock value using the custom A format.
func (*Chk) ClockLastFmtCusB ¶
ClockLastFmtCusB returns the most recent clock value using the custom B format.
func (*Chk) ClockLastFmtCusC ¶
ClockLastFmtCusC returns the most recent clock value using the custom C format.
func (*Chk) ClockLastFmtDate ¶
ClockLastFmtDate returns the most recent clock value formatted as YYYYMMDD.
func (*Chk) ClockLastFmtNano ¶
ClockLastFmtNano returns the most recent clock value formatted as YYYYMMDDHHmmSS.#########.
func (*Chk) ClockLastFmtTS ¶
ClockLastFmtTS returns the most recent clock value formatted as YYYYMMDDHHmmSS.
func (*Chk) ClockLastFmtTime ¶
ClockLastFmtTime returns the most recent clock value formatted as HHmmSS.
func (*Chk) ClockNext ¶
ClockNext advances the test clock by one increment and returns the result as a time.Time value.
func (*Chk) ClockNextFmtCusA ¶
ClockNextFmtCusA advances the test clock and returns the result formatted using the custom CusA format.
func (*Chk) ClockNextFmtCusB ¶
ClockNextFmtCusB advances the test clock and returns the result formatted using the custom CusB format.
func (*Chk) ClockNextFmtCusC ¶
ClockNextFmtCusC advances the test clock and returns the result formatted using the custom CusC format.
func (*Chk) ClockNextFmtDate ¶
ClockNextFmtDate advances the test clock and returns the result formatted as YYYYMMDD.
func (*Chk) ClockNextFmtNano ¶
ClockNextFmtNano advances the test clock and returns the result formatted as YYYYMMDDHHmmSS.#########.
func (*Chk) ClockNextFmtTS ¶
ClockNextFmtTS advances the test clock and returns the result formatted as YYYYMMDDHHmmSS.
func (*Chk) ClockNextFmtTime ¶
ClockNextFmtTime advances the test clock and returns the result formatted as HHmmSS.
func (*Chk) ClockOffset ¶
ClockOffset shifts the test clock by the specified duration. Optional increments may also be supplied, applied in the same cycling manner as ClockSet.
It returns a reset function that restores the clock to its prior state, intended for use with defer. Internally, the last time recorded is initialized to newTime minus the final increment.
func (*Chk) ClockOffsetDay ¶
ClockOffsetDay shifts the test clock by the specified number of days. Negative values move the clock into the past. Optional increments may also be supplied, applied in the same cycling manner as ClockSet.
It returns a reset function that restores the clock to its prior state, intended for use with defer. Internally, the last time recorded is initialized to newTime minus the final increment.
func (*Chk) ClockRemoveSub ¶
ClockRemoveSub disables a previously enabled substitution format.
func (*Chk) ClockSet ¶
ClockSet assigns a new base time for the test clock and, if provided, updates the sequence of increments. When multiple increments are supplied, they are applied in order and wrap around once exhausted.
It returns a reset function that restores the clock to its previous state, intended for use with defer. Internally, the last time recorded is initialized to newTime minus the final increment.
func (*Chk) ClockSetCusA ¶
ClockSetCusA defines the format string used for {{clkCusA#}} substitutions. The format must follow Go’s time layout conventions.
func (*Chk) ClockSetCusB ¶
ClockSetCusB defines the format string used for {{clkCusB#}} substitutions. The format must follow Go’s time layout conventions.
func (*Chk) ClockSetCusC ¶
ClockSetCusC defines the format string used for {{clkCusC#}} substitutions. The format must follow Go’s time layout conventions.
func (*Chk) ClockSetSub ¶
ClockSetSub replaces the active substitution formats with the specified set.
func (*Chk) Close ¶
Close implements io.Closer for chk. It returns the error previously set by SetCloseError, or nil if no error is pending. After returning a non-nil error, Close resets to return nil on future calls until re-primed.
func (*Chk) Complex64 ¶
Complex64 compares the got complex64 against want.
If they differ, the failure is reported via the underlying testingT and the optional msg values are formatted and appended to the report. Returns true if got == want.
func (*Chk) Complex64Slice ¶
Complex64Slice compares two complex64 slices for equality.
A mismatch in length or element values is reported to the underlying test. Optional msg values are included in the failure output. Returns true if slices are exactly equal.
func (*Chk) Complex64Slicef ¶
Complex64Slicef compares two complex64 slices for equality.
A mismatch is reported to the underlying test with a formatted message built from msgFmt and msgArgs. Returns true if slices are exactly equal.
func (*Chk) Complex64f ¶
Complex64f compares the got complex64 against want.
If they differ, the failure is reported with a formatted message built from msgFmt and msgArgs. Returns true if got == want.
func (*Chk) Complex128 ¶
func (chk *Chk) Complex128(got, want complex128, msg ...any) bool
Complex128 compares the got complex128 against want.
If they differ, the failure is reported via the underlying testingT and the optional msg values are formatted and appended to the report. Returns true if got == want.
func (*Chk) Complex128Slice ¶
func (chk *Chk) Complex128Slice( got, want []complex128, msg ...any, ) bool
Complex128Slice compares two complex128 slices for equality.
A mismatch in length or element values is reported to the underlying test. Optional msg values are included in the failure output. Returns true if slices are exactly equal.
func (*Chk) Complex128Slicef ¶
func (chk *Chk) Complex128Slicef( got, want []complex128, msgFmt string, msgArgs ...any, ) bool
Complex128Slicef compares two complex128 slices for equality.
A mismatch is reported to the underlying test with a formatted message built from msgFmt and msgArgs. Returns true if slices are exactly equal.
func (*Chk) Complex128f ¶
func (chk *Chk) Complex128f( got, want complex128, msgFmt string, msgArgs ...any, ) bool
Complex128f compares the got complex128 against want.
If they differ, the failure is reported with a formatted message built from msgFmt and msgArgs. Returns true if got == want.
func (*Chk) CreateTmpDir ¶
CreateTmpDir creates the root temporary directory for the current test, named after the test function and placed under the configured root (defaulting to SZTEST_TMP_DIR or /tmp). If the directory already exists, it is left unchanged and the absolute path is returned. Unless KeepTmpFiles is called, the directory and its contents are automatically removed when the test finishes without errors.
func (*Chk) CreateTmpFile ¶
CreateTmpFile removes any existing file of the same name and creates a new file in the test’s root temporary directory, writing the provided data. File permissions follow the current file mode setting. Relative paths are placed under the root directory; absolute paths are not allowed here. Unless KeepTmpFiles is called, the file is removed automatically when the test completes successfully.
func (*Chk) CreateTmpFileAs ¶
CreateTmpFileAs removes any existing file and creates a new file with the specified name in the provided path, writing the given data. The path rules are the same as for CreateTmpFileIn, and file permissions follow the current file mode setting. Unless KeepTmpFiles is called, the file is removed automatically when the test completes successfully.
func (*Chk) CreateTmpFileIn ¶
CreateTmpFileIn removes any existing file and creates a new file in the specified path, writing the provided data. The path may be relative (in which case it is resolved under the test’s root directory) or absolute, but absolute paths must begin with the test’s root directory. File permissions follow the current file mode setting. Unless KeepTmpFiles is called, the file is removed automatically when the test completes successfully.
func (*Chk) CreateTmpSubDir ¶
CreateTmpSubDir creates one or more subdirectories under the test’s root temporary directory. Each argument is appended to the path using os.PathSeparator. The full absolute path to the final subdirectory is returned. Existing directories in the chain are reused, so multiple calls with a shared parent will not overwrite each other, e.g.:
pathA := chk.CreateTmpSubDir("parent", "pathA")
pathB := chk.CreateTmpSubDir("parent", "pathB")
Both calls reuse the "parent" directory while creating separate child subdirectories. Unless KeepTmpFiles is called, all created directories are automatically removed if the test completes without errors.
func (*Chk) CreateTmpUnixScript ¶
CreateTmpUnixScript removes any existing file and creates a new Unix script in the test’s root temporary directory with the provided lines. Script permissions follow the current executable mode setting. Relative paths are placed under the root directory. Unless KeepTmpFiles is called, the script is removed automatically when the test completes successfully.
func (*Chk) CreateTmpUnixScriptAs ¶
CreateTmpUnixScriptAs removes any existing file and creates a new Unix script with the given name in the specified path, writing the provided lines. Paths follow the same rules as CreateTmpUnixScriptIn. Script permissions follow the current executable mode setting. Unless KeepTmpFiles is called, the script is removed automatically when the test completes successfully.
func (*Chk) CreateTmpUnixScriptIn ¶
CreateTmpUnixScriptIn removes any existing file and creates a new Unix script in the specified path with the provided lines. Paths may be relative (resolved under the test’s root directory) or absolute (must begin with the root directory). Script permissions follow the current executable mode setting. Unless KeepTmpFiles is called, the script is removed automatically when the test completes successfully.
func (*Chk) DelEnv ¶
DelEnv removes the named environment variable if it exists. The removal is reverted automatically when chk.Release() is called. Any error encountered is reported to the underlying *testingT.
func (*Chk) Dur ¶
Dur compares the got time.Duration against want.
If they differ, the failure is reported via the underlying testingT and the optional msg values are formatted and appended to the report. Returns true if got == want.
func (*Chk) DurBounded ¶
func (chk *Chk) DurBounded( got time.Duration, option BoundedOption, minV, maxV time.Duration, msg ...any, ) bool
DurBounded checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with the optional msg values appended. Returns true if got is within bounds.
func (*Chk) DurBoundedf ¶
func (chk *Chk) DurBoundedf( got time.Duration, option BoundedOption, minV, maxV time.Duration, msgFmt string, msgArgs ...any, ) bool
DurBoundedf checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) DurSlice ¶
DurSlice compares two time.Duration slices for equality.
A mismatch in length or element values is reported to the underlying test. Optional msg values are included in the failure output. Returns true if slices are exactly equal.
func (*Chk) DurSlicef ¶
DurSlicef compares two time.Duration slices for equality.
A mismatch is reported to the underlying test with a formatted message built from msgFmt and msgArgs. Returns true if slices are exactly equal.
func (*Chk) DurUnbounded ¶
func (chk *Chk) DurUnbounded( got time.Duration, option UnboundedOption, bound time.Duration, msg ...any, ) bool
DurUnbounded checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with optional msg values appended. Returns true if got is within bounds.
func (*Chk) DurUnboundedf ¶
func (chk *Chk) DurUnboundedf( got time.Duration, option UnboundedOption, bound time.Duration, msgFmt string, msgArgs ...any, ) bool
DurUnboundedf checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Durf ¶
Durf compares the got time.Duration against want.
If they differ, the failure is reported with a formatted message built from msgFmt and msgArgs. Returns true if got == want.
func (*Chk) Err ¶
Err compares a received error against its expected string form.
A nil error is matched by a want string of "" or "<nil>". The comparison uses err.Error() when got is non-nil. Extra context may be supplied via msg.
func (*Chk) ErrChain ¶ added in v0.1.1
ErrChain builds a string representation of an error chain.
Each element may be an error or a string. They are concatenated in order with the separator ": ". This allows construction of expected error messages for wrapped errors, suitable for comparison with Err or Errf.
func (*Chk) ErrSlice ¶
ErrSlice compares a slice of errors against a slice of expected strings.
Each error is converted to its string form (or "<nil>" if nil) before comparison. A nil error matches either "" or "<nil>" in want. Extra context may be supplied via msg.
func (*Chk) ErrSlicef ¶
ErrSlicef compares a slice of errors against a slice of expected strings.
Each error is converted to its string form (or "<nil>" if nil) before comparison. A nil error matches either "" or "<nil>" in want. Extra context may be supplied using a printf-style format string and arguments.
func (*Chk) Errf ¶
Errf compares a received error against its expected string form.
A nil error is matched by a want string of "" or "<nil>". The comparison uses err.Error() when got is non-nil. Extra context may be supplied using a printf-style format string and arguments.
func (*Chk) FailFast ¶
FailFast controls whether chk stops execution immediately after the first error (true) or continues accumulating further checks (false). This only applies to the current test and is independent of `go test -failfast`.
func (*Chk) False ¶
False compares the got bool against false.
If they differ, the failure is reported via the underlying testingT and the optional msg values are formatted and appended to the report. Returns true if got == want.
func (*Chk) Falsef ¶
Falsef compares the got bool against false.
If they differ, the failure is reported with a formatted message built from msgFmt and msgArgs. Returns true if got == want.
func (*Chk) Fatalf ¶
Fatalf forwards a formatted fatal error message to the underlying testingT. Internally it calls Errorf before aborting the current test.
func (*Chk) Float32 ¶
Float32 compares got and want within the given tolerance.
The values are considered equal if |got - want| <= tolerance. A tolerance of 0.0 requires exact equality. On mismatch, the failure is reported to the underlying testingT and the optional msg values are appended. Returns true if the comparison succeeds. NOTE: Values are considered equal if both are math.NaN.
func (*Chk) Float32Bounded ¶
func (chk *Chk) Float32Bounded( got float32, option BoundedOption, minV, maxV float32, msg ...any, ) bool
Float32Bounded checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with the optional msg values appended. Returns true if got is within bounds.
func (*Chk) Float32Boundedf ¶
func (chk *Chk) Float32Boundedf( got float32, option BoundedOption, minV, maxV float32, msgFmt string, msgArgs ...any, ) bool
Float32Boundedf checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Float32Slice ¶
Float32Slice compares two float64 slices element-wise within the given tolerance.
Each pair of elements must satisfy |got[i] - want[i]| <= tolerance. A tolerance of 0.0 requires exact equality. Length mismatches or element mismatches are reported to the underlying testingT. Optional msg values are included in the failure output. Returns true if slices are equal within tolerance. NOTE: Values are considered equal if both are math.NaN.
func (*Chk) Float32Slicef ¶
func (chk *Chk) Float32Slicef( got, want []float32, tolerance float32, msgFmt string, msgArgs ...any, ) bool
Float32Slicef compares two float64 slices element-wise within the given tolerance.
Each pair of elements must satisfy |got[i] - want[i]| <= tolerance. A tolerance of 0.0 requires exact equality. Length mismatches or element mismatches are reported to the underlying testingT with a formatted message built from msgFmt and msgArgs. Returns true if slices are equal within tolerance. NOTE: Values are considered equal if both are math.NaN.
func (*Chk) Float32Unbounded ¶
func (chk *Chk) Float32Unbounded( got float32, option UnboundedOption, bound float32, msg ...any, ) bool
Float32Unbounded checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with optional msg values appended. Returns true if got is within bounds.
func (*Chk) Float32Unboundedf ¶
func (chk *Chk) Float32Unboundedf( got float32, option UnboundedOption, bound float32, msgFmt string, msgArgs ...any, ) bool
Float32Unboundedf checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Float32f ¶
Float32f compares got and want within the given tolerance.
The values are considered equal if |got - want| <= tolerance. A tolerance of 0.0 requires exact equality. On mismatch, the failure is reported with a formatted message built from msgFmt and msgArgs. Returns true if the comparison succeeds. NOTE: Values are considered equal if both are math.NaN.
func (*Chk) Float64 ¶
Float64 compares got and want within the given tolerance.
The values are considered equal if |got - want| <= tolerance. A tolerance of 0.0 requires exact equality. On mismatch, the failure is reported to the underlying testingT and the optional msg values are appended. Returns true if the comparison succeeds. NOTE: Values are considered equal if both are math.NaN.
func (*Chk) Float64Bounded ¶
func (chk *Chk) Float64Bounded( got float64, option BoundedOption, minV, maxV float64, msg ...any, ) bool
Float64Bounded checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with the optional msg values appended. Returns true if got is within bounds.
func (*Chk) Float64Boundedf ¶
func (chk *Chk) Float64Boundedf( got float64, option BoundedOption, minV, maxV float64, msgFmt string, msgArgs ...any, ) bool
Float64Boundedf checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Float64Slice ¶
Float64Slice compares two float64 slices element-wise within the given tolerance.
Each pair of elements must satisfy |got[i] - want[i]| <= tolerance. A tolerance of 0.0 requires exact equality. Length mismatches or element mismatches are reported to the underlying testingT. Optional msg values are included in the failure output. Returns true if slices are equal within tolerance. NOTE: Values are considered equal if both are math.NaN.
func (*Chk) Float64Slicef ¶
func (chk *Chk) Float64Slicef( got, want []float64, tolerance float64, msgFmt string, msgArgs ...any, ) bool
Float64Slicef compares two float64 slices element-wise within the given tolerance.
Each pair of elements must satisfy |got[i] - want[i]| <= tolerance. A tolerance of 0.0 requires exact equality. Length mismatches or element mismatches are reported to the underlying testingT with a formatted message built from msgFmt and msgArgs. Returns true if slices are equal within tolerance. NOTE: Values are considered equal if both are math.NaN.
func (*Chk) Float64Unbounded ¶
func (chk *Chk) Float64Unbounded( got float64, option UnboundedOption, bound float64, msg ...any, ) bool
Float64Unbounded checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with optional msg values appended. Returns true if got is within bounds.
func (*Chk) Float64Unboundedf ¶
func (chk *Chk) Float64Unboundedf( got float64, option UnboundedOption, bound float64, msgFmt string, msgArgs ...any, ) bool
Float64Unboundedf checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Float64f ¶
Float64f compares got and want within the given tolerance.
The values are considered equal if |got - want| <= tolerance. A tolerance of 0.0 requires exact equality. On mismatch, the failure is reported with a formatted message built from msgFmt and msgArgs. Returns true if the comparison succeeds. NOTE: Values are considered equal if both are math.NaN.
func (*Chk) GetIOWriterData ¶
GetIOWriterData returns all bytes written to the io.Writer interface so far, and clears the internal buffer. This is useful for verifying output in tests.
func (*Chk) Int ¶
Int compares the got int against want.
If they differ, the failure is reported via the underlying testingT and the optional msg values are formatted and appended to the report. Returns true if got == want.
func (*Chk) Int8 ¶
Int8 compares the got int8 against want.
If they differ, the failure is reported via the underlying testingT and the optional msg values are formatted and appended to the report. Returns true if got == want.
func (*Chk) Int8Bounded ¶
Int8Bounded checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with the optional msg values appended. Returns true if got is within bounds.
func (*Chk) Int8Boundedf ¶
func (chk *Chk) Int8Boundedf( got int8, option BoundedOption, minV, maxV int8, msgFmt string, msgArgs ...any, ) bool
Int8Boundedf checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Int8Slice ¶
Int8Slice compares two int8 slices for equality.
A mismatch in length or element values is reported to the underlying test. Optional msg values are included in the failure output. Returns true if slices are exactly equal.
func (*Chk) Int8Slicef ¶
Int8Slicef compares two int8 slices for equality.
A mismatch is reported to the underlying test with a formatted message built from msgFmt and msgArgs. Returns true if slices are exactly equal.
func (*Chk) Int8Unbounded ¶
Int8Unbounded checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with optional msg values appended. Returns true if got is within bounds.
func (*Chk) Int8Unboundedf ¶
func (chk *Chk) Int8Unboundedf( got int8, option UnboundedOption, bound int8, msgFmt string, msgArgs ...any, ) bool
Int8Unboundedf checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Int8f ¶
Int8f compares the got int8 against want.
If they differ, the failure is reported with a formatted message built from msgFmt and msgArgs. Returns true if got == want.
func (*Chk) Int16 ¶
Int16 compares the got int16 against want.
If they differ, the failure is reported via the underlying testingT and the optional msg values are formatted and appended to the report. Returns true if got == want.
func (*Chk) Int16Bounded ¶
Int16Bounded checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with the optional msg values appended. Returns true if got is within bounds.
func (*Chk) Int16Boundedf ¶
func (chk *Chk) Int16Boundedf( got int16, option BoundedOption, minV, maxV int16, msgFmt string, msgArgs ...any, ) bool
Int16Boundedf checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Int16Slice ¶
Int16Slice compares two int16 slices for equality.
A mismatch in length or element values is reported to the underlying test. Optional msg values are included in the failure output. Returns true if slices are exactly equal.
func (*Chk) Int16Slicef ¶
Int16Slicef compares two int16 slices for equality.
A mismatch is reported to the underlying test with a formatted message built from msgFmt and msgArgs. Returns true if slices are exactly equal.
func (*Chk) Int16Unbounded ¶
Int16Unbounded checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with optional msg values appended. Returns true if got is within bounds.
func (*Chk) Int16Unboundedf ¶
func (chk *Chk) Int16Unboundedf( got int16, option UnboundedOption, bound int16, msgFmt string, msgArgs ...any, ) bool
Int16Unboundedf checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Int16f ¶
Int16f compares the got int16 against want.
If they differ, the failure is reported with a formatted message built from msgFmt and msgArgs. Returns true if got == want.
func (*Chk) Int32 ¶
Int32 compares the got int32 against want.
If they differ, the failure is reported via the underlying testingT and the optional msg values are formatted and appended to the report. Returns true if got == want.
func (*Chk) Int32Bounded ¶
Int32Bounded checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with the optional msg values appended. Returns true if got is within bounds.
func (*Chk) Int32Boundedf ¶
func (chk *Chk) Int32Boundedf( got int32, option BoundedOption, minV, maxV int32, msgFmt string, msgArgs ...any, ) bool
Int32Boundedf checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Int32Slice ¶
Int32Slice compares two int32 slices for equality.
A mismatch in length or element values is reported to the underlying test. Optional msg values are included in the failure output. Returns true if slices are exactly equal.
func (*Chk) Int32Slicef ¶
Int32Slicef compares two int32 slices for equality.
A mismatch is reported to the underlying test with a formatted message built from msgFmt and msgArgs. Returns true if slices are exactly equal.
func (*Chk) Int32Unbounded ¶
Int32Unbounded checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with optional msg values appended. Returns true if got is within bounds.
func (*Chk) Int32Unboundedf ¶
func (chk *Chk) Int32Unboundedf( got int32, option UnboundedOption, bound int32, msgFmt string, msgArgs ...any, ) bool
Int32Unboundedf checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Int32f ¶
Int32f compares the got int32 against want.
If they differ, the failure is reported with a formatted message built from msgFmt and msgArgs. Returns true if got == want.
func (*Chk) Int64 ¶
Int64 compares the got int64 against want.
If they differ, the failure is reported via the underlying testingT and the optional msg values are formatted and appended to the report. Returns true if got == want.
func (*Chk) Int64Bounded ¶
Int64Bounded checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with the optional msg values appended. Returns true if got is within bounds.
func (*Chk) Int64Boundedf ¶
func (chk *Chk) Int64Boundedf( got int64, option BoundedOption, minV, maxV int64, msgFmt string, msgArgs ...any, ) bool
Int64Boundedf checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Int64Slice ¶
Int64Slice compares two int64 slices for equality.
A mismatch in length or element values is reported to the underlying test. Optional msg values are included in the failure output. Returns true if slices are exactly equal.
func (*Chk) Int64Slicef ¶
Int64Slicef compares two int64 slices for equality.
A mismatch is reported to the underlying test with a formatted message built from msgFmt and msgArgs. Returns true if slices are exactly equal.
func (*Chk) Int64Unbounded ¶
Int64Unbounded checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with optional msg values appended. Returns true if got is within bounds.
func (*Chk) Int64Unboundedf ¶
func (chk *Chk) Int64Unboundedf( got int64, option UnboundedOption, bound int64, msgFmt string, msgArgs ...any, ) bool
Int64Unboundedf checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Int64f ¶
Int64f compares the got int64 against want.
If they differ, the failure is reported with a formatted message built from msgFmt and msgArgs. Returns true if got == want.
func (*Chk) IntBounded ¶
IntBounded checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with the optional msg values appended. Returns true if got is within bounds.
func (*Chk) IntBoundedf ¶
func (chk *Chk) IntBoundedf( got int, option BoundedOption, minV, maxV int, msgFmt string, msgArgs ...any, ) bool
IntBoundedf checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) IntSlice ¶
IntSlice compares two int slices for equality.
A mismatch in length or element values is reported to the underlying test. Optional msg values are included in the failure output. Returns true if slices are exactly equal.
func (*Chk) IntSlicef ¶
IntSlicef compares two int slices for equality.
A mismatch is reported to the underlying test with a formatted message built from msgFmt and msgArgs. Returns true if slices are exactly equal.
func (*Chk) IntUnbounded ¶
IntUnbounded checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with optional msg values appended. Returns true if got is within bounds.
func (*Chk) IntUnboundedf ¶
func (chk *Chk) IntUnboundedf( got int, option UnboundedOption, bound int, msgFmt string, msgArgs ...any, ) bool
IntUnboundedf checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Intf ¶
Intf compares the got int against want.
If they differ, the failure is reported with a formatted message built from msgFmt and msgArgs. Returns true if got == want.
func (*Chk) KeepTmpFiles ¶
func (chk *Chk) KeepTmpFiles()
KeepTmpFiles prevents automatic cleanup of the temporary directory tree when the test completes successfully. Applies only to the current test and is useful for debugging setups by inspecting intermediate files.
func (*Chk) LastErr ¶
LastErr extracts the final argument from args as an error.
This is useful for functions that return multiple values when only the trailing error needs to be checked. For example:
chk.NoErr(chk.LastErr(fmt.Fprintln(f, "msg")))
If args is empty or the final argument does not implement error, ErrInvalidLastErrArg is returned.
func (*Chk) Log ¶
Log compares the internally captured logger output against wantLines.
Any decorations applied by the standard library log package (such as timestamps, optional flags, or prefixes) are stripped before comparison. This ensures that tests focus only on the actual log message content rather than on formatting applied by the logger itself.
Returns true when the captured lines match exactly the supplied sequence. Failures are reported to the underlying testingT. Call this before chk.Release().
func (*Chk) Nil ¶
Nil reports whether got is nil, including cases where got is an interface holding a typed nil pointer. It reports a failure through chk’s testingT if got is non-nil. An optional message may be provided.
func (*Chk) Nilf ¶
Nilf reports whether got is nil, including cases where got is an interface holding a typed nil pointer. It reports a failure through chk’s testingT if got is non-nil. The message is formatted according to msgFmt and msgArgs.
func (*Chk) NoErr ¶
NoErr asserts that an error is nil.
It is equivalent to calling Err(got, ""). Extra context may be supplied via msg.
func (*Chk) NoErrf ¶
NoErrf asserts that an error is nil.
It is equivalent to calling Errf(got, "", msgFmt, msgArgs...). Extra context may be supplied using a printf-style format string and arguments.
func (*Chk) NoPanic ¶
NoPanic verifies that gotF does not panic.
Equivalent to calling Panic with want set to "".
func (*Chk) NoPanicf ¶
NoPanicf verifies that gotF does not panic.
Equivalent to calling Panicf with want set to "".
func (*Chk) NotNil ¶
NotNil reports whether got is non-nil. Unlike Nil, this treats an interface holding a typed nil pointer as nil. It reports a failure through chk’s testingT if got is nil. An optional message may be provided.
func (*Chk) NotNilf ¶
NotNilf reports whether got is non-nil. Unlike Nil, this treats an interface holding a typed nil pointer as nil. It reports a failure through chk’s testingT if got is nil. The message is formatted according to msgFmt and msgArgs.
func (*Chk) Panic ¶
Panic runs gotF and compares its panic value against want.
The stack trace is ignored; only the string form of the panic value is compared. A want of "" or "<nil>" indicates that no panic is expected.
func (*Chk) Panicf ¶
Panicf runs gotF and compares its panic value against want.
Behaves like Panic but formats msg using msgFmt and msgArgs when reporting a mismatch. A want of "" or "<nil>" indicates that no panic is expected.
func (*Chk) PushPostReleaseFunc ¶
PushPostReleaseFunc appends a new cleanup function to the post-release queue.
Post-release functions are executed after the Chk's internal cleanup and after pre-release functions. Functions are executed in the order they are pushed (FIFO). Each function should return a non-nil error to indicate a cleanup failure; Release will report such errors to the test.
func (*Chk) PushPreReleaseFunc ¶
PushPreReleaseFunc prepends a new cleanup function to the pre-release queue.
Pre-release functions are executed before the Chk's internal cleanup. Since each new function is placed at the front of the queue, pre-release funcs run in LIFO order (most recently pushed runs first). Return a non-nil error from a pre-release function to signal a cleanup failure; Release will report such errors to the test.
func (*Chk) Read ¶
Read implements io.Reader for chk. It serves data provided by SetIOReaderData, returns injected errors as configured by SetIOReaderError or SetReadError, and yields io.EOF once all data is consumed.
func (*Chk) Release ¶
func (chk *Chk) Release()
Release restores global state, runs any pushed pre-release functions, performs the Chk's internal cleanup (restoring os.Stdout/os.Stderr, log.Writer(), env vars, tmp files, clock state, etc.), and then runs any pushed post-release functions.
Release must be called (typically via defer) to avoid leaking global state or temporary resources. Any non-nil errors returned by pushed release functions are reported to the underlying testingT.
func (*Chk) Rune ¶
Rune compares the got rune against want.
If they differ, the failure is reported via the underlying testingT and the optional msg values are formatted and appended to the report. Returns true if got == want.
func (*Chk) RuneBounded ¶
RuneBounded checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with the optional msg values appended. Returns true if got is within bounds.
func (*Chk) RuneBoundedf ¶
func (chk *Chk) RuneBoundedf( got rune, option BoundedOption, minV, maxV rune, msgFmt string, msgArgs ...any, ) bool
RuneBoundedf checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) RuneSlice ¶
RuneSlice compares two rune slices for equality.
A mismatch in length or element values is reported to the underlying test. Optional msg values are included in the failure output. Returns true if slices are exactly equal.
func (*Chk) RuneSlicef ¶
RuneSlicef compares two rune slices for equality.
A mismatch is reported to the underlying test with a formatted message built from msgFmt and msgArgs. Returns true if slices are exactly equal.
func (*Chk) RuneUnbounded ¶
RuneUnbounded checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with optional msg values appended. Returns true if got is within bounds.
func (*Chk) RuneUnboundedf ¶
func (chk *Chk) RuneUnboundedf( got rune, option UnboundedOption, bound rune, msgFmt string, msgArgs ...any, ) bool
RuneUnboundedf checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Runef ¶
Runef compares the got rune against want.
If they differ, the failure is reported with a formatted message built from msgFmt and msgArgs. Returns true if got == want.
func (*Chk) Seek ¶
Seek implements the io.Seeker interface. It updates the current seek position and returns any pending error set via SetSeekError. If no error is pending, it behaves as a successful seek.
func (*Chk) SetArgs ¶ added in v0.0.1
SetArgs replaces the process arguments used by os.Args and the default flag.CommandLine. It sets os.Args to progName followed by args, and creates a new flag set configured with flag.PanicOnError. The original arguments and flag.CommandLine are restored when chk.Release() is called.
func (*Chk) SetCloseError ¶
SetCloseError primes chk so that the next call to Close returns err. After returning err once, Close resets to return nil on subsequent calls unless SetCloseError is invoked again.
func (*Chk) SetEnv ¶
SetEnv sets or updates the named environment variable to the given value. Changes are reverted automatically when chk.Release() is called. Any error encountered is reported to the underlying *testingT.
func (*Chk) SetIOReaderData ¶
SetIOReaderData initializes chk’s io.Reader with the supplied strings. The strings are concatenated and served sequentially through Read. Once exhausted, Read returns io.EOF.
func (*Chk) SetIOReaderError ¶
SetIOReaderError configures chk’s io.Reader to return err once the given byteCount has been read. After returning err, chk clears it and continues serving any remaining data until EOF.
func (*Chk) SetIOWriterError ¶
SetIOWriterError configures the io.Writer interface to return the specified error after writing n bytes. Once triggered, the error is cleared and subsequent writes proceed as normal unless another error is set.
func (*Chk) SetPermDir ¶
SetPermDir updates the default os.FileMode used for creating directories in temporary test setups, returning the previous value. The setting applies only to the current test. If not explicitly set, the default is taken from the SZTEST_PERM_DIR environment variable or falls back to 0o0700.
func (*Chk) SetPermExe ¶
SetPermExe updates the default os.FileMode used for creating executable files in temporary test setups, returning the previous value. The setting applies only to the current test. If not explicitly set, the default is taken from the SZTEST_PERM_EXE environment variable or falls back to 0o0700.
func (*Chk) SetPermFile ¶
SetPermFile updates the default os.FileMode used for creating regular files in temporary test setups, returning the previous value. The setting applies only to the current test. If not explicitly set, the default is taken from the SZTEST_PERM_FILE environment variable or falls back to 0o0600.
func (*Chk) SetReadError ¶
SetReadError primes chk’s io.Reader to return (pos, err) on the next call to Read. After returning, chk clears the error and resumes normal reading for subsequent calls.
func (*Chk) SetSeekError ¶
SetSeekError primes the chk object to return the provided error on a future Seek call. The error is returned once, after which normal seek behavior resumes.
func (*Chk) SetStdinData ¶
SetStdinData replaces os.Stdin with a stream that sequentially provides the supplied lines. Once exhausted, reads return io.EOF. This is not part of io.Reader itself but enables testing of code that directly consumes os.Stdin.
func (*Chk) SetTmpDir ¶
SetTmpDir overrides the root directory used when creating temporary files and directories, returning the previous value. The setting applies only to the current test. By default, the root is taken from the SZTEST_TMP_DIR environment variable or falls back to /tmp.
func (*Chk) SetWriteError ¶
SetWriteError primes the chk object to return the given position and error on the very next Write call. The error is returned once, and then cleared automatically.
func (*Chk) Stderr ¶
Stderr compares the internally captured stderr output against wantLines.
It returns true on an exact match and reports test failures via the Chk's testingT. Call this before chk.Release().
func (*Chk) Stdout ¶
Stdout compares the internally captured stdout output against wantLines.
It returns true on an exact match and reports test failures via the Chk's testingT. Call this before chk.Release().
func (*Chk) Str ¶
Str compares the got string against want.
If they differ, the failure is reported via the underlying testingT and the optional msg values are formatted and appended to the report. Returns true if got == want.
func (*Chk) StrBounded ¶
StrBounded checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with the optional msg values appended. Returns true if got is within bounds.
func (*Chk) StrBoundedf ¶
func (chk *Chk) StrBoundedf( got string, option BoundedOption, minV, maxV string, msgFmt string, msgArgs ...any, ) bool
StrBoundedf checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) StrSlice ¶
StrSlice compares two string slices for equality.
A mismatch in length or element values is reported to the underlying test. Optional msg values are included in the failure output. Returns true if slices are exactly equal.
func (*Chk) StrSlicef ¶
StrSlicef compares two string slices for equality.
A mismatch is reported to the underlying test with a formatted message built from msgFmt and msgArgs. Returns true if slices are exactly equal.
func (*Chk) StrUnbounded ¶
StrUnbounded checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with optional msg values appended. Returns true if got is within bounds.
func (*Chk) StrUnboundedf ¶
func (chk *Chk) StrUnboundedf( got string, option UnboundedOption, bound string, msgFmt string, msgArgs ...any, ) bool
StrUnboundedf checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Strf ¶
Strf compares the got string against want.
If they differ, the failure is reported with a formatted message built from msgFmt and msgArgs. Returns true if got == want.
func (*Chk) T ¶
func (chk *Chk) T() testingT
T exposes the chk's underlying testingT object, as provided at creation. Useful for advanced scenarios where direct access is required.
func (*Chk) TrimAll ¶ added in v0.1.5
TrimAll normalizes a multi-line string into a compact form suitable for output assertions.
It splits str into lines, removes common leading indentation, trims trailing whitespace from each line, and discards leading/trailing blank lines. The cleaned lines are then rejoined with a single '\n' between them and returned as one string.
To preserve intentional leading or trailing spaces/tabs, replace the first or last space/tab with the escape markers `\s` or `\t`. This allows test data to remain both human-readable and assertion-accurate. It is especially useful when comparing against captured output via Log, Stdout, or Stderr.
func (*Chk) True ¶
True compares the got bool against true.
If they differ, the failure is reported via the underlying testingT and the optional msg values are formatted and appended to the report. Returns true if got == want.
func (*Chk) Truef ¶
Truef compares the got bool against true.
If they differ, the failure is reported with a formatted message built from msgFmt and msgArgs. Returns true if got == want.
func (*Chk) Uint ¶
Uint compares the got uint against want.
If they differ, the failure is reported via the underlying testingT and the optional msg values are formatted and appended to the report. Returns true if got == want.
func (*Chk) Uint8 ¶
Uint8 compares the got uint8 against want.
If they differ, the failure is reported via the underlying testingT and the optional msg values are formatted and appended to the report. Returns true if got == want.
func (*Chk) Uint8Bounded ¶
Uint8Bounded checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with the optional msg values appended. Returns true if got is within bounds.
func (*Chk) Uint8Boundedf ¶
func (chk *Chk) Uint8Boundedf( got uint8, option BoundedOption, minV, maxV uint8, msgFmt string, msgArgs ...any, ) bool
Uint8Boundedf checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Uint8Slice ¶
Uint8Slice compares two uint8 slices for equality.
A mismatch in length or element values is reported to the underlying test. Optional msg values are included in the failure output. Returns true if slices are exactly equal.
func (*Chk) Uint8Slicef ¶
Uint8Slicef compares two uint8 slices for equality.
A mismatch is reported to the underlying test with a formatted message built from msgFmt and msgArgs. Returns true if slices are exactly equal.
func (*Chk) Uint8Unbounded ¶
Uint8Unbounded checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with optional msg values appended. Returns true if got is within bounds.
func (*Chk) Uint8Unboundedf ¶
func (chk *Chk) Uint8Unboundedf( got uint8, option UnboundedOption, bound uint8, msgFmt string, msgArgs ...any, ) bool
Uint8Unboundedf checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Uint8f ¶
Uint8f compares the got uint8 against want.
If they differ, the failure is reported with a formatted message built from msgFmt and msgArgs. Returns true if got == want.
func (*Chk) Uint16 ¶
Uint16 compares the got uint16 against want.
If they differ, the failure is reported via the underlying testingT and the optional msg values are formatted and appended to the report. Returns true if got == want.
func (*Chk) Uint16Bounded ¶
func (chk *Chk) Uint16Bounded( got uint16, option BoundedOption, minV, maxV uint16, msg ...any, ) bool
Uint16Bounded checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with the optional msg values appended. Returns true if got is within bounds.
func (*Chk) Uint16Boundedf ¶
func (chk *Chk) Uint16Boundedf( got uint16, option BoundedOption, minV, maxV uint16, msgFmt string, msgArgs ...any, ) bool
Uint16Boundedf checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Uint16Slice ¶
Uint16Slice compares two uint16 slices for equality.
A mismatch in length or element values is reported to the underlying test. Optional msg values are included in the failure output. Returns true if slices are exactly equal.
func (*Chk) Uint16Slicef ¶
Uint16Slicef compares two uint16 slices for equality.
A mismatch is reported to the underlying test with a formatted message built from msgFmt and msgArgs. Returns true if slices are exactly equal.
func (*Chk) Uint16Unbounded ¶
func (chk *Chk) Uint16Unbounded( got uint16, option UnboundedOption, bound uint16, msg ...any, ) bool
Uint16Unbounded checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with optional msg values appended. Returns true if got is within bounds.
func (*Chk) Uint16Unboundedf ¶
func (chk *Chk) Uint16Unboundedf( got uint16, option UnboundedOption, bound uint16, msgFmt string, msgArgs ...any, ) bool
Uint16Unboundedf checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Uint16f ¶
Uint16f compares the got uint16 against want.
If they differ, the failure is reported with a formatted message built from msgFmt and msgArgs. Returns true if got == want.
func (*Chk) Uint32 ¶
Uint32 compares the got uint32 against want.
If they differ, the failure is reported via the underlying testingT and the optional msg values are formatted and appended to the report. Returns true if got == want.
func (*Chk) Uint32Bounded ¶
func (chk *Chk) Uint32Bounded( got uint32, option BoundedOption, minV, maxV uint32, msg ...any, ) bool
Uint32Bounded checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with the optional msg values appended. Returns true if got is within bounds.
func (*Chk) Uint32Boundedf ¶
func (chk *Chk) Uint32Boundedf( got uint32, option BoundedOption, minV, maxV uint32, msgFmt string, msgArgs ...any, ) bool
Uint32Boundedf checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Uint32Slice ¶
Uint32Slice compares two uint32 slices for equality.
A mismatch in length or element values is reported to the underlying test. Optional msg values are included in the failure output. Returns true if slices are exactly equal.
func (*Chk) Uint32Slicef ¶
Uint32Slicef compares two uint32 slices for equality.
A mismatch is reported to the underlying test with a formatted message built from msgFmt and msgArgs. Returns true if slices are exactly equal.
func (*Chk) Uint32Unbounded ¶
func (chk *Chk) Uint32Unbounded( got uint32, option UnboundedOption, bound uint32, msg ...any, ) bool
Uint32Unbounded checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with optional msg values appended. Returns true if got is within bounds.
func (*Chk) Uint32Unboundedf ¶
func (chk *Chk) Uint32Unboundedf( got uint32, option UnboundedOption, bound uint32, msgFmt string, msgArgs ...any, ) bool
Uint32Unboundedf checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Uint32f ¶
Uint32f compares the got uint32 against want.
If they differ, the failure is reported with a formatted message built from msgFmt and msgArgs. Returns true if got == want.
func (*Chk) Uint64 ¶
Uint64 compares the got uint64 against want.
If they differ, the failure is reported via the underlying testingT and the optional msg values are formatted and appended to the report. Returns true if got == want.
func (*Chk) Uint64Bounded ¶
func (chk *Chk) Uint64Bounded( got uint64, option BoundedOption, minV, maxV uint64, msg ...any, ) bool
Uint64Bounded checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with the optional msg values appended. Returns true if got is within bounds.
func (*Chk) Uint64Boundedf ¶
func (chk *Chk) Uint64Boundedf( got uint64, option BoundedOption, minV, maxV uint64, msgFmt string, msgArgs ...any, ) bool
Uint64Boundedf checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Uint64Slice ¶
Uint64Slice compares two uint64 slices for equality.
A mismatch in length or element values is reported to the underlying test. Optional msg values are included in the failure output. Returns true if slices are exactly equal.
func (*Chk) Uint64Slicef ¶
Uint64Slicef compares two uint64 slices for equality.
A mismatch is reported to the underlying test with a formatted message built from msgFmt and msgArgs. Returns true if slices are exactly equal.
func (*Chk) Uint64Unbounded ¶
func (chk *Chk) Uint64Unbounded( got uint64, option UnboundedOption, bound uint64, msg ...any, ) bool
Uint64Unbounded checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with optional msg values appended. Returns true if got is within bounds.
func (*Chk) Uint64Unboundedf ¶
func (chk *Chk) Uint64Unboundedf( got uint64, option UnboundedOption, bound uint64, msgFmt string, msgArgs ...any, ) bool
Uint64Unboundedf checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Uint64f ¶
Uint64f compares the got uint64 against want.
If they differ, the failure is reported with a formatted message built from msgFmt and msgArgs. Returns true if got == want.
func (*Chk) UintBounded ¶
UintBounded checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with the optional msg values appended. Returns true if got is within bounds.
func (*Chk) UintBoundedf ¶
func (chk *Chk) UintBoundedf( got uint, option BoundedOption, minV, maxV uint, msgFmt string, msgArgs ...any, ) bool
UintBoundedf checks that got lies within the bounded interval defined by minV and maxV according to the chosen option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) UintSlice ¶
UintSlice compares two uint slices for equality.
A mismatch in length or element values is reported to the underlying test. Optional msg values are included in the failure output. Returns true if slices are exactly equal.
func (*Chk) UintSlicef ¶
UintSlicef compares two uint slices for equality.
A mismatch is reported to the underlying test with a formatted message built from msgFmt and msgArgs. Returns true if slices are exactly equal.
func (*Chk) UintUnbounded ¶
UintUnbounded checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with optional msg values appended. Returns true if got is within bounds.
func (*Chk) UintUnboundedf ¶
func (chk *Chk) UintUnboundedf( got uint, option UnboundedOption, bound uint, msgFmt string, msgArgs ...any, ) bool
UintUnboundedf checks that got lies within the unbounded interval defined by bound and option.
On failure, the test is reported with a formatted message built from msgFmt and msgArgs. Returns true if got is within bounds.
func (*Chk) Uintf ¶
Uintf compares the got uint against want.
If they differ, the failure is reported with a formatted message built from msgFmt and msgArgs. Returns true if got == want.
func (*Chk) Uintptr ¶
Uintptr compares the got uintptr against want.
If they differ, the failure is reported via the underlying testingT and the optional msg values are formatted and appended to the report. Returns true if got == want.
func (*Chk) UintptrSlice ¶
UintptrSlice compares two uintptr slices for equality.
A mismatch in length or element values is reported to the underlying test. Optional msg values are included in the failure output. Returns true if slices are exactly equal.
func (*Chk) UintptrSlicef ¶
UintptrSlicef compares two uintptr slices for equality.
A mismatch is reported to the underlying test with a formatted message built from msgFmt and msgArgs. Returns true if slices are exactly equal.
type ClkFmt ¶ added in v0.1.5
type ClkFmt int
ClkFmt represents supported clock formats.
const ( ClkFmtNone ClkFmt = 0 // No formats. ClkFmtTime ClkFmt = 1 << iota // {{clkTime#}} = HHmmSS. ClkFmtDate // {{clkDate#}} = YYYYMMDD. ClkFmtTS // {{clkTS#}} = YYYYMMDDHHmmSS. ClkFmtNano // {{clkNano#}} = YYYYMMDDHHmmSS.#########. ClkFmtCusA // {{clkCusA#}} = definable format string. ClkFmtCusB // {{clkCusB#}} = definable format string. ClkFmtCusC // {{clkCusC#}} = definable format string. ClkFmtAll = math.MaxInt // All defined formats. )
Clock formats and substitutions. Substitution strings allow clock ticks to be referenced in output and string assertions. If the corresponding format is enabled, {{clkXXXX#}} is replaced with the tick at the given sequence index (#):
ClkFmtTime {{clkTime#}} // HHmmSS
ClkFmtDate {{clkDate#}} // YYYYMMDD
ClkFmtTS {{clkTS#}} // YYYYMMDDHHmmSS
ClkFmtNano {{clkNano#}} // YYYYMMDDHHmmSS.#########
ClkFmtCusA {{clkCusA#}} // custom format string
ClkFmtCusB {{clkCusB#}} // custom format string
ClkFmtCusC {{clkCusC#}} // custom format string
Multiple substitution formats can be active at once, since the format flags are combined bitwise.
type UnboundedOption ¶
type UnboundedOption int
UnboundedOption specifies the inclusivity of bounds in a half-infinite interval check.
const ( // UnboundedMinOpen checks (a,+∞) = { x | x > a }. UnboundedMinOpen UnboundedOption = iota // UnboundedMinClosed checks [a,+∞) = { x | x >= a }. UnboundedMinClosed // UnboundedMaxOpen checks (-∞, b) = { x | x < b }. UnboundedMaxOpen // UnboundedMaxClosed checks (-∞, b] = { x | x <= b }. UnboundedMaxClosed )
Source Files
¶
- cfg.go
- cfg_colors.go
- cfg_init.go
- cfg_validate.go
- chk.go
- ck_bool.go
- ck_byte.go
- ck_complex128.go
- ck_complex64.go
- ck_dur.go
- ck_err.go
- ck_err_last.go
- ck_float32.go
- ck_float64.go
- ck_int.go
- ck_int16.go
- ck_int32.go
- ck_int64.go
- ck_int8.go
- ck_log.go
- ck_nil.go
- ck_panic.go
- ck_rune.go
- ck_str.go
- ck_uint.go
- ck_uint16.go
- ck_uint32.go
- ck_uint64.go
- ck_uint8.go
- ck_uintptr.go
- clock.go
- diff.go
- diff_fmt.go
- diff_markup.go
- dir.go
- doc.go
- env.go
- errs.go
- io_close.go
- io_reader.go
- io_seek.go
- io_writer.go
- os_args_and_flags.go
- substitution.go
- testing_t.go
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
appendix/large_example_function
Package example demonstrates a larger test function.
|
Package example demonstrates a larger test function. |
|
io_interface/close_error
Package example shows various test options.
|
Package example shows various test options. |
|
io_interface/read_error
Package example shows various test options.
|
Package example shows various test options. |
|
io_interface/read_seek_error
Package example shows various test options.
|
Package example shows various test options. |
|
io_interface/write_error
Package example shows various test options.
|
Package example shows various test options. |
|
io_interface/write_seek_error
Package example shows various test options.
|
Package example shows various test options. |
|
timestamp/logging
Package example provides an example of using the sztest Clock utility to test code that uses relative timestamps.
|
Package example provides an example of using the sztest Clock utility to test code that uses relative timestamps. |