File tree 8 files changed +35
-19
lines changed
8 files changed +35
-19
lines changed Original file line number Diff line number Diff line change 13
13
steps :
14
14
- uses : actions/setup-go@master
15
15
with :
16
- go-version : " 1.15 "
16
+ go-version : " 1.16 "
17
17
- uses : actions/checkout@master
18
18
with :
19
19
fetch-depth : 1
Original file line number Diff line number Diff line change @@ -5,17 +5,7 @@ GOMAXPROCS?=$(shell nproc)
5
5
.PHONY : test
6
6
test :
7
7
@mkdir -p tmp
8
- @echo " mode: atomic" > tmp/cover.out
9
- @for d in $(shell go list ./... | grep -v vendor | grep -v demo) ; do \
10
- GOMAXPROCS=$(GOMAXPROCS ) \
11
- go test \
12
- $(GOARGS ) \
13
- -timeout $(GOTIMEOUT ) \
14
- -coverprofile=tmp/pkg.out -covermode=atomic \
15
- " $$ d" || exit 1; \
16
- tail -n +2 tmp/pkg.out >> tmp/cover.out && \
17
- rm tmp/pkg.out; \
18
- done
8
+ @go test -cover -coverprofile=tmp/cover.out -covermode=atomic ./...
19
9
@go tool cover -html=tmp/cover.out -o tmp/coverage.html
20
10
21
11
.PHONY : bench
Original file line number Diff line number Diff line change @@ -26,7 +26,11 @@ func (b *BenchmarkStep) AddError(err error) {
26
26
b .mu .RLock ()
27
27
defer b .mu .RUnlock ()
28
28
29
- b .result .Errors .Add (failure .NewError (b .errorCode , err ))
29
+ if b .errorCode != nil {
30
+ b .result .Errors .Add (failure .NewError (b .errorCode , err ))
31
+ } else {
32
+ b .result .Errors .Add (err )
33
+ }
30
34
}
31
35
32
36
func (b * BenchmarkStep ) AddScore (tag score.ScoreTag ) {
Original file line number Diff line number Diff line change @@ -24,12 +24,13 @@ func TestBacktraceCleaner(t *testing.T) {
24
24
return strings .HasSuffix (b .Function , "TestBacktraceCleaner" )
25
25
})
26
26
27
+ var code StringCode = "cleaner"
27
28
var f func (int ) error
28
29
f = func (n int ) error {
29
30
if n > 0 {
30
31
return f (n - 1 )
31
32
}
32
- return NewError (UnknownErrorCode , fmt .Errorf ("invalid" ))
33
+ return NewError (code , fmt .Errorf ("invalid" ))
33
34
}
34
35
35
36
err := f (0 )
Original file line number Diff line number Diff line change @@ -20,11 +20,11 @@ type Error struct {
20
20
frames []xerrors.Frame
21
21
}
22
22
23
- func NewError (code Code , err error ) * Error {
24
- // var wrapped *Error
25
- // if ok := As (err, &wrapped); ok {
26
- // return NewError(code, wrapped. err)
27
- // }
23
+ func NewError (code Code , err error ) error {
24
+ // Skip already wrapped
25
+ if IsCode (err , code ) {
26
+ return err
27
+ }
28
28
29
29
var nerr net.Error
30
30
if As (err , & nerr ) {
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import (
12
12
const (
13
13
errApplication StringCode = "application"
14
14
errTemporary StringCode = "temporary"
15
+ errTest StringCode = "test"
15
16
)
16
17
17
18
func TestError (t * testing.T ) {
@@ -111,6 +112,14 @@ func TestErrorWrap(t *testing.T) {
111
112
if ! reflect .DeepEqual (codes , expectCodes ) {
112
113
t .Fatalf ("Error codes is invalid:\n %v\n %v" , codes , expectCodes )
113
114
}
115
+
116
+ err := NewError (errTest , fmt .Errorf ("error" ))
117
+ nilError := NewError (errTest , err )
118
+ codes = GetErrorCodes (nilError )
119
+ expectCodes = []string {"test" }
120
+ if ! reflect .DeepEqual (codes , expectCodes ) {
121
+ t .Fatalf ("Error codes is invalid:\n %v\n %v" , codes , expectCodes )
122
+ }
114
123
}
115
124
116
125
func TestErrorFrames (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -27,6 +27,12 @@ func TestErrors(t *testing.T) {
27
27
if len (errors ) != 100 {
28
28
t .Errorf ("missmatch errors count: %d" , len (errors ))
29
29
}
30
+
31
+ set .Reset ()
32
+ moreErrors := set .All ()
33
+ if len (moreErrors ) != 0 {
34
+ t .Errorf ("missmatch errors count: %d" , len (moreErrors ))
35
+ }
30
36
}
31
37
32
38
func TestErrorsClosed (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -13,13 +13,19 @@ func TestScoreWithDone(t *testing.T) {
13
13
for i := 0 ; i < 1000 ; i ++ {
14
14
score .Add ("foo" )
15
15
score .Add ("bar" )
16
+ score .Add ("baz" )
16
17
}
17
18
18
19
score .Done ()
19
20
20
21
if score .Total () != 3000 {
21
22
t .Fatalf ("Expected 3000 but got %d" , score .Total ())
22
23
}
24
+
25
+ score .Reset ()
26
+ if score .Total () != 0 {
27
+ t .Fatalf ("Expected 0 but got %d" , score .Total ())
28
+ }
23
29
}
24
30
25
31
func TestScoreWithContext (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments