ic

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNullable

func NewNullable(testFiles *map[string]string) (IC, *NullTester, *atomic.Bool, *cmd.OverridableFlagChecker)

func PrintTable

func PrintTable(w io.Writer, table any) error

Types

type DebugStringer

type DebugStringer interface {
	DebugString() string
}

DebugStringer allows for exactly defining the debug string used in tests.

func DebugWrap

func DebugWrap(val any) DebugStringer

func DebugWrapNil

func DebugWrapNil(val any) DebugStringer

func DebugWrapString

func DebugWrapString(val string) DebugStringer

type IC

type IC struct {
	Writer bytes.Buffer
	// contains filtered or unexported fields
}

IC is the test value runner. Create with New(*testing.TB)

func New

func New(t testing.TB) *IC

func (*IC) ClearReplace

func (ic *IC) ClearReplace()

ClearReplace can be used to reset the active replacements

func (*IC) Expect

func (ic *IC) Expect(want string)

Expect will compare the provided string to all the calls to ic.Print* combined. If "want" is an empty string, the library will automatically replace it with the provided value if either is set:

  • "IC_UPDATE" environment variable
  • "-test.icupdate" command line flag is set

Expect will fail the test immediately on failure. ExpectAndContinue can be used to keep running the rest of the test

func (*IC) ExpectAndContinue

func (ic *IC) ExpectAndContinue(want string)

ExpectAndContinue behaves exactly like Expect, with the exception that the test will continue to run on a failure

func (*IC) PS

func (ic *IC) PS()

func (*IC) PT

func (ic *IC) PT(val any)

PT is an alias for PrintTable

func (*IC) PV

func (ic *IC) PV(val any)

PV is an alias for PrintVals

func (*IC) PVWN

func (ic *IC) PVWN(name string, val any)

PVWN is an alias for PrintValWithName

func (*IC) Print

func (ic *IC) Print(output ...any)

func (*IC) PrintSection

func (ic *IC) PrintSection(name string)

func (*IC) PrintSep

func (ic *IC) PrintSep()

func (*IC) PrintTable

func (ic *IC) PrintTable(val any)

PrintTable will take an array of structs and print a table

func (*IC) PrintValWithName

func (ic *IC) PrintValWithName(name string, val any)

PrintValWithName is a simple formatter for testing values

func (*IC) PrintVals

func (ic *IC) PrintVals(val any)

PrintVals will take any struct and call PrintValWithName on each of the exported fields

func (*IC) Printf

func (ic *IC) Printf(format string, a ...any)

func (*IC) PrintfSection

func (ic *IC) PrintfSection(format string, a ...any)

func (*IC) Println

func (ic *IC) Println(output ...any)

func (*IC) Replace

func (ic *IC) Replace(regex string, repl string)

Replace can be used to run a regexp.ReplaceAll on the output before comparison

type NullTester

type NullTester struct {
	Failed bool
	Exited bool
	Output []string
}

NullTester is useful to fake out testing.T in order to verify we handle failures correctly

func NewNullTester

func NewNullTester() *NullTester

func (*NullTester) Fail

func (nt *NullTester) Fail()

func (*NullTester) FailNow

func (nt *NullTester) FailNow()

func (*NullTester) Helper

func (nt *NullTester) Helper()

func (*NullTester) Log

func (nt *NullTester) Log(args ...any)

func (*NullTester) Logf

func (nt *NullTester) Logf(format string, args ...any)

func (*NullTester) Reset

func (nt *NullTester) Reset()

type TT

type TT[T any] struct {
	Name       string
	Have, Want T
}

TT is a test table struct for PrintTable or PrintVals

type TestFileUpdater

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

func NewNullableTestFileUpdater

func NewNullableTestFileUpdater(testFiles *map[string]string) (TestFileUpdater, *atomic.Bool, *cmd.OverridableFlagChecker)

func NewTestFileUpdater

func NewTestFileUpdater() TestFileUpdater

func (TestFileUpdater) Update

func (d TestFileUpdater) Update(ic *IC, got string)

func (TestFileUpdater) UpdateEnabled

func (d TestFileUpdater) UpdateEnabled() bool

type Tester

type Tester interface {
	Fail()
	FailNow()
	Log(args ...any)
	Logf(format string, args ...any)
	Helper()
}

Tester is just the parts of testing.TB that we actually use. See NullTester for handy implementation for tests

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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