diff --git a/cmd/gowrapper/main.go b/cmd/gowrapper/main.go index 6542c23..5898419 100644 --- a/cmd/gowrapper/main.go +++ b/cmd/gowrapper/main.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Binary gowrapper replaces exisiting xerrors calls with errors analog. package main import ( diff --git a/multi_test.go b/multi_test.go new file mode 100644 index 0000000..10a4b7f --- /dev/null +++ b/multi_test.go @@ -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) + } +}