Skip to content

Commit

Permalink
tests for lower go
Browse files Browse the repository at this point in the history
  • Loading branch information
hedzr committed Sep 25, 2020
1 parent 1f3ed8f commit b8b69cc
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 7 deletions.
98 changes: 98 additions & 0 deletions errors_go1.13_test.go
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.")
// }
}
20 changes: 13 additions & 7 deletions errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package errors

import (
errorss "errors"
"fmt"
"github.com/pkg/errors"
"io"
Expand Down Expand Up @@ -220,12 +219,19 @@ func Test1(t *testing.T) {
t.Fatal("expect it is a EOF")
}

err = geneof13()
if errorss.Is(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 Test2(t *testing.T) {
Expand Down

0 comments on commit b8b69cc

Please sign in to comment.