当前位置: 首页>>代码示例>>Golang>>正文


Golang TB.FailNow方法代码示例

本文整理汇总了Golang中testing.TB.FailNow方法的典型用法代码示例。如果您正苦于以下问题:Golang TB.FailNow方法的具体用法?Golang TB.FailNow怎么用?Golang TB.FailNow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在testing.TB的用法示例。


在下文中一共展示了TB.FailNow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: equals

// equals fails the test if exp is not equal to act.
func equals(tb testing.TB, exp, act interface{}) {
	if !reflect.DeepEqual(exp, act) {
		_, file, line, _ := runtime.Caller(1)
		fmt.Printf("\033[31m%s:%d:\n\n\texp: %#v\n\n\tgot: %#v\033[39m\n\n", filepath.Base(file), line, exp, act)
		tb.FailNow()
	}
}
开发者ID:pombredanne,项目名称:pkg,代码行数:8,代码来源:usage_test.go

示例2: Assert

// Assert fails the test and displays 'msg', if the condition is false.
func Assert(tb testing.TB, condition bool, msg string, v ...interface{}) {
	if !condition {
		_, file, line, _ := runtime.Caller(1)
		fmt.Printf("%s:%d: "+msg+"\n\n", append([]interface{}{filepath.Base(file), line}, v...)...)
		tb.FailNow()
	}
}
开发者ID:jmorgan1321,项目名称:golang-games,代码行数:8,代码来源:helpers.go

示例3: AssertNotNil

// AssertNotNil fails the test if exp is not equal to act.
func AssertNotNil(tb testing.TB, exp interface{}) {
	if exp == nil {
		_, file, line, _ := runtime.Caller(1)
		fmt.Printf("\033[31m%s:%d: expecting not nil but got nil\033[39m\n\n", filepath.Base(file), line)
		tb.FailNow()
	}
}
开发者ID:ustrajunior,项目名称:minion,代码行数:8,代码来源:tst.go

示例4: ok

// ok fails the test if an err is not nil.
func ok(tb testing.TB, err error) {
	if err != nil {
		_, file, line, _ := runtime.Caller(1)
		fmt.Printf("\033[31m%s:%d: unexpected error: %s\033[39m\n\n", filepath.Base(file), line, err.Error())
		tb.FailNow()
	}
}
开发者ID:pombredanne,项目名称:pkg,代码行数:8,代码来源:usage_test.go

示例5: AssertJSONBody

func AssertJSONBody(tb testing.TB, exp, act interface{}) {
	red := ansi.ColorCode("red+h:black")
	green := ansi.ColorCode("green+h:black")
	yellow := ansi.ColorFunc("yellow+h")
	reset := ansi.ColorCode("reset")

	var actBuf bytes.Buffer
	err := json.Indent(&actBuf, []byte(act.(string)), "", " ")
	if err != nil {
		fmt.Println(red, "Invalid json: ", act, reset)
	}
	act = string(actBuf.Bytes())

	var expBuf bytes.Buffer
	err = json.Indent(&expBuf, []byte(exp.(string)), "", " ")
	if err != nil {
		fmt.Println(red, "Invalid json: ", exp, reset)
	}
	exp = string(expBuf.Bytes())

	if !reflect.DeepEqual(exp, act) {
		_, file, line, _ := runtime.Caller(1)

		fmt.Println(yellow(fmt.Sprintf("%s:%d", filepath.Base(file), line)))
		fmt.Println(green, "Expected: ", exp, reset)
		fmt.Println(red, "     Got: ", act, reset)

		tb.FailNow()
	}
}
开发者ID:ustrajunior,项目名称:minion,代码行数:30,代码来源:tst.go

示例6: Equals

// Equals fails the test if exp is not equal to act.
// Code was copied from https://github.com/benbjohnson/testing MIT license
func Equals(tb testing.TB, exp, act interface{}) {
	if !reflect.DeepEqual(exp, act) {
		_, file, line, _ := runtime.Caller(1)
		fmt.Printf("%s%s:%d:\n\n\texp: %#v\n\n\tgot: %#v%s\n\n", colors[red], filepath.Base(file), line, exp, act, colors[reset])
		tb.FailNow()
	}
}
开发者ID:alvaropeon,项目名称:hpcloud-kubesetup,代码行数:9,代码来源:testUtil.go

示例7: AssertEQ

