Skip to content

Commit

Permalink
Merge pull request #24 from go-faster/test/add-multi-comp-test
Browse files Browse the repository at this point in the history
test: add simple compatibility test for new `errors.Join`
  • Loading branch information
ernado committed Apr 4, 2023
2 parents ff8939f + 493a352 commit 5818433
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/gowrapper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
42 changes: 42 additions & 0 deletions multi_test.go
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)
}
}

0 comments on commit 5818433

Please sign in to comment.