-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from go-faster/test/add-multi-comp-test
test: add simple compatibility test for new `errors.Join`
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//go:build go1.20 | ||
|
||
package errors_test | ||
|
||
import ( | ||
stderrors "errors" | ||
"io" | ||
"testing" | ||
|
||
"github.com/go-faster/errors" | ||
) | ||
|
||
var ErrValue = errors.New("value error") | ||
|
||
type Error struct{} | ||
|
||
func (*Error) Error() string { | ||
return "typed error" | ||
} | ||
|
||
// Compatibility test for multi-errors generated by [errors.Join] | ||
func TestMulti(t *testing.T) { | ||
typedErr := new(Error) | ||
wrappedErr := errors.Wrap(io.ErrClosedPipe, "wrapped error") | ||
|
||
errs := stderrors.Join(ErrValue, typedErr, wrappedErr) | ||
|
||
// Test Is. | ||
if !errors.Is(errs, ErrValue) { | ||
t.Errorf("Expected Is(%+v, %+v) == true", errs, ErrValue) | ||
} | ||
|
||
// Test As. | ||
if target := new(*Error); !errors.As(errs, target) { | ||
t.Errorf("Expected As(%+v, %T) == true", errs, target) | ||
} | ||
|
||
// Test wrapping. | ||
if !errors.Is(errs, io.ErrClosedPipe) { | ||
t.Errorf("Expected Is(%+v, %+v) == true", errs, ErrValue) | ||
} | ||
} |