2021-10-27 14:59:57 +00:00
|
|
|
package decrr_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os"
|
2021-10-27 16:50:22 +00:00
|
|
|
"runtime"
|
2021-10-27 14:59:57 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/aldy505/decrr"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestWrap(t *testing.T) {
|
|
|
|
x := errors.New("why does a chicken cross the road?")
|
|
|
|
w := decrr.Wrap(x)
|
|
|
|
wd, _ := os.Getwd()
|
|
|
|
|
2021-10-27 16:50:22 +00:00
|
|
|
gt := runtime.GOROOT()
|
2021-10-27 15:59:40 +00:00
|
|
|
|
2021-10-27 14:59:57 +00:00
|
|
|
var expected string
|
|
|
|
expected += "why does a chicken cross the road?\n\n"
|
2021-10-27 16:50:22 +00:00
|
|
|
expected += "github.com/aldy505/decrr_test.TestWrap " + wd + "/decrr_test.go:14\n"
|
2021-10-27 15:59:40 +00:00
|
|
|
expected += "testing.tRunner " + gt + "/src/testing/testing.go:1259\n"
|
|
|
|
expected += "runtime.goexit " + gt + "/src/runtime/asm_amd64.s:1581"
|
2021-10-27 14:59:57 +00:00
|
|
|
|
|
|
|
if w.Error() != expected {
|
|
|
|
t.Error("different than expected:", w.Error(), "\nexpected:", expected)
|
|
|
|
}
|
2021-10-27 15:00:23 +00:00
|
|
|
}
|
2021-10-27 16:56:13 +00:00
|
|
|
|
|
|
|
func TestNilValue(t *testing.T) {
|
|
|
|
w := decrr.Wrap(nil)
|
|
|
|
|
|
|
|
if w != nil {
|
|
|
|
t.Error("should be nil, got:", w)
|
|
|
|
}
|
|
|
|
}
|