z_func_1_filetest.gno
0.98 Kb ยท 42 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 msg := "Boom!"
17 err := errors.New(msg)
18
19 expect.Func(t, func() error { return err }).Not().ToFail()
20 expect.Func(t, func() error { return err }).ToFail().Not().WithMessage(msg)
21 expect.Func(t, func() error { return err }).ToFail().Not().WithError(err)
22
23 expect.Func(t, func() (any, error) { return nil, err }).Not().ToFail()
24 expect.Func(t, func() (any, error) { return nil, err }).ToFail().Not().WithMessage(msg)
25 expect.Func(t, func() (any, error) { return nil, err }).ToFail().Not().WithError(err)
26
27 println(output.String())
28}
29
30// Output:
31// Func failed with error
32// Got: Boom!
33// Expected error message to be different
34// Got: Boom!
35// Expected errors to be different
36// Got: Boom!
37// Func failed with error
38// Got: Boom!
39// Expected error message to be different
40// Got: Boom!
41// Expected errors to be different
42// Got: Boom!