sztest

package module
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2025 License: GPL-3.0 Imports: 16 Imported by: 2

README

Package sztest

package sztest

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.


Contents

Usage

A'*sztest.Chk' object is created in the test function by calling one of the sztest.Capture* functions and then deferring its Release() method to run on the completion of the test function. Common got/want type testing is provided for all go builtin types as well as some common aliases and interfaces.

Example: General Form
cat ./examples/general_form/example_test.go
package example

import (
    "testing"

    "github.com/dancsecs/sztest"
)

func Test_PASS_GeneralForm(t *testing.T) {
    chk := sztest.CaptureNothing(t)
    defer chk.Release()

    s1 := "Value Got/Wnt"
    s2 := "Value Got/Wnt"

    chk.Str(s1, s2)
    chk.Str(s1, s2, "unformatted", " message", " not", " displayed")
    chk.Strf(s1, s2, "formatted %s %s %s", "message", "not", "displayed")
}

func Test_FAIL_GeneralForm(t *testing.T) {
    chk := sztest.CaptureNothing(t)
    defer chk.Release()

    chk.FailFast(false) // Do not stop on first problem.

    s1 := "Value Got"
    s2 := "Value Wnt"

    chk.Str(s1, s2)
    chk.Str(s1, s2, "unformatted", " message", " displayed")
    chk.Strf(s1, s2, "formatted %s %s", "message", "displayed")
}
go test -v -cover ./examples/general_form

$\small{\texttt{=== ͏ ͏RUN ͏ ͏ ͏ ͏ ͏ ͏Test ̲ ̲PASS ̲ ̲GeneralForm}}$
$\small{\texttt{‒‒‒ ͏ ͏PASS: ͏ ͏ ͏ ͏Test ̲ ̲PASS ̲ ̲GeneralForm ͏ ͏(0.0s)}}$
$\small{\texttt{=== ͏ ͏RUN ͏ ͏ ͏ ͏ ͏ ͏Test ̲ ̲FAIL ̲ ̲GeneralForm}}$
$\small{\texttt{ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏example ̲ ̲test.go:30: ͏ ͏unexpected ͏ ͏string:}}$
$\small{\texttt{ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏{\color{magenta}{GOT: ͏ ͏}}Value ͏ ͏{\color{darkturquoise}{Got}}}}$
$\small{\texttt{ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏{\color{cyan}{WNT: ͏ ͏}}Value ͏ ͏{\color{darkturquoise}{Wnt}}}}$
$\small{\texttt{ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏example ̲ ̲test.go:31: ͏ ͏unexpected ͏ ͏string:}}$
$\small{\texttt{ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏{\emph{unformatted ͏ ͏message ͏ ͏displayed}}:}}$
$\small{\texttt{ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏{\color{magenta}{GOT: ͏ ͏}}Value ͏ ͏{\color{darkturquoise}{Got}}}}$
$\small{\texttt{ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏{\color{cyan}{WNT: ͏ ͏}}Value ͏ ͏{\color{darkturquoise}{Wnt}}}}$
$\small{\texttt{ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏example ̲ ̲test.go:32: ͏ ͏unexpected ͏ ͏string:}}$
$\small{\texttt{ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏{\emph{formatted ͏ ͏message ͏ ͏displayed}}:}}$
$\small{\texttt{ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏{\color{magenta}{GOT: ͏ ͏}}Value ͏ ͏{\color{darkturquoise}{Got}}}}$
$\small{\texttt{ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏{\color{cyan}{WNT: ͏ ͏}}Value ͏ ͏{\color{darkturquoise}{Wnt}}}}$
$\small{\texttt{‒‒‒ ͏ ͏FAIL: ͏ ͏ ͏ ͏Test ̲ ̲FAIL ̲ ̲GeneralForm ͏ ͏(0.0s)}}$
$\small{\texttt{FAIL}}$
$\small{\texttt{coverage: ͏ ͏[no ͏ ͏statements]}}$
$\small{\texttt{FAIL ͏ ͏github.com/dancsecs/sztest/examples/general ̲ ̲form ͏ ͏0.0s}}$
$\small{\texttt{FAIL}}$

The *sztest.Chk object is created without capturing anything with the Release method being deferred until the function exits (This opening pattern will be used by all test functions). There are three string tests. The first two pass but the third fails producing the highlighted test differences.

Contents

Builtin Got/Wnt Checks

The most basic test is to compare something "Got" from the code being tested to the "Wnt" expected by the test. If the values do not exactly match an error is registered for the test using the (testing.T.Error) function and the error is displayed as exampled above. Got/Want functions are provided for all core data types as well as some aliases and interfaces. The general forms are:

func (*CHK) Type(got, wnt Type, msg ...any) bool
func (*CHK) Typef(got, wnt Type, msgFmt string, msgArgs ...any) bool

/*
Were Type is one of:

    // Basic Types
        Bool,
        Byte,
        Complex64, Complex128
        Float32, Float64,  // Includes extra tolerance parameter.
        Int, Int8, Int16, Int32, Int64,
        Rune, Str,
        Uint, Uint8, Uint16 , Uint32, Uint64,
        Uintptr

    // Aliases.
        Dur  // time.Duration
*/

providing for an optional message and returning true if the test passed.

Contents

Array Slices

Array slice tests are provided for all core data types. The arrays must match exactly (except for float types which have a tolerance argument) otherwise a failure will be registered. The general forms are:

func (*CHK) TypeSlice(got, wnt []Type, msg ...any)
func (*CHK) TypeSlicef(got, wnt []Type, fmtMsg string, msgArgs ...any)

/*
Were Type is one of:

    // Basic Types
        Bool,
        Byte,
        Complex64, Complex128,
        Float32, Float64,  // Includes extra tolerance parameter.
        Int, Int8, Int16, Int32, Int64,
        Rune, Str,
        Uint, Uint8, Uint16 , Uint32, Uint64,
        Uintptr

    // Aliases
        Dur  // time.Duration
*/

with error slices tested with:

// Errors NOTE:  Got/Wnt are different types.
func (*Chk) ErrSlice(got []error, wnt []string, msg ...any) bool

For a complete list of builtin got/wnt slice tests and their helpers see Appendix C: List of got/wnt slice test methods.

