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