// AssertEQ fails the test and displays 'msg', if exp is not equal to act.
func AssertEQ(tb testing.TB, exp, act interface{}, msg string) {
	if !reflect.DeepEqual(exp, act) {
		_, file, line, _ := runtime.Caller(1)
		fmt.Printf("%s:%d: %s\n\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, msg, exp, act)
		tb.FailNow()
	}
}
开发者ID:jmorgan1321,项目名称:golang-games,代码行数:8,代码来源:helpers.go

示例8: notOk

func notOk(tb testing.TB, err error) {
	if err == nil {
		_, file, line, _ := runtime.Caller(1)
		fmt.Printf("\033[31m%s:%d: expected error but got nil instead\n\n", filepath.Base(file), line)
		tb.FailNow()
	}
}
开发者ID:temal-,项目名称:trousseau,代码行数:7,代码来源:test_helpers.go

示例9: notNilUp

// notNilUp is like notNil, but used inside helper functions, to ensure that the
// file and line number reported by failures corresponds to one or more levels
// up the stack.
func notNilUp(obtained interface{}, t testing.TB, caller int) {
	if _isNil(obtained) {
		_, file, line, _ := runtime.Caller(caller + 1)
		fmt.Printf("%s:%d: expected non-nil, got: %v\n", filepath.Base(file), line, obtained)
		t.FailNow()
	}
}
开发者ID:natefinch,项目名称:discourse,代码行数:10,代码来源:testing_test.go

示例10: AssertError

func AssertError(tb testing.TB, err error) {
	if err == nil {
		_, file, line, _ := runtime.Caller(1)
		fmt.Printf("\033[31m%s:%d: expecting error but got nil\033[39m\n\n", filepath.Base(file), line)
		tb.FailNow()
	}
}
开发者ID:ustrajunior,项目名称:minion,代码行数:7,代码来源:tst.go

示例11: equalsUp

// equalsUp is like equals, but used inside helper functions, to ensure that the
// file and line number reported by failures corresponds to one or more levels
// up the stack.
func equalsUp(exp, act interface{}, t testing.TB, caller int) {
	if !reflect.DeepEqual(exp, act) {
		_, file, line, _ := runtime.Caller(caller + 1)
		fmt.Printf("%s:%d: exp: %v (%T), got: %v (%T)\n",
			filepath.Base(file), line, exp, exp, act, act)
		t.FailNow()
	}
}
开发者ID:natefinch,项目名称:discourse,代码行数:11,代码来源:testing_test.go

示例12: assertUp

// assertUp is like assert, but used inside helper functions, to ensure that
// the file and line number reported by failures corresponds to one or more
// levels up the stack.
func assertUp(condition bool, t testing.TB, caller int, msg string, v ...interface{}) {
	if !condition {
		_, file, line, _ := runtime.Caller(caller + 1)
		v = append([]interface{}{filepath.Base(file), line}, v...)
		fmt.Printf("%s:%d: "+msg+"\n", v...)
		t.FailNow()
	}
}
开发者ID:natefinch,项目名称:discourse,代码行数:11,代码来源:testing_test.go

示例13: contains

func contains(tb testing.TB, s []string, e string) {
	for _, a := range s {
		if a == e {
			return
		}
	}
	fmt.Printf("Expected to contain %s\n", e)
	tb.FailNow()
}
开发者ID:gaffo,项目名称:goosmtools,代码行数:9,代码来源:filter_test.go

示例14: Assert

// assert fails the test if the condition is false.
func Assert(tb testing.TB, condition bool, v ...interface{}) {
	if !condition {
		_, file, line, _ := runtime.Caller(1)
		fmt.Printf("\n\033[31m%s:%d: failure!!!\033[39m\n\n", append([]interface{}{filepath.Base(file), line}, v...)...)
		tb.FailNow()
	} else {
		fmt.Printf("\033[32m.\033[39m")
	}
}
开发者ID:bentrevor,项目名称:calhoun,代码行数:10,代码来源:bolt_test_helpers.go

示例15: AssertNotEquals

func AssertNotEquals(tb testing.TB, exp, act interface{}) {
	if reflect.DeepEqual(exp, act) {
		_, file, line, _ := runtime.Caller(1)
		fmt.Printf("\n\033[31m%s:%d:\n\n\texpected: %#v\n\n\tnot to eq: %#v\033[39m\n\n", filepath.Base(file), line, exp, act)
		tb.FailNow()
	} else {
		fmt.Printf("\033[32m.\033[39m")
	}
}
开发者ID:bentrevor,项目名称:calhoun,代码行数:9,代码来源:bolt_test_helpers.go


注:本文中的testing.TB.FailNow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。