-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
111 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright © 2020 Hedzr Yeh. | ||
|
||
// +build go1.13 | ||
|
||
package errors | ||
|
||
import ( | ||
errorsstd "errors" | ||
// pkgerrors "github.com/pkg/errors" | ||
"io" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func Test1go113(t *testing.T) { | ||
var err error | ||
|
||
err = geneof() | ||
if Cause(err) == io.EOF { | ||
t.Logf("ok: %v", err) | ||
} else { | ||
t.Fatal("expect it is a EOF") | ||
} | ||
|
||
//err = geneof2() | ||
//if pkgerrors.Cause(err) == io.EOF { | ||
// t.Logf("ok: %v", err) | ||
//} else { | ||
// t.Fatal("expect it is a EOF") | ||
//} | ||
|
||
err = geneof13() | ||
if errorsstd.Is(err, io.EOF) { | ||
t.Logf("ok: %v", err) | ||
} else { | ||
t.Fatal("expect it is a EOF") | ||
} | ||
} | ||
|
||
func Test2go113(t *testing.T) { | ||
var err error | ||
|
||
err = geneofx() | ||
if Cause(err) == io.EOF { | ||
t.Logf("ok: %v", err) | ||
} else { | ||
t.Fatal("expect it is a EOF") | ||
} | ||
if Cause(err) == io.EOF { | ||
t.Logf("ok: %+v", err) | ||
} else { | ||
t.Fatal("expect it is a EOF") | ||
} | ||
|
||
err = geneofxs() | ||
if Cause(err) == io.EOF { | ||
t.Logf("ok: %v", err) | ||
} else { | ||
t.Fatal("expect it is a EOF") | ||
} | ||
|
||
// errorx tests ------------------------------- | ||
|
||
// errorx.Cause() and Cause1() | ||
if Cause(err) == io.EOF { | ||
// Wrap(err, msg): the error object has stacktrace info | ||
t.Logf("ok: %+v", err) | ||
} else { | ||
t.Fatal("Cause() failed: expect it is a EOF") | ||
} | ||
if Is(err, io.EOF) { | ||
// Wrap(err, msg): the error object has stacktrace info | ||
t.Logf("ok: %+v", err) | ||
} else { | ||
t.Fatal("Is() failed: expect it is a EOF") | ||
} | ||
if Unwrap(Unwrap(err)) == io.EOF { | ||
// Wrap(err, msg): the error object has stacktrace info | ||
t.Logf("ok: %+v", err) | ||
} else { | ||
t.Fatal("Unwrap() failed: expect it is a EOF") | ||
} | ||
|
||
var perr *os.PathError | ||
err = Wrap(&os.PathError{Err: io.EOF, Op: "find", Path: "/"}, "wrong path and rights") | ||
if As(err, &perr) { | ||
t.Logf("ok: %+v", *perr) | ||
} else { | ||
t.Fatal("As() failed: expect it is a os.PathError{}") | ||
} | ||
|
||
// var c = NewContainer("container") | ||
// AttachTo(c, io.EOF, io.ErrShortBuffer, io.ErrUnexpectedEOF) | ||
// t.Logf("ok: %+v | container is empty: %v", c, ContainerIsEmpty(c)) | ||
// if ContainerIsEmpty(c) != false { | ||
// t.Fatal("ContainerIsEmpty(c) failed: expect it is false.") | ||
// } | ||
} |
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