本文整理匯總了Golang中testing.TB.Skipped方法的典型用法代碼示例。如果您正苦於以下問題:Golang TB.Skipped方法的具體用法?Golang TB.Skipped怎麽用?Golang TB.Skipped使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類testing.TB
的用法示例。
在下文中一共展示了TB.Skipped方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Report
// When a test is skipped or fails, runtime.Goexit() is called which destroys the callstack.
// This means the name of the test case is lost, so we need to grab a copy of pc before.
func Report(t testing.TB) {
// If the goroutine panics, Fatal()s, or Skip()s, the function name is at the 3rd callstack
// layer. On success, its at 1st. Since it's hard to check which happened, just try both.
pcs := make([]uintptr, 10)
total := runtime.Callers(1, pcs)
var name string
for _, pc := range pcs[:total] {
fn := runtime.FuncForPC(pc)
fullName := fn.Name()
if strings.HasPrefix(path.Ext(fullName), ".Test") {
// Skip the leading .
name = string([]byte(path.Ext(fullName))[1:])
break
}
}
if name == "" {
return
}
allCaseInfos.lock.Lock()
defer allCaseInfos.lock.Unlock()
allCaseInfos.Cases = append(allCaseInfos.Cases, &caseInfo{
Name: name,
Passed: !t.Failed() && !t.Skipped(),
Skipped: t.Skipped(),
Fatal: t.Failed() && !strings.HasPrefix(name, "TestSoon"),
})
}