Search Apps Documentation Source Content File Folder Download Copy Actions Download

helpers.gno

0.82 Kb · 51 lines
 1package uassert
 2
 3import "strings"
 4
 5func fail(t TestingT, customMsgs []string, failureMessage string, args ...any) bool {
 6	customMsg := ""
 7	if len(customMsgs) > 0 {
 8		customMsg = strings.Join(customMsgs, " ")
 9	}
10	if customMsg != "" {
11		failureMessage += " - " + customMsg
12	}
13	t.Errorf(failureMessage, args...)
14	return false
15}
16
17func checkDidPanic(f any) (didPanic bool, message string) {
18	didPanic = true
19	defer func() {
20		r := recover()
21
22		if r == nil {
23			message = "nil"
24			return
25		}
26
27		err, ok := r.(error)
28		if ok {
29			message = err.Error()
30			return
31		}
32
33		errStr, ok := r.(string)
34		if ok {
35			message = errStr
36			return
37		}
38
39		message = "recover: unsupported type"
40	}()
41	switch f := f.(type) {
42	case func():
43		f()
44	case func(realm):
45		f(cross)
46	default:
47		panic("f must be of type func() or func(realm)")
48	}
49	didPanic = false
50	return
51}