z_func_8_filetest.gno

1.52 Kb ยท 60 lines
 1// PKGPATH: gno.land/r/demo/test
 2package test
 3
 4import (
 5	"std"
 6	"strings"
 7	"testing"
 8
 9	"gno.land/p/jeronimoalbi/expect"
10)
11
12const (
13	caller = std.Address("g16jpf0puufcpcjkph5nxueec8etpcldz7zwgydq")
14	msg    = "Boom!"
15)
16
17var (
18	output strings.Builder
19	t      = expect.MockTestingT(&output)
20)
21
22func Fail(realm) {
23	panic(msg)
24}
25
26func main() {
27	testing.SetRealm(std.NewUserRealm(caller))
28
29	expect.Func(t, func() { Fail(cross) }).Not().ToCrossPanic()
30	expect.Func(t, func() { Fail(cross) }).ToCrossPanic().Not().WithMessage(msg)
31
32	expect.Func(t, func() error { Fail(cross); return nil }).Not().ToCrossPanic()
33	expect.Func(t, func() error { Fail(cross); return nil }).ToCrossPanic().Not().WithMessage(msg)
34
35	expect.Func(t, func() any { Fail(cross); return nil }).Not().ToCrossPanic()
36	expect.Func(t, func() any { Fail(cross); return nil }).ToCrossPanic().Not().WithMessage(msg)
37
38	expect.Func(t, func() (any, error) { Fail(cross); return nil, nil }).Not().ToCrossPanic()
39	expect.Func(t, func() (any, error) { Fail(cross); return nil, nil }).ToCrossPanic().Not().WithMessage(msg)
40
41	println(output.String())
42}
43
44// Output:
45// Expected func not to cross panic
46// Got: Boom!
47// Expected cross panic message to be different
48// Got: Boom!
49// Expected func not to cross panic
50// Got: Boom!
51// Expected cross panic message to be different
52// Got: Boom!
53// Expected func not to cross panic
54// Got: Boom!
55// Expected cross panic message to be different
56// Got: Boom!
57// Expected func not to cross panic
58// Got: Boom!
59// Expected cross panic message to be different
60// Got: Boom!