From 8ca2be74c2e9722698c3a2d0a35454d94f1a6c11 Mon Sep 17 00:00:00 2001 From: Hedzr Yeh Date: Wed, 13 Dec 2023 11:22:09 +0800 Subject: [PATCH] fixed tests --- join_go1.11_test.go | 56 +++++++++++++++++++++++++++++++++++++++++++++ join_go1.13_test.go | 14 ++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 join_go1.11_test.go diff --git a/join_go1.11_test.go b/join_go1.11_test.go new file mode 100644 index 0000000..4bc514e --- /dev/null +++ b/join_go1.11_test.go @@ -0,0 +1,56 @@ +// Copyright © 2023 Hedzr Yeh. + +//go:build go1.11 +// +build go1.11 + +package errors_test + +import ( + "errors" + "fmt" + "testing" + + v3 "gopkg.in/hedzr/errors.v3" +) + +func TestJoinErrorsStdFormatGo111(t *testing.T) { + err1 := errors.New("err1") + err2 := errors.New("err2") + + err := v3.Join(err1, err2) + + fmt.Printf("%T, %v\n", err, err) + + if v3.Is(err, err1) { + t.Log("err is err1") + } else { + t.Fatal("FAILED: expecting err is err1") + } + + if v3.Is(err, err2) { + t.Log("err is err2") + } else { + t.Fatal("FAILED: expecting err is err2") + } + + err3 := fmt.Errorf("error3: %w", err) + fmt.Printf("%T, %v\n", err3, v3.Unwrap(err3)) + + if v3.Is(err3, err1) { + t.Log("err3 is err1") + } else { + t.Fatal("FAILED: expecting err3 is err1") + } + + if v3.Is(err3, err2) { + t.Log("err3 is err2") + } else { + t.Fatal("FAILED: expecting err3 is err2") + } + + if !v3.Is(err2, err3) { + t.Log("err2 isn't err3") + } else { + t.Fatal("FAILED: expecting err2 is err3") + } +} diff --git a/join_go1.13_test.go b/join_go1.13_test.go index a0fbecb..1824285 100644 --- a/join_go1.13_test.go +++ b/join_go1.13_test.go @@ -8,6 +8,7 @@ package errors_test import ( "errors" "fmt" + "io" "testing" v3 "gopkg.in/hedzr/errors.v3" @@ -54,3 +55,16 @@ func TestJoinErrorsStdFormat(t *testing.T) { t.Fatal("FAILED: expecting err2 is err3") } } + +func TestCauses2_errors(t *testing.T) { + err := io.EOF + + if !errors.Is(err, io.EOF) { + t.Fail() + } + + err = dummy(t) + err = fmt.Errorf("wrapped: %w", err) + t.Logf("divide: %v", err) + t.Logf("Unwrap: %v", errors.Unwrap(err)) +}