本文整理汇总了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"),
})
}