Contents

Bounded Intervals

These tests compare a comparable got against a range of values. The general forms are:

// BoundedOption specifies the inclusivity of bounds in a closed interval
// check.
type BoundedOption int
// List of bounded options.
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
)
func (*CHK) TypeBounded(got Type, option BoundedOption,  min, max Type, msg ...any)
func (*CHK) TypeBoundedf(got Type, option BoundedOption,  min, max Type, fmtMsg string, msgArgs ...any)

/*
Were Type is one of:

    // Basic Types
        Byte,
        Float32, Float64,
        Int, Int8, Int16, Int32, Int64,
        Rune, Str,
        Uint, Uint8, Uint16 , Uint32, Uint64

    // Aliases
        Dur  // time.Duration
*/

Contents

Unbounded Intervals

These tests compare a comparable got against a range of values. The general forms are:

// UnboundedOption specifies the inclusivity of bounds in a half-infinite
// interval check.
type UnboundedOption int
// 
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
)
func (*CHK) TypeUnbounded(got Type, option UnboundedOption, bound Type, msg ...any)
func (*CHK) TypeUnboundedf(got Type, option UnboundedOption, bound Type, fmtMsg string, msgArgs ...any)

/*
Were Type is one of:

    // Basic Types
        Byte,
        Float32, Float64,
        Int, Int8, Int16, Int32, Int64,
        Rune, Str,
        Uint, Uint8, Uint16 , Uint32, Uint64

    // Aliases
        Dur  // time.Duration
*/

Contents

Errors

Error conditions are checked using the following method:

func (chk *Chk) Err(got error, want string, msg ...any) bool

and its helper methods:

