Documentation ¶
Overview ¶
Package assert provides some assertion functions for testing.
Return values: true if the assert holds, false otherwise.
Index ¶
- Variables
- func Equal(t testing.TB, name string, act, exp interface{}) bool
- func Error(t testing.TB, err error) bool
- func False(t testing.TB, name string, act bool) bool
- func NoError(t testing.TB, err error) bool
- func NoErrorOrDie(t testing.TB, err error)
- func NotEqual(t testing.TB, name string, act, exp interface{}) bool
- func Panic(t testing.TB, name string, f func()) bool
- func Should(t testing.TB, vl bool, showIfFailed string) bool
- func ShouldOrDie(t testing.TB, vl bool, showIfFailed string)
- func StringEqual(t testing.TB, name string, act, exp interface{}) bool
- func True(t testing.TB, name string, act bool) bool
- func ValueShould(t testing.TB, name string, act interface{}, expToFunc interface{}, ...) bool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var IncludeFilePosition = true
Set this to false to avoid include file position in logs.
Functions ¶
func Equal ¶
Example ¶
// The following two lines are for test/example of assert package itself. Use // *testing.T as t in normal testing instead. IncludeFilePosition = false defer func() { IncludeFilePosition = true }() t := &testingp.WriterTB{Writer: os.Stdout} Equal(t, "v", 1, 2) Equal(t, "v", 1, "1") Equal(t, "m", map[string]int{"Extra": 2, "Modified": 4}, map[string]int{"Missing": 1, "Modified": 5})
Output: v is expected to be 2, but got 1 v is expected to be "1"(type=string), but got 1(type=int) m is unexpected: m["Modified"] is expected to be 5, but got 4 extra "Extra" -> 2 missing "Missing" -> 1
func NoErrorOrDie ¶
func StringEqual ¶
StringEqual compares the string representation of the values. If act and exp are both slices, they were matched by elements and the results are presented in a diff style (if not totally equal).
Example ¶
// The following two lines are for test/example of assert package itself. Use // *testing.T as t in normal testing instead. IncludeFilePosition = false defer func() { IncludeFilePosition = true }() t := &testingp.WriterTB{Writer: os.Stdout} StringEqual(t, "s", []int{2, 3}, []string{"1", "2"}) StringEqual(t, "s", ` Extra Modified act`, ` Modified exp Missing`)
Output: Unexpected s: both 2 lines Difference(expected --- actual +++) --- 1: "1" +++ 2: "3" Unexpected s: both 3 lines Difference(expected --- actual +++) --- 2: "Modified exp" --- 3: "Missing" +++ 2: "Extra" +++ 3: "Modified act"
func ValueShould ¶
func ValueShould(t testing.TB, name string, act interface{}, expToFunc interface{}, descIfFailed string) bool
@param expToFunc could be a func with a single input value and a bool return, or a bool value directly.
Example ¶
// The following two lines are for test/example of assert package itself. Use // *testing.T as t in normal testing instead. IncludeFilePosition = false defer func() { IncludeFilePosition = true }() t := &testingp.WriterTB{Writer: os.Stdout} ValueShould(t, "s", "\xff\xfe\xfd", utf8.ValidString, "is not valid UTF8") ValueShould(t, "s", "abcd", len("abcd") <= 3, "has more than 3 bytes")
Output: s is not valid UTF8: "\xff\xfe\xfd"(type string) s has more than 3 bytes: "abcd"(type string)
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.