sztest

package module
v0.1.4 Latest Latest
Warning

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

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

README

Package sztest

Overview

Provides a single self contained go package of test helpers.

  • got/wnt helper testing
  • 'error' testing
  • 'panic' testing
  • 'os.Stdout' and 'os.Stderr' capture and testing
  • 'package log' capture and testing
  • 'io.Reader and 'io.Writer' interface testing
  • 'os.Args' and 'os.Flag' setup testing
  • temporary directories, files and scripts
  • timestamps

Package sztest only imports core go libraries minimizing your module's dependencies.


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: \color{default}Value \color{darkturquoise}Got\color{default}}}$
$\small{\texttt{        \color{cyan}WNT: \color{default}Value \color{darkturquoise}Wnt\color{default}}}$
$\small{\texttt{    example̲test.go:31: unexpected string:}}$
$\small{\texttt{        \emph{unformatted message displayed}:}}$
$\small{\texttt{        \color{magenta}GOT: \color{default}Value \color{darkturquoise}Got\color{default}}}$
$\small{\texttt{        \color{cyan}WNT: \color{default}Value \color{darkturquoise}Wnt\color{default}}}$
$\small{\texttt{    example̲test.go:32: unexpected string:}}$
$\small{\texttt{        \emph{formatted message displayed}:}}$
$\small{\texttt{        \color{magenta}GOT: \color{default}Value \color{darkturquoise}Got\color{default}}}$
$\small{\texttt{        \color{cyan}WNT: \color{default}Value \color{darkturquoise}Wnt\color{default}}}$
$\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 constant type.
type BoundedOption int
const (
    // BoundedOpen (a,b) = { x | a < x < b }.
    BoundedOpen BoundedOption = iota
    // BoundedClosed [a,b] = { x | a ≦ x ≦ b }.
    BoundedClosed
    // BoundedMinOpen (a,b] = { x | a < x ≦ b }.
    BoundedMinOpen
    // BoundedMaxClosed (a,b] = { x | a < x ≦ b }.
    BoundedMaxClosed
    // BoundedMaxOpen [a,b) = { x | a ≦ x < b }.
    BoundedMaxOpen
    // BoundedMinClosed [a,b) = { x | a ≦ x < b }.
    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 constant type.
type UnboundedOption int
const (
    // UnboundedMinOpen (a,+∞) = { x | x > a }.
    UnboundedMinOpen UnboundedOption = iota
    // UnboundedMinClosed [a,+∞) = { x | x ≧ a }.
    UnboundedMinClosed
    // UnboundedMaxOpen (-∞, b) = { x | x < b }.
    UnboundedMaxOpen
    // UnboundedMaxClosed (-∞, 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 i'th time returned.

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


Clock substitutions.

func (chk *Chk) ClockSetSub(i int)

ClockSetSub sets the fields to set substitutions for.

func (chk *Chk) ClockAddSub(i int)

ClockAddSub sets the fields to set substitutions for.

func (chk *Chk) ClockRemoveSub(i int)

ClockRemoveSub resets the fields to set substitutions for.

func (chk *Chk) ClockSetCusA(f string)

ClockSetCusA sets the custom date format to set tick substitution values.

func (chk *Chk) ClockSetCusB(f string)

ClockSetCusB sets the custom date format to set tick substitution values.

func (chk *Chk) ClockSetCusC(f string)

ClockSetCusC sets the custom date format to set tick substitution values.

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

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

ClockSet set the current test time and optionally sets the increments if provided. It returns a func to reset the clk back to its state when this function was called.

or

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

ClockOffsetDay adjusts the current clock by the number of specified days with negative numbers representing the past. It returns a func to reset the clk back to its state when this function was called.

or the clock can be adjusted with:

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

ClockOffset moves the current clock by the specified amount. No defined increments are applied and if a clock has not yet been set the current time advanced by the specified amount will be used. Nothing is returned.

while the last time returned can e retrieved with:

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

ClockLast returns the last timestamp generated.

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 new sztest object without any logs or standard io being captured.

func CaptureStdout(t testingT) *Chk

CaptureStdout returns a new *sztest.Chk reference capturing:

  • os.Stdout

which must be tested by calling the methods:

  • (*Chk).Stdout(wantLines ...string) bool

before (*Chk).Release() is invoked.

func CaptureLog(t testingT) *Chk

CaptureLog returns a new *sztest.Chk reference capturing:

  • log.Writer() io.Writer

which must be tested by calling the methods:

  • (*Chk).Log(wantLines ...string) bool

before (*Chk).Release() is invoked.

func CaptureLogAndStdout(t testingT) *Chk

CaptureLogAndStdout returns a new *sztest.Chk reference capturing:

  • log.Writer() io.Writer
  • os.Stdout

which must be tested by calling the methods:

  • (*Chk).Log(wantLines ...string) bool
  • (*Chk).Stdout(wantLines ...string) bool

before (*Chk).Release() is invoked.

func CaptureLogAndStderr(t testingT) *Chk

CaptureLogAndStderr returns a new *sztest.Chk reference capturing:

  • log.Writer() io.Writer
  • os.Stderr

which must be tested by calling the methods:

  • (*Chk).Log(wantLines ...string) bool
  • (*Chk).Stderr(wantLines ...string) bool

before (*Chk).Release() is invoked.

func CaptureLogAndStderrAndStdout(t testingT) *Chk

CaptureLogAndStderrAndStdout returns a new *sztest.Chk reference capturing:

  • log.Writer() io.Writer
  • os.Stderr
  • os.Stdout

which must be tested by calling the methods:

  • (*Chk).Log(wantLines ...string) bool
  • (*Chk).Stderr(wantLines ...string) bool
  • (*Chk).Stdout(wantLines ...string) bool

before (*Chk).Release() is invoked.

func CaptureLogWithStderr(t testingT) *Chk

CaptureLogWithStderr returns a new *sztest.Chk reference combining and capturing:

  • (log.Writer() io.Writer) + os.Stderr

which must be tested by calling ONE the methods:

  • (*Chk).Log(wantLines ...string) bool
  • OR
  • (*Chk).Stderr(wantLines ...string) bool

before (*Chk).Release() is invoked.

func CaptureLogWithStderrAndStdout(t testingT) *Chk

CaptureLogWithStderrAndStdout returns a new *sztest.Chk reference capturing:

  • (log.Writer() io.Writer) + os.Stderr
  • os.Stdout

which must be tested by calling ONE the methods:

  • (*Chk).Log(wantLines ...string) bool
  • OR
  • (*Chk).Stderr(wantLines ...string) bool

and the method:

  • (*Chk).Stdout(wantLines ...string) bool

before (*Chk).Release() is invoked.

func CaptureStderr(t testingT) *Chk

CaptureStderr returns a new *sztest.Chk reference capturing:

  • os.Stderr

which must be tested by calling the method:

  • (*Chk).Stderr(wantLines ...string) bool

before (*Chk).Release() is invoked.

func CaptureStderrAndStdout(t testingT) *Chk

CaptureStderrAndStdout returns a new *sztest.Chk reference capturing:

  • os.Stderr
  • os.Stdout

which must be tested by calling the methods:

  • (*Chk).Stderr(wantLines ...string) bool
  • (*Chk).Stdout(wantLines ...string) bool

before (*Chk).Release() is invoked.

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, min, max byte, msg ...any) bool
func (chk *Chk) Float32Bounded(got float32, option BoundedOption, min, max float32, msg ...any) bool
func (chk *Chk) Float64Bounded(got float64, option BoundedOption, min, max float64, msg ...any) bool
func (chk *Chk) IntBounded(got int, option BoundedOption, min, max int, msg ...any) bool
func (chk *Chk) Int8Bounded(got int8, option BoundedOption, min, max int8, msg ...any) bool
func (chk *Chk) Int16Bounded(got int16, option BoundedOption, min, max int16, msg ...any) bool
func (chk *Chk) Int32Bounded(got int32, option BoundedOption, min, max int32, msg ...any) bool
func (chk *Chk) Int64Bounded(got int64, option BoundedOption, min, max int64, msg ...any) bool
func (chk *Chk) RuneBounded(got rune, option BoundedOption, min, max rune, msg ...any) bool
func (chk *Chk) StrBounded(got string, option BoundedOption, min, max string, msg ...any) bool
func (chk *Chk) UintBounded(got uint, option BoundedOption, min, max uint, msg ...any) bool
func (chk *Chk) Uint8Bounded(got uint8, option BoundedOption, min, max uint8, msg ...any) bool
func (chk *Chk) Uint16Bounded(got uint16, option BoundedOption, min, max uint16, msg ...any) bool
func (chk *Chk) Uint32Bounded(got uint32, option BoundedOption, min, max uint32, msg ...any) bool
func (chk *Chk) Uint64Bounded(got uint64, option BoundedOption, min, max uint64, msg ...any) bool
func (chk *Chk) DurBounded(got time.Duration, option BoundedOption, min, max time.Duration, msg ...any) bool
Bounded Formatted
func (chk *Chk) ByteBoundedf(got byte, option BoundedOption, min, max byte, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Float32Boundedf(got float32, option BoundedOption, min, max float32, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Float64Boundedf(got float64, option BoundedOption, min, max float64, msgFmt string, msgArgs ...any) bool
func (chk *Chk) IntBoundedf(got int, option BoundedOption, min, max int, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Int8Boundedf(got int8, option BoundedOption, min, max int8, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Int16Boundedf(got int16, option BoundedOption, min, max int16, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Int32Boundedf(got int32, option BoundedOption, min, max int32, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Int64Boundedf(got int64, option BoundedOption, min, max int64, msgFmt string, msgArgs ...any) bool
func (chk *Chk) RuneBoundedf(got rune, option BoundedOption, min, max rune, msgFmt string, msgArgs ...any) bool
func (chk *Chk) StrBoundedf(got string, option BoundedOption, min, max string, msgFmt string, msgArgs ...any) bool
func (chk *Chk) UintBoundedf(got uint, option BoundedOption, min, max uint, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Uint8Boundedf(got uint8, option BoundedOption, min, max uint8, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Uint16Boundedf(got uint16, option BoundedOption, min, max uint16, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Uint32Boundedf(got uint32, option BoundedOption, min, max uint32, msgFmt string, msgArgs ...any) bool
func (chk *Chk) Uint64Boundedf(got uint64, option BoundedOption, min, max uint64, msgFmt string, msgArgs ...any) bool
func (chk *Chk) DurBoundedf(got time.Duration, option BoundedOption, min, max 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 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

Appendix I: To Be Documented
func (chk *Chk) FailFast(failFast bool) bool
func (chk *Chk) Logf(msgFmt string, msgArgs ...any)
func (chk *Chk) Errorf(msgFmt string, msgArgs ...any)
func (chk *Chk) Error(args ...any)
func (chk *Chk) Fatalf(msgFmt string, msgArgs ...any)
func (chk *Chk) Name() string
func (chk *Chk) T() testingT
func (chk *Chk) PushPreReleaseFunc(newFunc func() error)
func (chk *Chk) PushPostReleaseFunc(newFunc func() error)
func (chk *Chk) Release()
func CompareArrays[T chkType](got, wnt []T) string
func (*Chk) LastErr(args ...any) error
func (chk *Chk) Log(wantLines ...string) bool
func (chk *Chk) Stderr(wantLines ...string) bool
func (chk *Chk) Stdout(wantLines ...string) bool
func (chk *Chk) SetStdinData(lines ...string)

Errors can be tested using:

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

noting that the got and wnt are different types. Finally, checking for nil pointers or nil references can be tested with:

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

Some checks have helper functions provided for convenience.

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

For a complete list of builtin Got/Wnt tests and their helpers see Appendix B: List of got/wnt Test Methods

Contents

Documentation

Overview

Package sztest implements some general go testing helper functions to provide for cleaner more readable tests as well as automatic diffs of unexpected results. In addition to providing general tests it also provides builtin io interfaces that can be used to simulate io errors for code tests. Finally it provides for the capturing of logs and standard output streams with automatic diffs.

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 (
	ClockSubNone = 0           // No substitutions.
	ClockSubTime = 1 << iota   // {{clkTime#}} = HHmmSS.
	ClockSubDate               // {{clkDate#}} = YYYYMMDD.
	ClockSubTS                 // {{clkTS#}}   = YYYYMMDDHHmmSS.
	ClockSubNano               // {{clkNano#}} = YYYYMMDDHHmmSS.#########.
	ClockSubCusA               // {{clkCusA#}} = definable format string.
	ClockSubCusB               // {{clkCusB#}} = definable format string.
	ClockSubCusC               // {{clkCusC#}} = definable format string.
	ClockSubAll  = math.MaxInt // All defined substitutions.
)

Clock substitutions.

View Source
const (
	DiffWant  = diffType('W')
	DiffGot   = diffType('G')
	DiffMerge = diffType('M')
)

Represents the type of output displayed when diffing strings.

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 CompareArrays

func CompareArrays[T chkType](got, wnt []T) string

CompareArrays returns "" an empty string if there are no differences otherwise it returns a string outlining the differences.

func CompareSlices

func CompareSlices[T chkType](
	title string,
	got, want []T,
	minRunSlice, minRunString int,
	cmp func(a, b T) bool,
	_ func(any) string,
) string

CompareSlices checks two slices for differences.

func DiffSlice

func DiffSlice[T chkType](
	gotSlice, wntSlice []T,
	dFmt *diffLnFmt,
	changed *bool,
	minRunSlice int,
	minRunString int,
	cmp func(a, b T) bool,
) []string

DiffSlice compares two Slices.

func DiffString

func DiffString(gotStr, wntStr string, dType diffType, minRun int) string

DiffString checks two strings for differences.

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 permitting an application to force certain settings required for embedded runs.

func SettingBufferSize

func SettingBufferSize() int

SettingBufferSize returns the default setting overridden by env settings.

func SettingDiffChars

func SettingDiffChars() int

SettingDiffChars returns the default setting overridden by env settings.

func SettingDiffSlice

func SettingDiffSlice() int

SettingDiffSlice returns the default setting overridden by env settings.

func SettingFailFast

func SettingFailFast() bool

SettingFailFast returns the default setting overridden by env settings.

func SettingMarkChgOff

func SettingMarkChgOff() string

SettingMarkChgOff returns the default setting overridden by env settings.

func SettingMarkChgOn

func SettingMarkChgOn() string

SettingMarkChgOn returns the default setting overridden by env settings.

func SettingMarkDelOff

func SettingMarkDelOff() string

SettingMarkDelOff returns the default setting overridden by env settings.

func SettingMarkDelOn

func SettingMarkDelOn() string

SettingMarkDelOn returns the default setting overridden by env settings.

func SettingMarkGotOff

func SettingMarkGotOff() string

SettingMarkGotOff returns the default setting overridden by env settings.

func SettingMarkGotOn

func SettingMarkGotOn() string

SettingMarkGotOn returns the default setting overridden by env settings.

func SettingMarkInsOff

func SettingMarkInsOff() string

SettingMarkInsOff returns the default setting overridden by env settings.

func SettingMarkInsOn

func SettingMarkInsOn() string

SettingMarkInsOn returns the default setting overridden by env settings.

func SettingMarkMsgOff

func SettingMarkMsgOff() string

SettingMarkMsgOff returns the default setting overridden by env settings.

func SettingMarkMsgOn

func SettingMarkMsgOn() string

SettingMarkMsgOn returns the default setting overridden by env settings.

func SettingMarkSepOff

func SettingMarkSepOff() string

SettingMarkSepOff returns the default setting overridden by env settings.

func SettingMarkSepOn

func SettingMarkSepOn() string

SettingMarkSepOn returns the default setting overridden by env settings.

func SettingMarkWntOff

func SettingMarkWntOff() string

SettingMarkWntOff returns the default setting overridden by env settings.

func SettingMarkWntOn

func SettingMarkWntOn() string

SettingMarkWntOn returns the default setting overridden by env settings.

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 constant type.

const (
	// BoundedOpen (a,b) = { x | a < x < b }.
	BoundedOpen BoundedOption = iota
	// BoundedClosed [a,b] = { x | a ≦ x ≦ b }.
	BoundedClosed
	// BoundedMinOpen (a,b] = { x | a < x ≦ b }.
	BoundedMinOpen
	// BoundedMaxClosed (a,b] = { x | a < x ≦ b }.
	BoundedMaxClosed
	// BoundedMaxOpen [a,b) = { x | a ≦ x < b }.
	BoundedMaxOpen
	// BoundedMinClosed [a,b) = { x | a ≦ x < b }.
	BoundedMinClosed
)

type Chk

type Chk struct {
	// contains filtered or unexported fields
}

Chk structure provides a selector and data to perform testing functions.

func CaptureLog

func CaptureLog(t testingT) *Chk

CaptureLog returns a new *sztest.Chk reference capturing:

- log.Writer() io.Writer

which must be tested by calling the methods:

- (*Chk).Log(wantLines ...string) bool

before (*Chk).Release() is invoked.

func CaptureLogAndStderr

func CaptureLogAndStderr(t testingT) *Chk

CaptureLogAndStderr returns a new *sztest.Chk reference capturing:

- log.Writer() io.Writer - os.Stderr

which must be tested by calling the methods:

- (*Chk).Log(wantLines ...string) bool - (*Chk).Stderr(wantLines ...string) bool

before (*Chk).Release() is invoked.

func CaptureLogAndStderrAndStdout

func CaptureLogAndStderrAndStdout(t testingT) *Chk

CaptureLogAndStderrAndStdout returns a new *sztest.Chk reference capturing:

- log.Writer() io.Writer - os.Stderr - os.Stdout

which must be tested by calling the methods:

- (*Chk).Log(wantLines ...string) bool - (*Chk).Stderr(wantLines ...string) bool - (*Chk).Stdout(wantLines ...string) bool

before (*Chk).Release() is invoked.

func CaptureLogAndStdout

func CaptureLogAndStdout(t testingT) *Chk

CaptureLogAndStdout returns a new *sztest.Chk reference capturing:

- log.Writer() io.Writer - os.Stdout

which must be tested by calling the methods:

- (*Chk).Log(wantLines ...string) bool - (*Chk).Stdout(wantLines ...string) bool

before (*Chk).Release() is invoked.

func CaptureLogWithStderr

func CaptureLogWithStderr(t testingT) *Chk

CaptureLogWithStderr returns a new *sztest.Chk reference combining and capturing:

- (log.Writer() io.Writer) + os.Stderr

which must be tested by calling ONE the methods:

- (*Chk).Log(wantLines ...string) bool - OR - (*Chk).Stderr(wantLines ...string) bool

before (*Chk).Release() is invoked.

func CaptureLogWithStderrAndStdout

func CaptureLogWithStderrAndStdout(t testingT) *Chk

CaptureLogWithStderrAndStdout returns a new *sztest.Chk reference capturing:

- (log.Writer() io.Writer) + os.Stderr - os.Stdout

which must be tested by calling ONE the methods:

- (*Chk).Log(wantLines ...string) bool - OR - (*Chk).Stderr(wantLines ...string) bool

and the method:

- (*Chk).Stdout(wantLines ...string) bool

before (*Chk).Release() is invoked.

func CaptureNothing

func CaptureNothing(t testingT) *Chk

CaptureNothing returns a new sztest object without any logs or standard io being captured.

func CaptureStderr

func CaptureStderr(t testingT) *Chk

CaptureStderr returns a new *sztest.Chk reference capturing:

- os.Stderr

which must be tested by calling the method:

- (*Chk).Stderr(wantLines ...string) bool

before (*Chk).Release() is invoked.

func CaptureStderrAndStdout

func CaptureStderrAndStdout(t testingT) *Chk

CaptureStderrAndStdout returns a new *sztest.Chk reference capturing:

- os.Stderr - os.Stdout

which must be tested by calling the methods:

- (*Chk).Stderr(wantLines ...string) bool - (*Chk).Stdout(wantLines ...string) bool

before (*Chk).Release() is invoked.

func CaptureStdout

func CaptureStdout(t testingT) *Chk

CaptureStdout returns a new *sztest.Chk reference capturing:

- os.Stdout

which must be tested by calling the methods:

- (*Chk).Stdout(wantLines ...string) bool

before (*Chk).Release() is invoked.

func (*Chk) AddSub

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

AddSub compiles and adds a new regexp and substitute string.

func (*Chk) Bool

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

Bool compare the wanted boolean against the gotten bool invoking an error should they not match.

func (*Chk) BoolSlice

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

BoolSlice checks two boolean slices for equality.

func (*Chk) BoolSlicef

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

BoolSlicef checks two boolean slices for equality.

func (*Chk) Boolf

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

Boolf compare the wanted boolean against the gotten bool invoking an error should they not match.

func (*Chk) Byte

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

Byte compares the wanted byte against the gotten byte invoking an error should they not match.

func (*Chk) ByteBounded

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

ByteBounded checks value is within specified bounded range.

func (*Chk) ByteBoundedf

func (chk *Chk) ByteBoundedf(
	got byte,
	option BoundedOption,
	minV, maxV byte,
	msgFmt string, msgArgs ...any,
) bool

ByteBoundedf checks value is within specified bounded range.

func (*Chk) ByteSlice

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

ByteSlice checks two byte slices for equality.

func (*Chk) ByteSlicef

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

ByteSlicef checks two byte slices for equality.

func (*Chk) ByteUnbounded

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

ByteUnbounded checks value is within specified unbounded range.

func (*Chk) ByteUnboundedf

func (chk *Chk) ByteUnboundedf(
	got byte,
	option UnboundedOption,
	bound byte,
	msgFmt string, msgArgs ...any,
) bool

ByteUnboundedf checks value is within specified unbounded range.

func (*Chk) Bytef

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

Bytef compares the wanted byte against the gotten byte invoking an error should they not match.

func (*Chk) CaptureFlagUsage

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

CaptureFlagUsage is a convenience function that captures the output of the provided *flag.FlagSet.

func (*Chk) ClockAddSub

func (chk *Chk) ClockAddSub(i int)

ClockAddSub sets the fields to set substitutions for.

func (*Chk) ClockLast

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

ClockLast returns the last timestamp generated.

func (*Chk) ClockLastFmtCusA

func (chk *Chk) ClockLastFmtCusA() string

ClockLastFmtCusA returns the last time generated in the indicated format.

func (*Chk) ClockLastFmtCusB

func (chk *Chk) ClockLastFmtCusB() string

ClockLastFmtCusB returns the last time generated in the indicated format.

func (*Chk) ClockLastFmtCusC

func (chk *Chk) ClockLastFmtCusC() string

ClockLastFmtCusC returns the last time generated in the indicated format.

func (*Chk) ClockLastFmtDate

func (chk *Chk) ClockLastFmtDate() string

ClockLastFmtDate returns the last time generated in the indicated format.

func (*Chk) ClockLastFmtNano

func (chk *Chk) ClockLastFmtNano() string

ClockLastFmtNano returns the last time generated in the indicated format.

func (*Chk) ClockLastFmtTS

func (chk *Chk) ClockLastFmtTS() string

ClockLastFmtTS returns the last time generated in the indicated format.

func (*Chk) ClockLastFmtTime

func (chk *Chk) ClockLastFmtTime() string

ClockLastFmtTime returns the last time generated in the indicated format.

func (*Chk) ClockNext

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

ClockNext returns the current time or the next time sequence if a clock has been set.

func (*Chk) ClockNextFmtCusA

func (chk *Chk) ClockNextFmtCusA() string

ClockNextFmtCusA returns the last time generated in the indicated format.

func (*Chk) ClockNextFmtCusB

func (chk *Chk) ClockNextFmtCusB() string

ClockNextFmtCusB returns the last time generated in the indicated format.

func (*Chk) ClockNextFmtCusC

func (chk *Chk) ClockNextFmtCusC() string

ClockNextFmtCusC returns the last time generated in the indicated format.

func (*Chk) ClockNextFmtDate

func (chk *Chk) ClockNextFmtDate() string

ClockNextFmtDate returns the last time generated in the indicated format.

func (*Chk) ClockNextFmtNano

func (chk *Chk) ClockNextFmtNano() string

ClockNextFmtNano returns the last time generated in the indicated format.

func (*Chk) ClockNextFmtTS

func (chk *Chk) ClockNextFmtTS() string

ClockNextFmtTS returns the last time generated in the indicated format.

func (*Chk) ClockNextFmtTime

func (chk *Chk) ClockNextFmtTime() string

ClockNextFmtTime returns the last time generated in the indicated format.

func (*Chk) ClockOffset

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

ClockOffset moves the current clock by the specified amount. No defined increments are applied and if a clock has not yet been set the current time advanced by the specified amount will be used. Nothing is returned.

func (*Chk) ClockOffsetDay

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

ClockOffsetDay adjusts the current clock by the number of specified days with negative numbers representing the past. It returns a func to reset the clk back to its state when this function was called.

func (*Chk) ClockRemoveSub

func (chk *Chk) ClockRemoveSub(i int)

ClockRemoveSub resets the fields to set substitutions for.

func (*Chk) ClockSet

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

ClockSet set the current test time and optionally sets the increments if provided. It returns a func to reset the clk back to its state when this function was called.

func (*Chk) ClockSetCusA

func (chk *Chk) ClockSetCusA(f string)

ClockSetCusA sets the custom date format to set tick substitution values.

func (*Chk) ClockSetCusB

func (chk *Chk) ClockSetCusB(f string)

ClockSetCusB sets the custom date format to set tick substitution values.

func (*Chk) ClockSetCusC

func (chk *Chk) ClockSetCusC(f string)

ClockSetCusC sets the custom date format to set tick substitution values.

func (*Chk) ClockSetSub

func (chk *Chk) ClockSetSub(i int)

ClockSetSub sets the fields to set substitutions for.

func (*Chk) ClockTick

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

ClockTick returns i'th time returned.

func (*Chk) Close

func (chk *Chk) Close() error

Close implements the interface to simulate a close operation returning an error if provided.

func (*Chk) Complex64

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

Complex64 compares the wanted complex64 against the gotten complex64 invoking an error should they not match.

func (*Chk) Complex64Slice

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

Complex64Slice checks two complex64 slices for equality.

func (*Chk) Complex64Slicef

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

Complex64Slicef checks two complex64 slices for equality.

func (*Chk) Complex64f

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

Complex64f compares the wanted complex64 against the gotten complex64 invoking an error should they not match.

func (*Chk) Complex128

func (chk *Chk) Complex128(got, want complex128, msg ...any) bool

Complex128 compares the wanted complex128 against the gotten complex128 invoking an error should they not match.

func (*Chk) Complex128Slice

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

Complex128Slice checks two complex128 slices for equality.

func (*Chk) Complex128Slicef

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

Complex128Slicef checks two complex128 slices for equality.

func (*Chk) Complex128f

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

Complex128f compares the wanted complex128 against the gotten complex128 invoking an error should they not match.

func (*Chk) CreateTmpDir

func (chk *Chk) CreateTmpDir() string

CreateTmpDir creates a temporary test directory using the test functions name in the /tmp directory.

func (*Chk) CreateTmpFile

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

CreateTmpFile removes and creates the named directory with the provided permissions.

func (*Chk) CreateTmpFileAs

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

CreateTmpFileAs removes and creates the named file in the provided path.

func (*Chk) CreateTmpFileIn

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

CreateTmpFileIn removes and creates a tmp file in the provided path.

func (*Chk) CreateTmpSubDir

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

CreateTmpSubDir creates a temporary test directory using the test functions name in the /tmp directory.

func (*Chk) CreateTmpUnixScript

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

CreateTmpUnixScript removes and creates the named directory with the provided permissions.

func (*Chk) CreateTmpUnixScriptAs

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

CreateTmpUnixScriptAs removes and creates the named script with the provided permissions.

func (*Chk) CreateTmpUnixScriptIn

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

CreateTmpUnixScriptIn removes and creates the generated script name with the provided permissions.

func (*Chk) DelEnv

func (chk *Chk) DelEnv(name string)

DelEnv removes the env variable if it exists. Any changes are reversed when chk.Release() is called.

func (*Chk) Dur

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

Dur compare the wanted boolean against the gotten bool invoking an error should they not match.

func (*Chk) DurBounded

func (chk *Chk) DurBounded(
	got time.Duration,
	option BoundedOption,
	minV, maxV time.Duration,
	msg ...any,
) bool

DurBounded checks value is within specified bounded range.

func (*Chk) DurBoundedf

func (chk *Chk) DurBoundedf(
	got time.Duration, option BoundedOption, minV, maxV time.Duration,
	msgFmt string, msgArgs ...any,
) bool

DurBoundedf checks value is within specified bounded range.

func (*Chk) DurSlice

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

DurSlice checks two time.Duration slices for equality.

func (*Chk) DurSlicef

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

DurSlicef checks two time.Duration slices for equality.

func (*Chk) DurUnbounded

func (chk *Chk) DurUnbounded(
	got time.Duration, option UnboundedOption, bound time.Duration, msg ...any,
) bool

DurUnbounded checks value is within specified unbounded range.

func (*Chk) DurUnboundedf

func (chk *Chk) DurUnboundedf(
	got time.Duration, option UnboundedOption, bound time.Duration,
	msgFmt string, msgArgs ...any,
) bool

DurUnboundedf checks value is within specified unbounded range.

func (*Chk) Durf

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

Durf compare the wanted boolean against the gotten bool invoking an error should they not match.

func (*Chk) Err

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

Err compare the gotten error against the wanted error string. If either "" or "<nil>" is wanted the error should be a nil.

func (*Chk) ErrChain added in v0.1.1

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

ErrChain returns a string concatenating all of the errors and strings with the separator.

func (*Chk) ErrSlice

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

ErrSlice compare the gotten error against the wanted error string. If either "" or "<nil>" is wanted the error should be a nil.

func (*Chk) ErrSlicef

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

ErrSlicef compare the gotten error against the wanted error string. If either "" or "<nil>" is wanted the error should be a nil.

func (*Chk) Errf

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

Errf compare the gotten error against the wanted error string. If either "" or "<nil>" is wanted the error should be a nil.

func (*Chk) Error

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

Error passthrough to t.

func (*Chk) Errorf

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

Errorf passthrough to t.

func (*Chk) FailFast

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

FailFast sets the action takin after an error is discovered.

func (*Chk) False

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

False simply invokes Bool with want set to true.

func (*Chk) Falsef

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

Falsef simply invokes Bool with want set to true and msg formatted.

func (*Chk) Fatalf

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

Fatalf passthrough to t.

func (*Chk) Float32

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

Float32 compares the wanted boolean against the gotten bool invoking an error should they not match.

func (*Chk) Float32Bounded

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

Float32Bounded checks value is within specified bounded range.

func (*Chk) Float32Boundedf

func (chk *Chk) Float32Boundedf(
	got float32, option BoundedOption, minV, maxV float32,
	msgFmt string, msgArgs ...any,
) bool

Float32Boundedf checks value is within specified bounded range.

func (*Chk) Float32Slice

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

Float32Slice compare the wanted boolean against the gotten bool invoking an error should they not match.

func (*Chk) Float32Slicef

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

Float32Slicef compare the wanted boolean against the gotten bool invoking an error should they not match.

func (*Chk) Float32Unbounded

func (chk *Chk) Float32Unbounded(
	got float32, option UnboundedOption, bound float32, msg ...any,
) bool

Float32Unbounded checks value is within specified unbounded range.

func (*Chk) Float32Unboundedf

func (chk *Chk) Float32Unboundedf(
	got float32, option UnboundedOption, bound float32,
	msgFmt string, msgArgs ...any,
) bool

Float32Unboundedf checks value is within specified unbounded range.

func (*Chk) Float32f

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

Float32f compare the wanted boolean against the gotten bool invoking an error should they not match.

func (*Chk) Float64

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

Float64 compare the wanted boolean against the gotten bool invoking an error should they not match.

func (*Chk) Float64Bounded

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

Float64Bounded checks value is within specified bounded range.

func (*Chk) Float64Boundedf

func (chk *Chk) Float64Boundedf(
	got float64, option BoundedOption, minV, maxV float64,
	msgFmt string, msgArgs ...any,
) bool

Float64Boundedf checks value is within specified bounded range.

func (*Chk) Float64Slice

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

Float64Slice compare the wanted boolean against the gotten bool invoking an error should they not match.

func (*Chk) Float64Slicef

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

Float64Slicef compare the wanted boolean against the gotten bool invoking an error should they not match.

func (*Chk) Float64Unbounded

func (chk *Chk) Float64Unbounded(
	got float64, option UnboundedOption, bound float64, msg ...any,
) bool

Float64Unbounded checks value is within specified unbounded range.

func (*Chk) Float64Unboundedf

func (chk *Chk) Float64Unboundedf(
	got float64, option UnboundedOption, bound float64,
	msgFmt string, msgArgs ...any,
) bool

Float64Unboundedf checks value is within specified unbounded range.

func (*Chk) Float64f

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

Float64f compare the wanted boolean against the gotten bool invoking an error should they not match.

func (*Chk) GetIOWriterData

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

GetIOWriterData returns the bytes received on the ioWriter interface.

func (*Chk) Int

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

Int compares the wanted int against the gotten int invoking an error should they not match.

func (*Chk) Int8

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

Int8 compares the wanted int8 against the gotten int8 invoking an error should they not match.

func (*Chk) Int8Bounded

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

Int8Bounded checks value is within specified bounded range.

func (*Chk) Int8Boundedf

func (chk *Chk) Int8Boundedf(
	got int8,
	option BoundedOption,
	minV, maxV int8,
	msgFmt string, msgArgs ...any,
) bool

Int8Boundedf checks value is within specified bounded range.

func (*Chk) Int8Slice

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

Int8Slice checks two int8 slices for equality.

func (*Chk) Int8Slicef

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

Int8Slicef checks two int8 slices for equality.

func (*Chk) Int8Unbounded

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

Int8Unbounded checks value is within specified unbounded range.

func (*Chk) Int8Unboundedf

func (chk *Chk) Int8Unboundedf(
	got int8,
	option UnboundedOption,
	bound int8,
	msgFmt string, msgArgs ...any,
) bool

Int8Unboundedf checks value is within specified unbounded range.

func (*Chk) Int8f

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

Int8f compares the wanted int8 against the gotten int8 invoking an error should they not match.

func (*Chk) Int16

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

Int16 compares the wanted int16 against the gotten int16 invoking an error should they not match.

func (*Chk) Int16Bounded

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

Int16Bounded checks value is within specified bounded range.

func (*Chk) Int16Boundedf

func (chk *Chk) Int16Boundedf(
	got int16, option BoundedOption, minV, maxV int16,
	msgFmt string, msgArgs ...any,
) bool

Int16Boundedf checks value is within specified bounded range.

func (*Chk) Int16Slice

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

Int16Slice checks two int16 slices for equality.

func (*Chk) Int16Slicef

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

Int16Slicef checks two int16 slices for equality.

func (*Chk) Int16Unbounded

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

Int16Unbounded checks value is within specified unbounded range.

func (*Chk) Int16Unboundedf

func (chk *Chk) Int16Unboundedf(
	got int16, option UnboundedOption, bound int16,
	msgFmt string, msgArgs ...any,
) bool

Int16Unboundedf checks value is within specified unbounded range.

func (*Chk) Int16f

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

Int16f compares the wanted int16 against the gotten int16 invoking an error should they not match.

func (*Chk) Int32

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

Int32 compares the wanted int32 against the gotten int32 invoking an error should they not match.

func (*Chk) Int32Bounded

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

Int32Bounded checks value is within specified bounded range.

func (*Chk) Int32Boundedf

func (chk *Chk) Int32Boundedf(
	got int32, option BoundedOption, minV, maxV int32,
	msgFmt string, msgArgs ...any,
) bool

Int32Boundedf checks value is within specified bounded range.

func (*Chk) Int32Slice

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

Int32Slice checks two int32 slices for equality.

func (*Chk) Int32Slicef

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

Int32Slicef checks two int32 slices for equality.

func (*Chk) Int32Unbounded

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

Int32Unbounded checks value is within specified unbounded range.

func (*Chk) Int32Unboundedf

func (chk *Chk) Int32Unboundedf(
	got int32, option UnboundedOption, bound int32,
	msgFmt string, msgArgs ...any,
) bool

Int32Unboundedf checks value is within specified unbounded range.

func (*Chk) Int32f

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

Int32f compares the wanted int32 against the gotten int32 invoking an error should they not match.

func (*Chk) Int64

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

Int64 compares the wanted int64 against the gotten int64 invoking an error should they not match.

func (*Chk) Int64Bounded

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

Int64Bounded checks value is within specified bounded range.

func (*Chk) Int64Boundedf

func (chk *Chk) Int64Boundedf(
	got int64, option BoundedOption, minV, maxV int64,
	msgFmt string, msgArgs ...any,
) bool

Int64Boundedf checks value is within specified bounded range.

func (*Chk) Int64Slice

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

Int64Slice checks two int64 slices for equality.

func (*Chk) Int64Slicef

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

Int64Slicef checks two int64 slices for equality.

func (*Chk) Int64Unbounded

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

Int64Unbounded checks value is within specified unbounded range.

func (*Chk) Int64Unboundedf

func (chk *Chk) Int64Unboundedf(
	got int64, option UnboundedOption, bound int64,
	msgFmt string, msgArgs ...any,
) bool

Int64Unboundedf checks value is within specified unbounded range.

func (*Chk) Int64f

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

Int64f compares the wanted int64 against the gotten int64 invoking an error should they not match.

func (*Chk) IntBounded

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

IntBounded checks value is within specified bounded range.

func (*Chk) IntBoundedf

func (chk *Chk) IntBoundedf(
	got int, option BoundedOption, minV, maxV int,
	msgFmt string, msgArgs ...any,
) bool

IntBoundedf checks value is within specified bounded range.

func (*Chk) IntSlice

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

IntSlice checks two int slices for equality.

func (*Chk) IntSlicef

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

IntSlicef checks two int slices for equality.

func (*Chk) IntUnbounded

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

IntUnbounded checks value is within specified unbounded range.

func (*Chk) IntUnboundedf

func (chk *Chk) IntUnboundedf(
	got int, option UnboundedOption, bound int, msgFmt string, msgArgs ...any,
) bool

IntUnboundedf checks value is within specified unbounded range.

func (*Chk) Intf

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

Intf compares the wanted int against the gotten int invoking an error should they not match.

func (*Chk) KeepTmpFiles

func (chk *Chk) KeepTmpFiles()

KeepTmpFiles stops the removal of tmp files when the check is fault free.

func (*Chk) LastErr

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

LastErr returns the last argument in the list as an error. If there are no arguments or the last parameter is not an Error interface then ErrInvalidLastErrArg is returned.

func (*Chk) Log

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

Log checks the internally captured log data with the supplied list.

func (*Chk) Logf

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

Logf passthrough to t.

func (*Chk) Name

func (chk *Chk) Name() string

Name returns the name of the saved test object.

func (*Chk) Nil

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

Nil checks that the interface value is nil.

func (*Chk) Nilf

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

Nilf checks that the interface value is nil with formatted msg.

func (*Chk) NoErr

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

NoErr simply invokes Err with want set to "".

func (*Chk) NoErrf

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

NoErrf simply invokes Err with want set to "" and msg formatted.

func (*Chk) NoPanic

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

NoPanic simply invokes Err with want set to "".

func (*Chk) NoPanicf

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

NoPanicf simply invokes Panic with want set to "" and msg formatted.

func (*Chk) NotNil

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

NotNil checks that the interface value is nil.

func (*Chk) NotNilf

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

NotNilf checks that the interface value is nil with formatted msg.

func (*Chk) Panic

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

Panic runs the supplied function and compares the panic value asserted to the supplied string.

func (*Chk) Panicf

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

Panicf runs the supplied function and compares the panic value asserted to the supplied string.

func (*Chk) PushPostReleaseFunc

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

PushPostReleaseFunc adds a new release function to the end of the queue.

func (*Chk) PushPreReleaseFunc

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

PushPreReleaseFunc adds a new release function to the front of the queue.

func (*Chk) Read

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

Read implements the ioReader interface.

func (*Chk) Release

func (chk *Chk) Release()

Release invokes all pushed release functions.

func (*Chk) Rune

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

Rune compares the wanted rune against the gotten rune invoking an error should they not match.

func (*Chk) RuneBounded

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

RuneBounded checks value is within specified bounded range.

func (*Chk) RuneBoundedf

func (chk *Chk) RuneBoundedf(
	got rune,
	option BoundedOption,
	minV, maxV rune,
	msgFmt string, msgArgs ...any,
) bool

RuneBoundedf checks value is within specified bounded range.

func (*Chk) RuneSlice

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

RuneSlice checks two rune slices for equality.

func (*Chk) RuneSlicef

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

RuneSlicef checks two rune slices for equality.

func (*Chk) RuneUnbounded

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

RuneUnbounded checks value is within specified unbounded range.

func (*Chk) RuneUnboundedf

func (chk *Chk) RuneUnboundedf(
	got rune,
	option UnboundedOption,
	bound rune,
	msgFmt string, msgArgs ...any,
) bool

RuneUnboundedf checks value is within specified unbounded range.

func (*Chk) Runef

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

Runef compares the wanted rune against the gotten rune invoking an error should they not match.

func (*Chk) Seek

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

Seek implements the interface to simulate a Seek operation returning an error if provided.

func (*Chk) SetArgs added in v0.0.1

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

SetArgs invokes the current arguments in os.Args and flag.CommandLine. Package variable os.Args is set to the provided arguments and a new flag set is assigned to flag.CommandLine and is ready to use. Original values are restores with the chk object is released.

func (*Chk) SetCloseError

func (chk *Chk) SetCloseError(err error)

SetCloseError primes the chk object to return the provided error.

func (*Chk) SetEnv

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

SetEnv adds or modifies the names environment variable to the specified value. Any Changes made are reset when chk.Release() is called.

func (*Chk) SetIOReaderData

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

SetIOReaderData initializes the IO reader interface for testing.

func (*Chk) SetIOReaderError

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

SetIOReaderError initializes the IO reader to return en error after the specified number of bytes have been read.

func (*Chk) SetIOWriterError

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

SetIOWriterError provides to limit the amount of bytes that will be read before an error (or the supplied error will be returned.)

func (*Chk) SetPermDir

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

SetPermDir changes the os.FileMode used when creating directories and returns the current value.

func (*Chk) SetPermExe

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

SetPermExe changes the os.FileMode used when creating directories and returns the current value.

func (*Chk) SetPermFile

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

SetPermFile changes the os.FileMode used when creating directories and returns the current value.

func (*Chk) SetReadError

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

SetReadError primes the chk object to return the provided error on the next read operation.

func (*Chk) SetSeekError

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

SetSeekError primes the chk object to return the provided error.

func (*Chk) SetStdinData

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

SetStdinData sets the os.Stdin to stream the provided data.

func (*Chk) SetTmpDir

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

SetTmpDir changes the root directory used when creating directories and returns the current value.

func (*Chk) SetWriteError

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

SetWriteError primes the chk object to return the provided error on the next Write operation.

func (*Chk) Stderr

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

Stderr checks the internally captured log data with the supplied list.

func (*Chk) Stdout

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

Stdout checks the internally captured log data with the supplied list.

func (*Chk) Str

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

Str compare the wanted boolean against the gotten bool invoking an error should they not match.

func (*Chk) StrBounded

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

StrBounded checks value is within specified bounded range.

func (*Chk) StrBoundedf

func (chk *Chk) StrBoundedf(
	got string, option BoundedOption, minV, maxV string,
	msgFmt string, msgArgs ...any,
) bool

StrBoundedf checks value is within specified bounded range.

func (*Chk) StrSlice

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

StrSlice checks two string slices for equality.

func (*Chk) StrSlicef

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

StrSlicef checks two string slices for equality.

func (*Chk) StrUnbounded

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

StrUnbounded checks value is within specified unbounded range.

func (*Chk) StrUnboundedf

func (chk *Chk) StrUnboundedf(
	got string, option UnboundedOption, bound string,
	msgFmt string, msgArgs ...any,
) bool

StrUnboundedf checks value is within specified unbounded range.

func (*Chk) Strf

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

Strf compare the wanted boolean against the gotten bool invoking an error should they not match.

func (*Chk) T

func (chk *Chk) T() testingT

T returns an interface to sztest object provided on creation.

func (*Chk) True

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

True simply invokes Bool with want set to true.

func (*Chk) Truef

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

Truef simply invokes Bool with want set to true and msg formatted.

func (*Chk) Uint

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

Uint compares the wanted uint against the gotten uint invoking an error should they not match.

func (*Chk) Uint8

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

Uint8 compares the wanted uint8 against the gotten uint8 invoking an error should they not match.

func (*Chk) Uint8Bounded

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

Uint8Bounded checks value is within specified bounded range.

func (*Chk) Uint8Boundedf

func (chk *Chk) Uint8Boundedf(
	got uint8, option BoundedOption, minV, maxV uint8,
	msgFmt string, msgArgs ...any,
) bool

Uint8Boundedf checks value is within specified bounded range.

func (*Chk) Uint8Slice

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

Uint8Slice checks two uint8 slices for equality.

func (*Chk) Uint8Slicef

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

Uint8Slicef checks two uint8 slices for equality.

func (*Chk) Uint8Unbounded

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

Uint8Unbounded checks value is within specified unbounded range.

func (*Chk) Uint8Unboundedf

func (chk *Chk) Uint8Unboundedf(
	got uint8, option UnboundedOption, bound uint8,
	msgFmt string, msgArgs ...any,
) bool

Uint8Unboundedf checks value is within specified unbounded range.

func (*Chk) Uint8f

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

Uint8f compares the wanted uint8 against the gotten uint8 invoking an error should they not match.

func (*Chk) Uint16

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

Uint16 compares the wanted uint16 against the gotten uint16 invoking an error should they not match.

func (*Chk) Uint16Bounded

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

Uint16Bounded checks value is within specified bounded range.

func (*Chk) Uint16Boundedf

func (chk *Chk) Uint16Boundedf(
	got uint16, option BoundedOption, minV, maxV uint16,
	msgFmt string, msgArgs ...any,
) bool

Uint16Boundedf checks value is within specified bounded range.

func (*Chk) Uint16Slice

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

Uint16Slice checks two uint16 slices for equality.

func (*Chk) Uint16Slicef

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

Uint16Slicef checks two uint16 slices for equality.

func (*Chk) Uint16Unbounded

func (chk *Chk) Uint16Unbounded(
	got uint16, option UnboundedOption, bound uint16, msg ...any,
) bool

Uint16Unbounded checks value is within specified unbounded range.

func (*Chk) Uint16Unboundedf

func (chk *Chk) Uint16Unboundedf(
	got uint16, option UnboundedOption, bound uint16,
	msgFmt string, msgArgs ...any,
) bool

Uint16Unboundedf checks value is within specified unbounded range.

func (*Chk) Uint16f

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

Uint16f compares the wanted uint16 against the gotten uint16 invoking an error should they not match.

func (*Chk) Uint32

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

Uint32 compares the wanted uint32 against the gotten uint32 invoking an error should they not match.

func (*Chk) Uint32Bounded

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

Uint32Bounded checks value is within specified bounded range.

func (*Chk) Uint32Boundedf

func (chk *Chk) Uint32Boundedf(
	got uint32, option BoundedOption, minV, maxV uint32,
	msgFmt string, msgArgs ...any,
) bool

Uint32Boundedf checks value is within specified bounded range.

func (*Chk) Uint32Slice

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

Uint32Slice checks two uint32 slices for equality.

func (*Chk) Uint32Slicef

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

Uint32Slicef checks two uint32 slices for equality.

func (*Chk) Uint32Unbounded

func (chk *Chk) Uint32Unbounded(
	got uint32, option UnboundedOption, bound uint32, msg ...any,
) bool

Uint32Unbounded checks value is within specified unbounded range.

func (*Chk) Uint32Unboundedf

func (chk *Chk) Uint32Unboundedf(
	got uint32, option UnboundedOption, bound uint32,
	msgFmt string, msgArgs ...any,
) bool

Uint32Unboundedf checks value is within specified unbounded range.

func (*Chk) Uint32f

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

Uint32f compares the wanted uint32 against the gotten uint32 invoking an error should they not match.

func (*Chk) Uint64

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

Uint64 compares the wanted uint64 against the gotten uint64 invoking an error should they not match.

func (*Chk) Uint64Bounded

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

Uint64Bounded checks value is within specified bounded range.

func (*Chk) Uint64Boundedf

func (chk *Chk) Uint64Boundedf(
	got uint64, option BoundedOption, minV, maxV uint64,
	msgFmt string, msgArgs ...any,
) bool

Uint64Boundedf checks value is within specified bounded range.

func (*Chk) Uint64Slice

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

Uint64Slice checks two uint64 slices for equality.

func (*Chk) Uint64Slicef

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

Uint64Slicef checks two uint64 slices for equality.

func (*Chk) Uint64Unbounded

func (chk *Chk) Uint64Unbounded(
	got uint64, option UnboundedOption, bound uint64, msg ...any,
) bool

Uint64Unbounded checks value is within specified unbounded range.

func (*Chk) Uint64Unboundedf

func (chk *Chk) Uint64Unboundedf(
	got uint64, option UnboundedOption, bound uint64,
	msgFmt string, msgArgs ...any,
) bool

Uint64Unboundedf checks value is within specified unbounded range.

func (*Chk) Uint64f

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

Uint64f compares the wanted uint64 against the gotten uint64 invoking an error should they not match.

func (*Chk) UintBounded

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

UintBounded checks value is within specified bounded range.

func (*Chk) UintBoundedf

func (chk *Chk) UintBoundedf(
	got uint,
	option BoundedOption,
	minV, maxV uint,
	msgFmt string, msgArgs ...any,
) bool

UintBoundedf checks value is within specified bounded range.

func (*Chk) UintSlice

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

UintSlice checks two uint slices for equality.

func (*Chk) UintSlicef

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

UintSlicef checks two uint slices for equality.

func (*Chk) UintUnbounded

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

UintUnbounded checks value is within specified unbounded range.

func (*Chk) UintUnboundedf

func (chk *Chk) UintUnboundedf(
	got uint,
	option UnboundedOption,
	bound uint,
	msgFmt string, msgArgs ...any,
) bool

UintUnboundedf checks value is within specified unbounded range.

func (*Chk) Uintf

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

Uintf compares the wanted uint against the gotten uint invoking an error should they not match.

func (*Chk) Uintptr

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

Uintptr compares the wanted uintptr against the gotten uintptr invoking an error should they not match.

func (*Chk) UintptrSlice

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

UintptrSlice checks two uintptr slices for equality.

func (*Chk) UintptrSlicef

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

UintptrSlicef checks two uintptr slices for equality.

func (*Chk) Uintptrf

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

Uintptrf compares the wanted uintptr against the gotten uintptr invoking an error should they not match.

func (*Chk) Write

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

Write implements the ioReader interface.

type UnboundedOption

type UnboundedOption int

UnboundedOption constant type.

const (
	// UnboundedMinOpen (a,+∞) = { x | x > a }.
	UnboundedMinOpen UnboundedOption = iota
	// UnboundedMinClosed [a,+∞) = { x | x ≧ a }.
	UnboundedMinClosed
	// UnboundedMaxOpen (-∞, b) = { x | x < b }.
	UnboundedMaxOpen
	// UnboundedMaxClosed (-∞, 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