func (chk *Chk) Errf(got error, want string, 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

Please note with these methods the got and wnt are different data types with the got being an error and the wnt being a string. So what happens if the error is not nil but empty?

errors.New("")

then the error returned is represented by the constant

const BlankErrorMessage = "sztest.BlankErrorMessage"

Contents

Panics

Insuring that your code properly terminates when it encounters an untenable state is important to verify. To facilitate this the library defines a panic check function:

func (chk *Chk) Panic(gotF func(), want string, msg ...any) bool

where gotF is a function that is expected to issue a panic and wnt is the string representation of the expected panic. An empty ("") wnt string represents that no panic should be thrown. The string

const BlankPanicMessage = "sztest.BlankPanicMessage"

is returned to represent an empty ("") panic was thrown differentiating it from no panic being thrown.

There are three helper functions:

func (chk *Chk) Panicf(gotF func(), want string, 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

Contents

Output

Programs writing to standard outputs (os.Stdout, os.Stderr) and the go log package (which may be distinct from os.Stderr) can have the outputs captured and reviewed as part of testing. This can be to confirm failing conditions are properly logged and reported as part of full testing.

Each can be captured individually or the log package and os.Stderr can be combined together into a single captured feed. Selection of the feeds is instantiated when the check object is initially created. See Appendix A: Capture* creation functions for a complete list.

Contents

IO Interface

The check object implements some io interfaces permitting easy simulation of hard to duplicate error and panic situations. IO interface methods implemented by the *Chk object are:

func (chk *Chk) Seek(_ int64, _ int) (int64, error)
func (chk *Chk) Read(dataBuf []byte) (int, error)
func (chk *Chk) Write(data []byte) (int, error)
func (chk *Chk) Close() error

Each of the above functions can have errors set to be returned on the next call with the following methods:

func (chk *Chk) SetReadError(pos int, err error)
func (chk *Chk) SetWriteError(pos int, err error)
func (chk *Chk) SetSeekError(pos int64, err error)
func (chk *Chk) SetCloseError(err error)

Once set the next call to the corresponding io method (read, Write ,Seek, Close or a composition function) will return the pos and error provided. The error is cleared so subsequent calls result in the default action.

Data for read actions (and position errors) is setup using the following methods:

func (chk *Chk) SetIOReaderData(d ...string)
func (chk *Chk) SetIOReaderError(byteCount int, err error)

The data will be returned (one byte at time) until the data is exhausted resulting in an io.EOF error or the optional byteCount is reached then the supplied error will be returned.

Data written can be retrieved using the following method:

func (chk *Chk) GetIOWriterData() []byte

while a positional error condition can be setup to be returned when the nth byte is written. This is setup with:

func (chk *Chk) SetIOWriterError(n int, err error)

Contents

Arguments And Flags

In order to test main default argument processing, test args and a clean flag environment are implemented with:

func (chk *Chk) SetArgs(progName string, args ...string)

where both os.Args and flags.CommandLine are saved and replaced with the provided args and a NewFlagSet respectively. Original vales are restored when the chk.Release() method is called. NOTE: The new default flag set is set to panicOnError.

Contents

Environment Variables

System environment variables mat be set or deleted using the following:

func (chk *Chk) SetEnv(name, value string)
func (chk *Chk) DelEnv(name string)

Original values are restores when the chk.Release() method is called.

Contents

Temporary directories, files, scripts

Testing underlying os file interfacing code can be somewhat automated by using some builtin helpers. Directories, files and scripts created through *chk methods will be automatically deleted on a successful test. The items are not deleted on failure or if the following helper method is invoked from the test.

func (chk *Chk) KeepTmpFiles()

The default temporary dir for the current test function is both created and identified with:

func (chk *Chk) CreateTmpDir() string

directly (or indirectly by one of these helper functions)

func (chk *Chk) CreateTmpFile(data []byte) string
func (chk *Chk) CreateTmpFileIn(path string, data []byte) string
func (chk *Chk) CreateTmpFileAs(path, fName string, data []byte) string
func (chk *Chk) CreateTmpUnixScript(lines []string) string
func (chk *Chk) CreateTmpUnixScriptIn(path string, lines []string) string
func (chk *Chk) CreateTmpUnixScriptAs(path, fName string, lines []string) string
func (chk *Chk) CreateTmpSubDir(subDirs ...string) string

which all return the path constructed by creating a new sub directory in the default temp directory.

This can be set using the environment variable:

SZTEST_TMP_DIR="/custom/tmp"

or set from within the test with:

func (chk *Chk) SetTmpDir(dir string) string

otherwise it defaults to

os.TempDir()

Permissions used when creating these objects can be defined with the following environment variables

SZTEST_PERM_DIR="0700"
SZTEST_PERM_FILE="0600"
SZTEST_PERM_EXE="0700"

or from within the test with:

func (chk *Chk) SetPermDir(p os.FileMode) os.FileMode
func (chk *Chk) SetPermFile(p os.FileMode) os.FileMode
func (chk *Chk) SetPermExe(p os.FileMode) os.FileMode

Contents

Timestamps

Predictable timestamps are provided to permit full testing of applications using timestamps. In order to facilitate this the application must use its own timestamp function pointer that defaults to be the standardtime.Now function and can be replaced by the the testing clock function (*Chk).ClockNext.

Replacing the internal time.Now method is possible using an external monkey patch library such as go-mpatch using something similar to:

//  ...

import (
   "github.com/dancsecs/sztest"
   "github.com/undefinedlabs/go-mpatch"
)

func Test_UsesTimeStamps(t *testing) {
  chk:=sztest.CaptureStdout(t)
  defer chk.Release()

  patch,err:=mpatch.PatchMethod(time.Now, chk.ClockNext)
  chk.NoErr(err)
  defer func() {
    _ = patch.Unpatch()
  }()

  // Run tests that use golang's default time.Now function.
  // ...
}

Chk.ClockNext may be invoked indirectly with the formatting convenience methods:

func (chk *Chk) ClockNextFmtTime() string
func (chk *Chk) ClockNextFmtDate() string
func (chk *Chk) ClockNextFmtTS() string
func (chk *Chk) ClockNextFmtNano() string
func (chk *Chk) ClockNextFmtCusA() string
func (chk *Chk) ClockNextFmtCusB() string
func (chk *Chk) ClockNextFmtCusC() string

As timestamps are generated they are saved and can be queried with the function:

func (chk *Chk) ClockTick(i int) time.Time

ClockTick returns the i'th time value that was generated by the test clock.

Further chk substitutions can be generated for each timestamp produced including up to three custom date formats with the following constants and methods:

// ClkFmt represents supported clock formats.
type ClkFmt int
// 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.
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.
)
func (chk *Chk) ClockSetSub(clkFmt ClkFmt)

ClockSetSub replaces the active substitution formats with the specified set.

func (chk *Chk) ClockAddSub(clkFmt ClkFmt)

ClockAddSub enables an additional substitution format.

func (chk *Chk) ClockRemoveSub(clkFmt ClkFmt)

ClockRemoveSub disables a previously enabled substitution format.

func (chk *Chk) ClockSetCusA(f string)

ClockSetCusA defines the format string used for {{clkCusA#}} substitutions. The format must follow Go’s time layout conventions.

func (chk *Chk) ClockSetCusB(f string)

ClockSetCusB defines the format string used for {{clkCusB#}} substitutions. The format must follow Go’s time layout conventions.

func (chk *Chk) ClockSetCusC(f string)

ClockSetCusC defines the format string used for {{clkCusC#}} substitutions. The format must follow Go’s time layout conventions.

The time (and increments used between successive timestamps) can be set with:

func (chk *Chk) ClockSet(newTime time.Time, inc ...time.Duration) func()

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.

or

func (chk *Chk) ClockOffsetDay(dayOffset int, inc ...time.Duration) func()

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.

or the clock can be adjusted with:

func (chk *Chk) ClockOffset(d time.Duration, inc ...time.Duration) func()

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.

while the last time returned can e retrieved with:

func (chk *Chk) ClockLast() time.Time

ClockLast returns the most recent timestamp generated by the test clock.

or the formatting convenience methods:

func (chk *Chk) ClockLastFmtTime() string
func (chk *Chk) ClockLastFmtDate() string
func (chk *Chk) ClockLastFmtTS() string
func (chk *Chk) ClockLastFmtNano() string
func (chk *Chk) ClockLastFmtCusA() string
func (chk *Chk) ClockLastFmtCusB() string
func (chk *Chk) ClockLastFmtCusC() string

Contents

Appendices

Appendix A: List of sztest.Capture* Create Functions
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 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 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 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 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(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 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(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 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(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().

Contents

Appendix B: List of got/wnt test methods
Unformatted
func (chk *Chk) Bool(got, want bool, msg ...any) bool
func (chk *Chk) False(got bool, msg ...any) bool
func (chk *Chk) True(got bool, msg ...any) bool
func (chk *Chk) Byte(got, want byte, msg ...any) bool
func (chk *Chk) Complex64(got, want complex64, msg ...any) bool
func (chk *Chk) Complex128(got, want complex128, msg ...any) bool
func (chk *Chk) Float32(got, want, tolerance float32, msg ...any) bool
func (chk *Chk) Float64(got, want, tolerance float64, msg ...any) bool
func (chk *Chk) Int(got, want int, msg ...any) bool
func (chk *Chk) Int8(got, want int8, msg ...any) bool
func (chk *Chk) Int16(got, want int16, msg ...any) bool
func (chk *Chk) Int32(got, want int32, msg ...any) bool
func (chk *Chk) Int64(got, want int64, msg ...any) bool
func (chk *Chk) Rune(got, want rune, msg ...any) bool
func (chk *Chk) Str(got, want string, msg ...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) Uint16(got, want uint16, msg ...any) bool
func (chk *Chk) Uint32(got, want uint32, msg ...any) bool
func (chk *Chk) Uint64(got, want uint64, msg ...any) bool
func (chk *Chk) Uintptr(got, want uintptr, msg ...any) bool
func (chk *Chk) Dur(got, want time.Duration, msg ...any) bool
Formatted
func (chk *Chk) Boolf(got, want bool, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Falsef(got bool, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Truef(got bool, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Bytef(got, want byte, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Complex64f(got, want complex64, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Complex128f(got, want complex128, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Float32f(got, want, tolerance float32, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Float64f(got, want, tolerance float64, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Intf(got, want int, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Int8f(got, want int8, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Int16f(got, want int16, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Int32f(got, want int32, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Int64f(got, want int64, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Runef(got, want rune, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Strf(got, want string, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Uintf(got, want uint, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Uint8f(got, want uint8, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Uint16f(got, want uint16, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Uint32f(got, want uint32, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Uint64f(got, want uint64, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Uintptrf(got, want uintptr, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Durf(got, want time.Duration, msgFmt string, msgArgs ...any) bool
Pointers and References Unformatted
func (chk *Chk) Nil(got any, msg ...any) bool
func (chk *Chk) NotNil(got any, msg ...any) bool
Pointers and References Formatted
func (chk *Chk) Nilf(got any, msgFmt string, msgArgs ...any) bool
func (chk *Chk) NotNilf(got any, msgFmt string, msgArgs ...any) bool

Contents

Appendix C: List of got/wnt slice test methods
Unformatted Slice
func (chk *Chk) BoolSlice(got, want []bool, msg ...any) bool
func (chk *Chk) ByteSlice(got, want []byte, msg ...any) bool
func (chk *Chk) Complex64Slice(got, want []complex64, msg ...any) bool
func (chk *Chk) Complex128Slice(got, want []complex128, msg ...any) bool
func (chk *Chk) Float32Slice(got, want []float32, tolerance float32, msg ...any) bool
func (chk *Chk) Float64Slice(got, want []float64, tolerance float64, msg ...any) bool
func (chk *Chk) IntSlice(got, want []int, msg ...any) bool
func (chk *Chk) Int8Slice(got, want []int8, msg ...any) bool
func (chk *Chk) Int16Slice(got, want []int16, msg ...any) bool
func (chk *Chk) Int32Slice(got, want []int32, msg ...any) bool
func (chk *Chk) Int64Slice(got, want []int64, msg ...any) bool
func (chk *Chk) RuneSlice(got, want []rune, msg ...any) bool
func (chk *Chk) StrSlice(got, want []string, msg ...any) bool
func (chk *Chk) UintSlice(got, want []uint, msg ...any) bool
func (chk *Chk) Uint8Slice(got, want []uint8, msg ...any) bool
func (chk *Chk) Uint16Slice(got, want []uint16, msg ...any) bool
func (chk *Chk) Uint32Slice(got, want []uint32, msg ...any) bool
func (chk *Chk) Uint64Slice(got, want []uint64, msg ...any) bool
func (chk *Chk) UintptrSlice(got, want []uintptr, msg ...any) bool
func (chk *Chk) DurSlice(got, want []time.Duration, msg ...any) bool
func (chk *Chk) ErrSlice(got []error, want []string, msg ...any) bool
Formatted Slice
func (chk *Chk) BoolSlicef(got, want []bool, msgFmt string, msgArgs ...any) bool
func (chk *Chk) ByteSlicef(got, want []byte, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Complex64Slicef(got, want []complex64, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Complex128Slicef(got, want []complex128, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Float32Slicef(got, want []float32, tolerance float32, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Float64Slicef(got, want []float64, tolerance float64, msgFmt string, msgArgs ...any) bool
func (chk *Chk) IntSlicef(got, want []int, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Int8Slicef(got, want []int8, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Int16Slicef(got, want []int16, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Int32Slicef(got, want []int32, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Int64Slicef(got, want []int64, msgFmt string, msgArgs ...any) bool
func (chk *Chk) RuneSlicef(got, want []rune, msgFmt string, msgArgs ...any) bool
func (chk *Chk) StrSlicef(got, want []string, msgFmt string, msgArgs ...any) bool
func (chk *Chk) UintSlicef(got, want []uint, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Uint8Slicef(got, want []uint8, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Uint16Slicef(got, want []uint16, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Uint32Slicef(got, want []uint32, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Uint64Slicef(got, want []uint64, msgFmt string, msgArgs ...any) bool
func (chk *Chk) UintptrSlicef(got, want []uintptr, msgFmt string, msgArgs ...any) bool
func (chk *Chk) DurSlicef(got, want []time.Duration, msgFmt string, msgArgs ...any) bool
func (chk *Chk) ErrSlicef(got []error, want []string, msgFmt string, msgArgs ...any) bool

Contents

Appendix D: List of Bounded and Unbounded Interval tests
Bounded Unformatted
func (chk *Chk) ByteBounded(got byte, option BoundedOption, minV, maxV byte, msg ...any) bool
func (chk *Chk) Float32Bounded(got float32, option BoundedOption, minV, maxV float32, msg ...any) bool
func (chk *Chk) Float64Bounded(got float64, option BoundedOption, minV, maxV float64, msg ...any) bool
func (chk *Chk) IntBounded(got int, option BoundedOption, minV, maxV int, msg ...any) bool
func (chk *Chk) Int8Bounded(got int8, option BoundedOption, minV, maxV int8, msg ...any) bool
func (chk *Chk) Int16Bounded(got int16, option BoundedOption, minV, maxV int16, msg ...any) bool
func (chk *Chk) Int32Bounded(got int32, option BoundedOption, minV, maxV int32, msg ...any) bool
func (chk *Chk) Int64Bounded(got int64, option BoundedOption, minV, maxV int64, msg ...any) bool
func (chk *Chk) RuneBounded(got rune, option BoundedOption, minV, maxV rune, msg ...any) bool
func (chk *Chk) StrBounded(got string, option BoundedOption, minV, maxV string, msg ...any) bool
func (chk *Chk) UintBounded(got uint, option BoundedOption, minV, maxV uint, msg ...any) bool
func (chk *Chk) Uint8Bounded(got uint8, option BoundedOption, minV, maxV uint8, msg ...any) bool
func (chk *Chk) Uint16Bounded(got uint16, option BoundedOption, minV, maxV uint16, msg ...any) bool
func (chk *Chk) Uint32Bounded(got uint32, option BoundedOption, minV, maxV uint32, msg ...any) bool
func (chk *Chk) Uint64Bounded(got uint64, option BoundedOption, minV, maxV uint64, msg ...any) bool
func (chk *Chk) DurBounded(got time.Duration, option BoundedOption, minV, maxV time.Duration, msg ...any) bool
Bounded Formatted
func (chk *Chk) ByteBoundedf(got byte, option BoundedOption, minV, maxV byte, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Float32Boundedf(got float32, option BoundedOption, minV, maxV float32, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Float64Boundedf(got float64, option BoundedOption, minV, maxV float64, msgFmt string, msgArgs ...any) bool
func (chk *Chk) IntBoundedf(got int, option BoundedOption, minV, maxV int, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Int8Boundedf(got int8, option BoundedOption, minV, maxV int8, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Int16Boundedf(got int16, option BoundedOption, minV, maxV int16, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Int32Boundedf(got int32, option BoundedOption, minV, maxV int32, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Int64Boundedf(got int64, option BoundedOption, minV, maxV int64, msgFmt string, msgArgs ...any) bool
func (chk *Chk) RuneBoundedf(got rune, option BoundedOption, minV, maxV rune, msgFmt string, msgArgs ...any) bool
func (chk *Chk) StrBoundedf(got string, option BoundedOption, minV, maxV string, msgFmt string, msgArgs ...any) bool
func (chk *Chk) UintBoundedf(got uint, option BoundedOption, minV, maxV uint, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Uint8Boundedf(got uint8, option BoundedOption, minV, maxV uint8, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Uint16Boundedf(got uint16, option BoundedOption, minV, maxV uint16, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Uint32Boundedf(got uint32, option BoundedOption, minV, maxV uint32, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Uint64Boundedf(got uint64, option BoundedOption, minV, maxV uint64, msgFmt string, msgArgs ...any) bool
func (chk *Chk) DurBoundedf(got time.Duration, option BoundedOption, minV, maxV time.Duration, msgFmt string, msgArgs ...any) bool
Unbounded Unformatted
func (chk *Chk) ByteUnbounded(got byte, option UnboundedOption, bound byte, msg ...any) bool
func (chk *Chk) Float32Unbounded(got float32, option UnboundedOption, bound float32, msg ...any) bool
func (chk *Chk) Float64Unbounded(got float64, option UnboundedOption, bound float64, msg ...any) bool
func (chk *Chk) IntUnbounded(got int, option UnboundedOption, bound int, msg ...any) bool
func (chk *Chk) Int8Unbounded(got int8, option UnboundedOption, bound int8, msg ...any) bool
func (chk *Chk) Int16Unbounded(got int16, option UnboundedOption, bound int16, msg ...any) bool
func (chk *Chk) Int32Unbounded(got int32, option UnboundedOption, bound int32, msg ...any) bool
func (chk *Chk) Int64Unbounded(got int64, option UnboundedOption, bound int64, msg ...any) bool
func (chk *Chk) RuneUnbounded(got rune, option UnboundedOption, bound rune, msg ...any) bool
func (chk *Chk) StrUnbounded(got string, option UnboundedOption, bound string, msg ...any) bool
func (chk *Chk) UintUnbounded(got uint, option UnboundedOption, bound uint, msg ...any) bool
func (chk *Chk) Uint8Unbounded(got uint8, option UnboundedOption, bound uint8, msg ...any) bool
func (chk *Chk) Uint16Unbounded(got uint16, option UnboundedOption, bound uint16, msg ...any) bool
func (chk *Chk) Uint32Unbounded(got uint32, option UnboundedOption, bound uint32, msg ...any) bool
func (chk *Chk) Uint64Unbounded(got uint64, option UnboundedOption, bound uint64, msg ...any) bool
func (chk *Chk) DurUnbounded(got time.Duration, option UnboundedOption, bound time.Duration, msg ...any) bool
Unbounded Formatted
func (chk *Chk) ByteUnboundedf(got byte, option UnboundedOption, bound byte, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Float32Unboundedf(got float32, option UnboundedOption, bound float32, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Float64Unboundedf(got float64, option UnboundedOption, bound float64, msgFmt string, msgArgs ...any) bool
func (chk *Chk) IntUnboundedf(got int, option UnboundedOption, bound int, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Int8Unboundedf(got int8, option UnboundedOption, bound int8, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Int16Unboundedf(got int16, option UnboundedOption, bound int16, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Int32Unboundedf(got int32, option UnboundedOption, bound int32, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Int64Unboundedf(got int64, option UnboundedOption, bound int64, msgFmt string, msgArgs ...any) bool
func (chk *Chk) RuneUnboundedf(got rune, option UnboundedOption, bound rune, msgFmt string, msgArgs ...any) bool
func (chk *Chk) StrUnboundedf(got string, option UnboundedOption, bound string, msgFmt string, msgArgs ...any) bool
func (chk *Chk) UintUnboundedf(got uint, option UnboundedOption, bound uint, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Uint8Unboundedf(got uint8, option UnboundedOption, bound uint8, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Uint16Unboundedf(got uint16, option UnboundedOption, bound uint16, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Uint32Unboundedf(got uint32, option UnboundedOption, bound uint32, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Uint64Unboundedf(got uint64, option UnboundedOption, bound uint64, msgFmt string, msgArgs ...any) bool
func (chk *Chk) DurUnboundedf(got time.Duration, option UnboundedOption, bound time.Duration, msgFmt string, msgArgs ...any) bool

Contents

Appendix E: Builtin Ansi Terminal Markup

See CONFIGURE.md Appendix E: Builtin Ansi Terminal Markup

Contents

Appendix F: Large Example Function

See Appendix F Example: Large Example Function

Contents

Appendix G: Large Example Main Function

See Appendix G: Large Example Main Function

Contents

Appendix H: License

/* Golang testing utility. Copyright (C) 2023-2025 Leslie Dancsecs

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/. */

Contents

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

View Source
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.

View Source
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.

View Source
const BlankErrorMessage = "sztest.BlankErrorMessage"

BlankErrorMessage represents an empty panic message received.

View Source
const BlankPanicMessage = "sztest.BlankPanicMessage"

BlankPanicMessage represents an empty panic message received.

Variables

View Source
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

func IsFloat32Similar(num1, num2, tolerance float32) bool

IsFloat32Similar compares two floats to see if they match within the specified tolerance.

func IsFloat64Similar

func IsFloat64Similar(num1, num2, tolerance float64) bool

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

func SettingPermDir() os.FileMode

SettingPermDir returns the default setting overridden by env settings.

func SettingPermExe

func SettingPermExe() os.FileMode

SettingPermExe returns the default setting overridden by env settings.

func SettingPermFile

func SettingPermFile() os.FileMode

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

func (chk *Chk) AddSub(expr, subStr string)

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

func (chk *Chk) Bool(got, want bool, msg ...any) 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

func (chk *Chk) BoolSlice(got, want []bool, msg ...any) bool

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

func (chk *Chk) BoolSlicef(
	got, want []bool, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) Boolf(got, want bool, msgFmt string, msgArgs ...any) bool

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

func (chk *Chk) Byte(got, want byte, msg ...any) bool

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

func (chk *Chk) ByteBounded(
	got byte, option BoundedOption, minV, maxV byte, msg ...any,
) bool

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

func (chk *Chk) ByteSlice(got, want []byte, msg ...any) bool

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

func (chk *Chk) ByteSlicef(
	got, want []byte, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) ByteUnbounded(
	got byte, option UnboundedOption, bound byte, msg ...any,
) bool

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

func (chk *Chk) Bytef(got, want byte, msgFmt string, msgArgs ...any) bool

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

func (*Chk) CaptureFlagUsage(flagSet *flag.FlagSet) string

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

func (chk *Chk) ClockAddSub(clkFmt ClkFmt)

ClockAddSub enables an additional substitution format.

func (*Chk) ClockLast

func (chk *Chk) ClockLast() time.Time

ClockLast returns the most recent timestamp generated by the test clock.

func (*Chk) ClockLastFmtCusA

func (chk *Chk) ClockLastFmtCusA() string

ClockLastFmtCusA returns the most recent clock value using the custom A format.

func (*Chk) ClockLastFmtCusB

func (chk *Chk) ClockLastFmtCusB() string

ClockLastFmtCusB returns the most recent clock value using the custom B format.

func (*Chk) ClockLastFmtCusC

func (chk *Chk) ClockLastFmtCusC() string

ClockLastFmtCusC returns the most recent clock value using the custom C format.

func (*Chk) ClockLastFmtDate

func (chk *Chk) ClockLastFmtDate() string

ClockLastFmtDate returns the most recent clock value formatted as YYYYMMDD.

func (*Chk) ClockLastFmtNano

func (chk *Chk) ClockLastFmtNano() string

ClockLastFmtNano returns the most recent clock value formatted as YYYYMMDDHHmmSS.#########.

func (*Chk) ClockLastFmtTS

func (chk *Chk) ClockLastFmtTS() string

ClockLastFmtTS returns the most recent clock value formatted as YYYYMMDDHHmmSS.

func (*Chk) ClockLastFmtTime

func (chk *Chk) ClockLastFmtTime() string

ClockLastFmtTime returns the most recent clock value formatted as HHmmSS.

func (*Chk) ClockNext

func (chk *Chk) ClockNext() time.Time

ClockNext advances the test clock by one increment and returns the result as a time.Time value.

func (*Chk) ClockNextFmtCusA

func (chk *Chk) ClockNextFmtCusA() string

ClockNextFmtCusA advances the test clock and returns the result formatted using the custom CusA format.

func (*Chk) ClockNextFmtCusB

func (chk *Chk) ClockNextFmtCusB() string

ClockNextFmtCusB advances the test clock and returns the result formatted using the custom CusB format.

func (*Chk) ClockNextFmtCusC

func (chk *Chk) ClockNextFmtCusC() string

ClockNextFmtCusC advances the test clock and returns the result formatted using the custom CusC format.

func (*Chk) ClockNextFmtDate

func (chk *Chk) ClockNextFmtDate() string

ClockNextFmtDate advances the test clock and returns the result formatted as YYYYMMDD.

func (*Chk) ClockNextFmtNano

func (chk *Chk) ClockNextFmtNano() string

ClockNextFmtNano advances the test clock and returns the result formatted as YYYYMMDDHHmmSS.#########.

func (*Chk) ClockNextFmtTS

func (chk *Chk) ClockNextFmtTS() string

ClockNextFmtTS advances the test clock and returns the result formatted as YYYYMMDDHHmmSS.

func (*Chk) ClockNextFmtTime

func (chk *Chk) ClockNextFmtTime() string

ClockNextFmtTime advances the test clock and returns the result formatted as HHmmSS.

func (*Chk) ClockOffset

func (chk *Chk) ClockOffset(d time.Duration, inc ...time.Duration) func()

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

func (chk *Chk) ClockOffsetDay(dayOffset int, inc ...time.Duration) func()

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

func (chk *Chk) ClockRemoveSub(clkFmt ClkFmt)

ClockRemoveSub disables a previously enabled substitution format.

func (*Chk) ClockSet

func (chk *Chk) ClockSet(newTime time.Time, inc ...time.Duration) func()

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

func (chk *Chk) ClockSetCusA(f string)

ClockSetCusA defines the format string used for {{clkCusA#}} substitutions. The format must follow Go’s time layout conventions.

func (*Chk) ClockSetCusB

func (chk *Chk) ClockSetCusB(f string)

ClockSetCusB defines the format string used for {{clkCusB#}} substitutions. The format must follow Go’s time layout conventions.

func (*Chk) ClockSetCusC

func (chk *Chk) ClockSetCusC(f string)

ClockSetCusC defines the format string used for {{clkCusC#}} substitutions. The format must follow Go’s time layout conventions.

func (*Chk) ClockSetSub

func (chk *Chk) ClockSetSub(clkFmt ClkFmt)

ClockSetSub replaces the active substitution formats with the specified set.

func (*Chk) ClockTick

func (chk *Chk) ClockTick(i int) time.Time

ClockTick returns the i'th time value that was generated by the test clock.

func (*Chk) Close

func (chk *Chk) Close() error

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

func (chk *Chk) Complex64(got, want complex64, msg ...any) bool

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

func (chk *Chk) Complex64Slice(
	got, want []complex64, msg ...any,
) bool

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

func (chk *Chk) Complex64Slicef(
	got, want []complex64, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) Complex64f(
	got, want complex64, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) CreateTmpDir() string

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

func (chk *Chk) CreateTmpFile(data []byte) string

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

func (chk *Chk) CreateTmpFileAs(path, fName string, data []byte) string

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

func (chk *Chk) CreateTmpFileIn(path string, data []byte) string

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

func (chk *Chk) CreateTmpSubDir(subDirs ...string) string

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

func (chk *Chk) CreateTmpUnixScript(lines []string) string

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

func (chk *Chk) CreateTmpUnixScriptAs(
	path, fName string,
	lines []string,
) string

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

func (chk *Chk) CreateTmpUnixScriptIn(path string, lines []string) string

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

func (chk *Chk) DelEnv(name string)

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

func (chk *Chk) Dur(got, want time.Duration, msg ...any) bool

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

func (chk *Chk) DurSlice(got, want []time.Duration, msg ...any) bool

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

func (chk *Chk) DurSlicef(
	got, want []time.Duration, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) Durf(
	got, want time.Duration, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) Err(got error, want string, msg ...any) bool

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

func (chk *Chk) ErrChain(first any, rest ...any) string

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

func (chk *Chk) ErrSlice(
	got []error, want []string, msg ...any,
) bool

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

func (chk *Chk) ErrSlicef(
	got []error, want []string, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) Errf(
	got error, want string, msgFmt string, msgArgs ...any,
) bool

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) Error

func (chk *Chk) Error(args ...any)

Error forwards an error message to the underlying testingT.

func (*Chk) Errorf

func (chk *Chk) Errorf(msgFmt string, msgArgs ...any)

Errorf forwards a formatted error message to the underlying testingT.

func (*Chk) FailFast

func (chk *Chk) FailFast(failFast bool) bool

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

func (chk *Chk) False(got bool, msg ...any) bool

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

func (chk *Chk) Falsef(got bool, msgFmt string, msgArgs ...any) bool

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

func (chk *Chk) Fatalf(msgFmt string, msgArgs ...any)

Fatalf forwards a formatted fatal error message to the underlying testingT. Internally it calls Errorf before aborting the current test.

func (*Chk) Float32

func (chk *Chk) Float32(
	got, want, tolerance float32, msg ...any,
) bool

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

func (chk *Chk) Float32Slice(
	got, want []float32, tolerance float32, msg ...any,
) bool

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

func (chk *Chk) Float32f(
	got, want, tolerance float32, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) Float64(
	got, want, tolerance float64, msg ...any,
) bool

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

func (chk *Chk) Float64Slice(
	got, want []float64, tolerance float64, msg ...any,
) bool

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

func (chk *Chk) Float64f(
	got, want, tolerance float64, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) GetIOWriterData() []byte

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

func (chk *Chk) Int(got, want int, msg ...any) bool

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

func (chk *Chk) Int8(got, want int8, msg ...any) bool

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

func (chk *Chk) Int8Bounded(
	got int8, option BoundedOption, minV, maxV int8, msg ...any,
) bool

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

func (chk *Chk) Int8Slice(got, want []int8, msg ...any) bool

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

func (chk *Chk) Int8Slicef(
	got, want []int8, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) Int8Unbounded(
	got int8, option UnboundedOption, bound int8, msg ...any,
) bool

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

func (chk *Chk) Int8f(got, want int8, msgFmt string, msgArgs ...any) bool

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

func (chk *Chk) Int16(got, want int16, msg ...any) bool

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

func (chk *Chk) Int16Bounded(
	got int16, option BoundedOption, minV, maxV int16, msg ...any,
) bool

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

func (chk *Chk) Int16Slice(got, want []int16, msg ...any) bool

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

func (chk *Chk) Int16Slicef(
	got, want []int16, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) Int16Unbounded(
	got int16, option UnboundedOption, bound int16, msg ...any,
) bool

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

func (chk *Chk) Int16f(got, want int16, msgFmt string, msgArgs ...any) bool

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

func (chk *Chk) Int32(got, want int32, msg ...any) bool

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

func (chk *Chk) Int32Bounded(
	got int32, option BoundedOption, minV, maxV int32, msg ...any,
) bool

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

func (chk *Chk) Int32Slice(got, want []int32, msg ...any) bool

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

func (chk *Chk) Int32Slicef(
	got, want []int32, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) Int32Unbounded(
	got int32, option UnboundedOption, bound int32, msg ...any,
) bool

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

func (chk *Chk) Int32f(got, want int32, msgFmt string, msgArgs ...any) bool

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

func (chk *Chk) Int64(got, want int64, msg ...any) bool

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

func (chk *Chk) Int64Bounded(
	got int64, option BoundedOption, minV, maxV int64, msg ...any,
) bool

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

func (chk *Chk) Int64Slice(got, want []int64, msg ...any) bool

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

func (chk *Chk) Int64Slicef(
	got, want []int64, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) Int64Unbounded(
	got int64, option UnboundedOption, bound int64, msg ...any,
) bool

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

func (chk *Chk) Int64f(got, want int64, msgFmt string, msgArgs ...any) bool

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

func (chk *Chk) IntBounded(
	got int, option BoundedOption, minV, maxV int, msg ...any,
) bool

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

func (chk *Chk) IntSlice(got, want []int, msg ...any) bool

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

func (chk *Chk) IntSlicef(
	got, want []int, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) IntUnbounded(
	got int, option UnboundedOption, bound int, msg ...any,
) bool

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

func (chk *Chk) Intf(got, want int, msgFmt string, msgArgs ...any) bool

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

func (*Chk) LastErr(args ...any) error

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

func (chk *Chk) Log(wantLines ...string) bool

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) Logf

func (chk *Chk) Logf(msgFmt string, msgArgs ...any)

Logf forwards a formatted log message to the underlying testingT.

func (*Chk) Name

func (chk *Chk) Name() string

Name returns the name of the current test from the underlying testingT.

func (*Chk) Nil

func (chk *Chk) Nil(got any, msg ...any) bool

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

func (chk *Chk) Nilf(got any, msgFmt string, msgArgs ...any) bool

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

func (chk *Chk) NoErr(got error, msg ...any) bool

NoErr asserts that an error is nil.

It is equivalent to calling Err(got, ""). Extra context may be supplied via msg.

func (*Chk) NoErrf

func (chk *Chk) NoErrf(got error, msgFmt string, msgArgs ...any) bool

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

func (chk *Chk) NoPanic(gotF func(), msg ...any) bool

NoPanic verifies that gotF does not panic.

Equivalent to calling Panic with want set to "".

func (*Chk) NoPanicf

func (chk *Chk) NoPanicf(gotF func(), msgFmt string, msgArgs ...any) bool

NoPanicf verifies that gotF does not panic.

Equivalent to calling Panicf with want set to "".

func (*Chk) NotNil

func (chk *Chk) NotNil(got any, msg ...any) bool

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

func (chk *Chk) NotNilf(got any, msgFmt string, msgArgs ...any) bool

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

func (chk *Chk) Panic(gotF func(), want string, msg ...any) bool

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

func (chk *Chk) Panicf(
	gotF func(), want string, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) PushPostReleaseFunc(newFunc func() error)

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

func (chk *Chk) PushPreReleaseFunc(newFunc func() error)

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

func (chk *Chk) Read(dataBuf []byte) (int, error)

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

func (chk *Chk) Rune(got, want rune, msg ...any) bool

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

func (chk *Chk) RuneBounded(
	got rune, option BoundedOption, minV, maxV rune, msg ...any,
) bool

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

func (chk *Chk) RuneSlice(got, want []rune, msg ...any) bool

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

func (chk *Chk) RuneSlicef(
	got, want []rune, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) RuneUnbounded(
	got rune, option UnboundedOption, bound rune, msg ...any,
) bool

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

func (chk *Chk) Runef(got, want rune, msgFmt string, msgArgs ...any) bool

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

func (chk *Chk) Seek(_ int64, _ int) (int64, error)

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

func (chk *Chk) SetArgs(progName string, args ...string)

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

func (chk *Chk) SetCloseError(err error)

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

func (chk *Chk) SetEnv(name, value string)

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

func (chk *Chk) SetIOReaderData(d ...string)

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

func (chk *Chk) SetIOReaderError(byteCount int, err error)

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

func (chk *Chk) SetIOWriterError(n int, err error)

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

func (chk *Chk) SetPermDir(p os.FileMode) os.FileMode

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

func (chk *Chk) SetPermExe(p os.FileMode) os.FileMode

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

func (chk *Chk) SetPermFile(p os.FileMode) os.FileMode

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

func (chk *Chk) SetReadError(pos int, err error)

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

func (chk *Chk) SetSeekError(pos int64, err error)

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

func (chk *Chk) SetStdinData(lines ...string)

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

func (chk *Chk) SetTmpDir(dir string) string

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

func (chk *Chk) SetWriteError(pos int, err error)

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

func (chk *Chk) Stderr(wantLines ...string) bool

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

func (chk *Chk) Stdout(wantLines ...string) bool

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

func (chk *Chk) Str(got, want string, msg ...any) bool

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

func (chk *Chk) StrBounded(
	got string, option BoundedOption, minV, maxV string, msg ...any,
) bool

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

func (chk *Chk) StrSlice(got, want []string, msg ...any) bool

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

func (chk *Chk) StrSlicef(
	got, want []string, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) StrUnbounded(
	got string, option UnboundedOption, bound string, msg ...any,
) bool

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

func (chk *Chk) Strf(got, want string, msgFmt string, msgArgs ...any) bool

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

func (chk *Chk) TrimAll(str string) string

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

func (chk *Chk) True(got bool, msg ...any) bool

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

func (chk *Chk) Truef(got bool, msgFmt string, msgArgs ...any) bool

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

func (chk *Chk) Uint(got, want uint, msg ...any) bool

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

func (chk *Chk) Uint8(got, want uint8, msg ...any) bool

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

func (chk *Chk) Uint8Bounded(
	got uint8, option BoundedOption, minV, maxV uint8, msg ...any,
) bool

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

func (chk *Chk) Uint8Slice(got, want []uint8, msg ...any) bool

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

func (chk *Chk) Uint8Slicef(
	got, want []uint8, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) Uint8Unbounded(
	got uint8, option UnboundedOption, bound uint8, msg ...any,
) bool

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

func (chk *Chk) Uint8f(got, want uint8, msgFmt string, msgArgs ...any) bool

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

func (chk *Chk) Uint16(got, want uint16, msg ...any) bool

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

func (chk *Chk) Uint16Slice(got, want []uint16, msg ...any) bool

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

func (chk *Chk) Uint16Slicef(
	got, want []uint16, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) Uint16f(
	got, want uint16, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) Uint32(got, want uint32, msg ...any) bool

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

func (chk *Chk) Uint32Slice(got, want []uint32, msg ...any) bool

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

func (chk *Chk) Uint32Slicef(
	got, want []uint32, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) Uint32f(
	got, want uint32, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) Uint64(got, want uint64, msg ...any) bool

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

func (chk *Chk) Uint64Slice(got, want []uint64, msg ...any) bool

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

func (chk *Chk) Uint64Slicef(
	got, want []uint64, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) Uint64f(
	got, want uint64, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) UintBounded(
	got uint, option BoundedOption, minV, maxV uint, msg ...any,
) bool

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

func (chk *Chk) UintSlice(got, want []uint, msg ...any) bool

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

func (chk *Chk) UintSlicef(
	got, want []uint, msgFmt string, msgArgs ...any,
) bool

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

func (chk *Chk) UintUnbounded(
	got uint, option UnboundedOption, bound uint, msg ...any,
) bool

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

func (chk *Chk) Uintf(got, want uint, msgFmt string, msgArgs ...any) bool

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

func (chk *Chk) Uintptr(got, want uintptr, msg ...any) bool

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

func (chk *Chk) UintptrSlice(got, want []uintptr, msg ...any) bool

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

func (chk *Chk) UintptrSlicef(
	got, want []uintptr, msgFmt string, msgArgs ...any,
) bool

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.

func (*Chk) Uintptrf

func (chk *Chk) Uintptrf(
	got, want uintptr, msgFmt string, msgArgs ...any,
) bool

Uintptrf compares the got uintptr 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) Write

func (chk *Chk) Write(data []byte) (int, error)

Write implements the io.Writer interface. Data is recorded internally and can be retrieved via GetIOWriterData. Pending errors set with SetIOWriterError or SetWriteError take precedence and are returned according to their rules.

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
)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL