testutil

package
v1.3.12 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearImg

func ClearImg(img draw.Image)

func ClearImg2

func ClearImg2(img draw.Image, c color.Color)

func CollectLog

func CollectLog(t *testing.T, fn func() error) ([]byte, []byte, error)

func CollectLog2 added in v1.3.7

func CollectLog2(t *testing.T, logf func(string, ...any), fn func() error) ([]byte, []byte, error)

func CompareImgs

func CompareImgs(img1, img2 image.Image) error

func CompareImgsOrSavePng

func CompareImgsOrSavePng(img1 image.Image, filename2 string) error

func DrawPoint

func DrawPoint(img draw.Image, p image.Point, size int, c color.Color)

func GenerateImg

func GenerateImg(r image.Rectangle, seed int) image.Image

func OpenImage

func OpenImage(filename string) (image.Image, string, error)

func RunArchive

func RunArchive(t *testing.T, ar *Archive, filesExts []string,
	fn func(t2 *testing.T, name string, datas [][]byte) error,
)

Expects n files named in filesExts args

func RunArchive2

func RunArchive2(t *testing.T, ar *Archive,
	fn func(t2 *testing.T, name string, input, output []byte) error,
)

func SPrintImg

func SPrintImg(img image.Image) string

func SPrintImgs

func SPrintImgs(imgs ...image.Image) string

func SourceCursor

func SourceCursor(cursorStr, src string, n int) (string, int, error)

Allows a src string to have multiple cursor strings to simulate cursor position. Used in testing. Useful cursor runes: "●". First n position is zero.

func TrimLineSpaces added in v1.3.7

func TrimLineSpaces(str string) string

Useful to compare src code lines.

func TrimLineSpaces2 added in v1.3.7

func TrimLineSpaces2(str string, pre string) string

Types

type Archive

type Archive struct {
	Tar      *txtar.Archive
	Filename string // for errors
	Lines    []int  // Tar.Files[] line position in src
}

func ParseTxtar

func ParseTxtar(src []byte, filename string) *Archive

func (*Archive) Error

func (ar *Archive) Error(err error, i int) error

type ST added in v1.3.12

type ST struct {
	T   *testing.T
	Env osutil.Envm

	Dir string // current dir

	// collects output for lastcmd
	// error is returned by the func
	Stdout *bytes.Buffer
	Stderr *bytes.Buffer
	// contains filtered or unexported fields
}

func (*ST) DirJoin added in v1.3.12

func (st *ST) DirJoin(fp string) string

func (*ST) Log added in v1.3.12

func (st *ST) Log(s string)

func (*ST) Logf added in v1.3.12

func (st *ST) Logf(f string, args ...any)

func (*ST) Printf added in v1.3.12

func (st *ST) Printf(f string, args ...any)

func (*ST) Println added in v1.3.12

func (st *ST) Println(args ...any)

type Script

type Script struct {
	ScriptsDir     string
	Args           []string
	Cmds           []*ScriptCmd // user cmds (provided)
	Work           bool         // don't remove work dir at end
	NoFilepathsFix bool         // don't rewrite filepaths for current dir
	Parallel       bool

	ScriptStart func(*testing.T) error // each script init
	ScriptStop  func(*testing.T) error // each script close
}

based on txtar (txt archive)

func NewScript

func NewScript(args []string) *Script

func (*Script) Run

func (scr *Script) Run(t *testing.T)

type ScriptCmd

type ScriptCmd struct {
	Name string
	Fn   ScriptCmdFn
}

type ScriptCmdFn added in v1.3.12

type ScriptCmdFn func(st *ST, args []string) error

Jump to

Keyboard shortcuts

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