當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。