assertion

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package assertion is the implementation detail of package assert. One can use API to create a customized assert function with this package

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert(t *testing.T, expr interface{}, trigger *Trigger)

Assert tests expr and call `t.Fatalf` to terminate test case if expr is false-equivalent value.

func AssertEqual

func AssertEqual(t *testing.T, v1, v2 interface{}, trigger *Trigger)

AssertEqual uses `reflect.DeepEqual` to test v1 and v2 equality.

func AssertNilError

func AssertNilError(t *testing.T, result []interface{}, trigger *Trigger)

AssertNilError expects a function return a nil error. Otherwise, it will terminate the test case using `t.Fatalf`.

func AssertNonNilError

func AssertNonNilError(t *testing.T, result []interface{}, trigger *Trigger)

AssertNonNilError expects a function return a non-nil error. Otherwise, it will terminate the test case using `t.Fatalf`.

func AssertNotEqual

func AssertNotEqual(t *testing.T, v1, v2 interface{}, trigger *Trigger)

AssertNotEqual uses `reflect.DeepEqual` to test v1 and v2 equality.

func ParseArgs

func ParseArgs(name string, skip int, argIndex []int) (args []string, filename string, line int, err error)

ParseArgs parses caller's source code, finds out the right call expression by name and returns the argument source code.

Skip is the stack frame calling an assert function. If skip is 0, the stack frame for ParseArgs is selected. In most cases, caller should set skip to 1 to skip ParseArgs itself.

func TriggerAssert

func TriggerAssert(t *testing.T, name string, skip int, argIndex []int, k FalseKind)

TriggerAssert calls t.Fatalf to terminate a test case. It must be called by an assert function which will be directly used in test cases. See code in `Assertion#Assert` as a sample.

Types

type FalseKind

type FalseKind int

FalseKind is the kind of a false-equivalent value.

const (
	Positive FalseKind = iota
	Nil
	False
	Zero
	EmptyString
)

Valid kinds for all false-equivalent values.

func ParseFalseKind

func ParseFalseKind(expr interface{}) FalseKind

ParseFalseKind checks expr value and return false when expr is `false`, 0, `nil` and empty string. Otherwise, return true.

type Trigger

type Trigger struct {
	FuncName string
	Skip     int
	Args     []int
}

Trigger represents the method which triggers assertion.

Jump to

Keyboard shortcuts

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