z_func_2_filetest.gno

1.23 Kb ยท 53 lines
 1package main
 2
 3import (
 4	"strings"
 5
 6	"gno.land/p/jeronimoalbi/expect"
 7)
 8
 9var (
10	output strings.Builder
11	t      = expect.MockTestingT(&output)
12)
13
14func main() {
15	gotMsg := "Boom!"
16	wantMsg := "Tick Tock"
17
18	expect.Func(t, func() {}).ToPanic()
19	expect.Func(t, func() { panic(gotMsg) }).ToPanic().WithMessage(wantMsg)
20
21	expect.Func(t, func() error { return nil }).ToPanic()
22	expect.Func(t, func() error { panic(gotMsg) }).ToPanic().WithMessage(wantMsg)
23
24	expect.Func(t, func() any { return nil }).ToPanic()
25	expect.Func(t, func() any { panic(gotMsg) }).ToPanic().WithMessage(wantMsg)
26
27	expect.Func(t, func() (any, error) { return nil, nil }).ToPanic()
28	expect.Func(t, func() (any, error) { panic(gotMsg) }).ToPanic().WithMessage(wantMsg)
29
30	expect.Func(t, func() int { return 0 }).ToPanic()
31
32	println(output.String())
33}
34
35// Output:
36// Expected function to panic
37// Expected panic message to match
38// Got: Boom!
39// Want: Tick Tock
40// Expected function to panic
41// Expected panic message to match
42// Got: Boom!
43// Want: Tick Tock
44// Expected function to panic
45// Expected panic message to match
46// Got: Boom!
47// Want: Tick Tock
48// Expected function to panic
49// Expected panic message to match
50// Got: Boom!
51// Want: Tick Tock
52// Unsupported func type
53// Got: unknown