-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathformat_go20_test.go
53 lines (44 loc) · 1.2 KB
/
format_go20_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//go:build go1.20
// +build go1.20
package errors_test
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"gitlab.com/tozd/go/errors"
)
func TestJoinErrorf(t *testing.T) {
t.Parallel()
tests := []struct {
error
format string
want string
}{{
errors.Errorf("multiple: %w %w", errors.New("error1"), errors.New("error2")),
"% #-+.1v",
"^multiple: error1 error2\n" +
"stack trace \\(most recent call first\\):\n" +
"gitlab.com/tozd/go/errors_test.TestJoinErrorf\n" +
"\t.+/format_go20_test.go:23\n" +
"(.+\n\t.+:\\d+\n)+" +
"\nthe above error joins errors:\n\n" +
"\terror1\n" +
"\tstack trace \\(most recent call first\\):\n" +
"\tgitlab.com/tozd/go/errors_test.TestJoinErrorf\n" +
"\t\t.+/format_go20_test.go:23\n" +
"(.+\n\t\t.+:\\d+\n)+" +
"\n" +
"\terror2\n" +
"\tstack trace \\(most recent call first\\):\n" +
"\tgitlab.com/tozd/go/errors_test.TestJoinErrorf\n" +
"\t\t.+/format_go20_test.go:23\n" +
"(.+\n\t\t.+:\\d+\n)+$",
}}
for k, tt := range tests {
tt := tt
t.Run(fmt.Sprintf("case=%d", k), func(t *testing.T) {
t.Parallel()
assert.Regexp(t, tt.want, fmt.Sprintf(tt.format, errors.Formatter{Error: tt.error}))
})
}
}