z_func_0_filetest.gno

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