Hi,
I have tried to run tests and did not have much luck with it. Few problems are documented below.
How to run tests?
It is not clear how to run them (this is very much skill issue on my part). Usual go test -v gives
go test -v .
go: cannot find main module, but found .git/config in /tmp/errors
to create a module there, run:
go mod init
I do not have experience with pre-modules golang, so I am sure there is a way, but would be nice to have it written somewhere. In the end I just followed the instructions and did:
go mod init github.com/pkg/errors
go mod tidy
vet complains
$ go test -v .
# github.com/pkg/errors
# [github.com/pkg/errors]
./errors_test.go:128:24: non-constant format string in call to github.com/pkg/errors.Wrapf
./errors_test.go:220:31: non-constant format string in call to github.com/pkg/errors.WithMessagef
FAIL github.com/pkg/errors [build failed]
FAIL
So to have the tests pass, one needs to run them with -vet off.
test failures
Some tests just fail:
$ go test -v -vet off .
=== RUN TestNew
--- PASS: TestNew (0.00s)
=== RUN TestWrapNil
--- PASS: TestWrapNil (0.00s)
=== RUN TestWrap
--- PASS: TestWrap (0.00s)
=== RUN TestCause
--- PASS: TestCause (0.00s)
=== RUN TestWrapfNil
--- PASS: TestWrapfNil (0.00s)
=== RUN TestWrapf
--- PASS: TestWrapf (0.00s)
=== RUN TestErrorf
--- PASS: TestErrorf (0.00s)
=== RUN TestWithStackNil
--- PASS: TestWithStackNil (0.00s)
=== RUN TestWithStack
--- PASS: TestWithStack (0.00s)
=== RUN TestWithMessageNil
--- PASS: TestWithMessageNil (0.00s)
=== RUN TestWithMessage
--- PASS: TestWithMessage (0.00s)
=== RUN TestWithMessagefNil
--- PASS: TestWithMessagefNil (0.00s)
=== RUN TestWithMessagef
--- PASS: TestWithMessagef (0.00s)
=== RUN TestErrorEquality
--- PASS: TestErrorEquality (0.00s)
=== RUN TestFormatNew
format_test.go:38: test 3: line 3: fmt.Sprintf("%+v", err):
got: "error\ngithub.com/pkg/errors.TestFormatNew\n\t/tmp/errors/format_test.go:26\ntesting.tRunner\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/testing/testing.go:2036\nruntime.goexit\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/runtime/asm_amd64.s:1771"
want: "error\ngithub.com/pkg/errors.TestFormatNew\n\t.+/github.com/pkg/errors/format_test.go:26"
--- FAIL: TestFormatNew (0.00s)
=== RUN TestFormatErrorf
format_test.go:64: test 3: line 3: fmt.Sprintf("%+v", err):
got: "error\ngithub.com/pkg/errors.TestFormatErrorf\n\t/tmp/errors/format_test.go:56\ntesting.tRunner\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/testing/testing.go:2036\nruntime.goexit\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/runtime/asm_amd64.s:1771"
want: "error\ngithub.com/pkg/errors.TestFormatErrorf\n\t.+/github.com/pkg/errors/format_test.go:56"
--- FAIL: TestFormatErrorf (0.00s)
=== RUN TestFormatWrap
format_test.go:116: test 3: line 3: fmt.Sprintf("%+v", err):
got: "error\ngithub.com/pkg/errors.TestFormatWrap\n\t/tmp/errors/format_test.go:82\ntesting.tRunner\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/testing/testing.go:2036\nruntime.goexit\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/runtime/asm_amd64.s:1771\nerror2\ngithub.com/pkg/errors.TestFormatWrap\n\t/tmp/errors/format_test.go:82\ntesting.tRunner\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/testing/testing.go:2036\nruntime.goexit\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/runtime/asm_amd64.s:1771"
want: "error\ngithub.com/pkg/errors.TestFormatWrap\n\t.+/github.com/pkg/errors/format_test.go:82"
format_test.go:116: test 6: line 4: fmt.Sprintf("%+v", err):
got: "EOF\nerror\ngithub.com/pkg/errors.TestFormatWrap\n\t/tmp/errors/format_test.go:96\ntesting.tRunner\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/testing/testing.go:2036\nruntime.goexit\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/runtime/asm_amd64.s:1771"
want: "EOF\nerror\ngithub.com/pkg/errors.TestFormatWrap\n\t.+/github.com/pkg/errors/format_test.go:96"
format_test.go:116: test 7: line 4: fmt.Sprintf("%+v", err):
got: "EOF\nerror1\ngithub.com/pkg/errors.TestFormatWrap\n\t/tmp/errors/format_test.go:103\ntesting.tRunner\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/testing/testing.go:2036\nruntime.goexit\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/runtime/asm_amd64.s:1771\nerror2\ngithub.com/pkg/errors.TestFormatWrap\n\t/tmp/errors/format_test.go:103\ntesting.tRunner\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/testing/testing.go:2036\nruntime.goexit\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/runtime/asm_amd64.s:1771"
want: "EOF\nerror1\ngithub.com/pkg/errors.TestFormatWrap\n\t.+/github.com/pkg/errors/format_test.go:103\n"
--- FAIL: TestFormatWrap (0.00s)
=== RUN TestFormatWrapf
format_test.go:157: test 3: line 4: fmt.Sprintf("%+v", err):
got: "EOF\nerror2\ngithub.com/pkg/errors.TestFormatWrapf\n\t/tmp/errors/format_test.go:134\ntesting.tRunner\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/testing/testing.go:2036\nruntime.goexit\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/runtime/asm_amd64.s:1771"
want: "EOF\nerror2\ngithub.com/pkg/errors.TestFormatWrapf\n\t.+/github.com/pkg/errors/format_test.go:134"
format_test.go:157: test 6: line 3: fmt.Sprintf("%+v", err):
got: "error\ngithub.com/pkg/errors.TestFormatWrapf\n\t/tmp/errors/format_test.go:149\ntesting.tRunner\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/testing/testing.go:2036\nruntime.goexit\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/runtime/asm_amd64.s:1771\nerror2\ngithub.com/pkg/errors.TestFormatWrapf\n\t/tmp/errors/format_test.go:149\ntesting.tRunner\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/testing/testing.go:2036\nruntime.goexit\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/runtime/asm_amd64.s:1771"
want: "error\ngithub.com/pkg/errors.TestFormatWrapf\n\t.+/github.com/pkg/errors/format_test.go:149"
--- FAIL: TestFormatWrapf (0.00s)
=== RUN TestFormatWithStack
format_test.go:502: test 3: block 2: fmt.Sprintf("%+v", err):
got:
"github.com/pkg/errors.TestFormatWithStack\n\t/tmp/errors/format_test.go:175\ntesting.tRunner\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/testing/testing.go:2036\nruntime.goexit\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/runtime/asm_amd64.s:1771"
want:
"github.com/pkg/errors.TestFormatWithStack\n\t.+/github.com/pkg/errors/format_test.go:175"
all-got:
EOF
github.com/pkg/errors.TestFormatWithStack
/tmp/errors/format_test.go:175
testing.tRunner
/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/testing/testing.go:2036
runtime.goexit
/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/runtime/asm_amd64.s:1771
all-want:
EOF
github.com/pkg/errors.TestFormatWithStack
.+/github.com/pkg/errors/format_test.go:175
--- FAIL: TestFormatWithStack (0.00s)
=== RUN TestFormatWithMessage
format_test.go:502: test 3: block 2: fmt.Sprintf("%+v", err):
got:
"github.com/pkg/errors.TestFormatWithMessage\n\t/tmp/errors/format_test.go:244\ntesting.tRunner\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/testing/testing.go:2036\nruntime.goexit\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/runtime/asm_amd64.s:1771"
want:
"github.com/pkg/errors.TestFormatWithMessage\n\t.+/github.com/pkg/errors/format_test.go:244"
all-got:
error
github.com/pkg/errors.TestFormatWithMessage
/tmp/errors/format_test.go:244
testing.tRunner
/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/testing/testing.go:2036
runtime.goexit
/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/runtime/asm_amd64.s:1771
error2
all-want:
error
github.com/pkg/errors.TestFormatWithMessage
.+/github.com/pkg/errors/format_test.go:244
error2
--- FAIL: TestFormatWithMessage (0.00s)
=== RUN TestFormatGeneric
format_test.go:502: test 1: block 2: fmt.Sprintf("%+v", err):
got:
"github.com/pkg/errors.TestFormatGeneric\n\t/tmp/errors/format_test.go:315\ntesting.tRunner\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/testing/testing.go:2036\nruntime.goexit\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/runtime/asm_amd64.s:1771"
want:
"github.com/pkg/errors.TestFormatGeneric\n\t.+/github.com/pkg/errors/format_test.go:315"
all-got:
new-error
github.com/pkg/errors.TestFormatGeneric
/tmp/errors/format_test.go:315
testing.tRunner
/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/testing/testing.go:2036
runtime.goexit
/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/runtime/asm_amd64.s:1771
all-want:
new-error
github.com/pkg/errors.TestFormatGeneric
.+/github.com/pkg/errors/format_test.go:315
--- FAIL: TestFormatGeneric (0.00s)
=== RUN TestFormatWrappedNew
format_test.go:383: test 1: line 3: fmt.Sprintf("%+v", err):
got: "error\ngithub.com/pkg/errors.wrappedNew\n\t/tmp/errors/format_test.go:364\ngithub.com/pkg/errors.TestFormatWrappedNew\n\t/tmp/errors/format_test.go:373\ntesting.tRunner\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/testing/testing.go:2036\nruntime.goexit\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/runtime/asm_amd64.s:1771"
want: "error\ngithub.com/pkg/errors.wrappedNew\n\t.+/github.com/pkg/errors/format_test.go:364\ngithub.com/pkg/errors.TestFormatWrappedNew\n\t.+/github.com/pkg/errors/format_test.go:373"
format_test.go:383: test 1: line 5: fmt.Sprintf("%+v", err):
got: "error\ngithub.com/pkg/errors.wrappedNew\n\t/tmp/errors/format_test.go:364\ngithub.com/pkg/errors.TestFormatWrappedNew\n\t/tmp/errors/format_test.go:373\ntesting.tRunner\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/testing/testing.go:2036\nruntime.goexit\n\t/gnu/store/nqi0024l00rz8x6spkcal7hwyvsxpznj-go-1.26.1/lib/go/src/runtime/asm_amd64.s:1771"
want: "error\ngithub.com/pkg/errors.wrappedNew\n\t.+/github.com/pkg/errors/format_test.go:364\ngithub.com/pkg/errors.TestFormatWrappedNew\n\t.+/github.com/pkg/errors/format_test.go:373"
--- FAIL: TestFormatWrappedNew (0.00s)
=== RUN TestErrorChainCompat
--- PASS: TestErrorChainCompat (0.00s)
=== RUN TestIs
=== RUN TestIs/with_stack
=== RUN TestIs/with_message
=== RUN TestIs/with_message_format
=== RUN TestIs/std_errors_compatibility
--- PASS: TestIs (0.00s)
--- PASS: TestIs/with_stack (0.00s)
--- PASS: TestIs/with_message (0.00s)
--- PASS: TestIs/with_message_format (0.00s)
--- PASS: TestIs/std_errors_compatibility (0.00s)
=== RUN TestAs
=== RUN TestAs/with_stack
=== RUN TestAs/with_message
=== RUN TestAs/with_message_format
=== RUN TestAs/std_errors_compatibility
--- PASS: TestAs (0.00s)
--- PASS: TestAs/with_stack (0.00s)
--- PASS: TestAs/with_message (0.00s)
--- PASS: TestAs/with_message_format (0.00s)
--- PASS: TestAs/std_errors_compatibility (0.00s)
=== RUN TestUnwrap
=== RUN TestUnwrap/with_stack
=== RUN TestUnwrap/with_message
=== RUN TestUnwrap/with_message_format
=== RUN TestUnwrap/std_errors_compatibility
--- PASS: TestUnwrap (0.00s)
--- PASS: TestUnwrap/with_stack (0.00s)
--- PASS: TestUnwrap/with_message (0.00s)
--- PASS: TestUnwrap/with_message_format (0.00s)
--- PASS: TestUnwrap/std_errors_compatibility (0.00s)
=== RUN TestFrameMarshalText
json_test.go:26: test 1: MarshalJSON:
got "github.com/pkg/errors.init /tmp/errors/stack_test.go:9"
want "^github.com/pkg/errors\\.init(\\.ializers)? .+/github\\.com/pkg/errors/stack_test.go:\\d+$"
--- FAIL: TestFrameMarshalText (0.00s)
=== RUN TestFrameMarshalJSON
json_test.go:48: test 1: MarshalJSON:
got "\"github.com/pkg/errors.init /tmp/errors/stack_test.go:9\""
want "^\"github\\.com/pkg/errors\\.init(\\.ializers)? .+/github\\.com/pkg/errors/stack_test.go:\\d+\"$"
--- FAIL: TestFrameMarshalJSON (0.00s)
=== RUN TestFrameFormat
stack_test.go:91: test 2: line 2: fmt.Sprintf("%+s", err):
got: "github.com/pkg/errors.init\n\t/tmp/errors/stack_test.go"
want: "github.com/pkg/errors.init\n\t.+/github.com/pkg/errors/stack_test.go"
stack_test.go:91: test 12: line 2: fmt.Sprintf("%+v", err):
got: "github.com/pkg/errors.init\n\t/tmp/errors/stack_test.go:9"
want: "github.com/pkg/errors.init\n\t.+/github.com/pkg/errors/stack_test.go:9"
--- FAIL: TestFrameFormat (0.00s)
=== RUN TestFuncname
--- PASS: TestFuncname (0.00s)
=== RUN TestStackTrace
stack_test.go:166: test 1: line 2: fmt.Sprintf("%+v", err):
got: "github.com/pkg/errors.TestStackTrace\n\t/tmp/errors/stack_test.go:121"
want: "github.com/pkg/errors.TestStackTrace\n\t.+/github.com/pkg/errors/stack_test.go:121"
stack_test.go:166: test 2: line 2: fmt.Sprintf("%+v", err):
got: "github.com/pkg/errors.TestStackTrace\n\t/tmp/errors/stack_test.go:126"
want: "github.com/pkg/errors.TestStackTrace\n\t.+/github.com/pkg/errors/stack_test.go:126"
stack_test.go:166: test 3: line 2: fmt.Sprintf("%+v", err):
got: "github.com/pkg/errors.TestStackTrace\n\t/tmp/errors/stack_test.go:131"
want: "github.com/pkg/errors.TestStackTrace\n\t.+/github.com/pkg/errors/stack_test.go:131"
stack_test.go:166: test 4: line 2: fmt.Sprintf("%+v", err):
got: "github.com/pkg/errors.TestStackTrace.func1\n\t/tmp/errors/stack_test.go:136"
want: "github.com/pkg/errors.TestStackTrace.func1\n\t.+/github.com/pkg/errors/stack_test.go:136"
stack_test.go:166: test 4: line 2: fmt.Sprintf("%+v", err):
got: "github.com/pkg/errors.TestStackTrace\n\t/tmp/errors/stack_test.go:136"
want: "github.com/pkg/errors.TestStackTrace\n\t.+/github.com/pkg/errors/stack_test.go:136"
stack_test.go:166: test 5: line 1: fmt.Sprintf("%+v", err):
got: "github.com/pkg/errors.TestStackTrace.TestStackTrace.func2.func3\n\t/tmp/errors/stack_test.go:145"
want: "github.com/pkg/errors.TestStackTrace.func2.1\n\t.+/github.com/pkg/errors/stack_test.go:145"
stack_test.go:166: test 5: line 2: fmt.Sprintf("%+v", err):
got: "github.com/pkg/errors.TestStackTrace.TestStackTrace.func2.func3\n\t/tmp/errors/stack_test.go:145"
want: "github.com/pkg/errors.TestStackTrace.func2.1\n\t.+/github.com/pkg/errors/stack_test.go:145"
stack_test.go:166: test 5: line 2: fmt.Sprintf("%+v", err):
got: "github.com/pkg/errors.TestStackTrace.func2\n\t/tmp/errors/stack_test.go:146"
want: "github.com/pkg/errors.TestStackTrace.func2\n\t.+/github.com/pkg/errors/stack_test.go:146"
stack_test.go:166: test 5: line 2: fmt.Sprintf("%+v", err):
got: "github.com/pkg/errors.TestStackTrace\n\t/tmp/errors/stack_test.go:147"
want: "github.com/pkg/errors.TestStackTrace\n\t.+/github.com/pkg/errors/stack_test.go:147"
--- FAIL: TestStackTrace (0.00s)
=== RUN TestStackTraceFormat
stack_test.go:239: test 11: line 3: fmt.Sprintf("%+v", err):
got: "\ngithub.com/pkg/errors.stackTrace\n\t/tmp/errors/stack_test.go:174\ngithub.com/pkg/errors.TestStackTraceFormat\n\t/tmp/errors/stack_test.go:225"
want: "\ngithub.com/pkg/errors.stackTrace\n\t.+/github.com/pkg/errors/stack_test.go:174\ngithub.com/pkg/errors.TestStackTraceFormat\n\t.+/github.com/pkg/errors/stack_test.go:225"
stack_test.go:239: test 11: line 5: fmt.Sprintf("%+v", err):
got: "\ngithub.com/pkg/errors.stackTrace\n\t/tmp/errors/stack_test.go:174\ngithub.com/pkg/errors.TestStackTraceFormat\n\t/tmp/errors/stack_test.go:225"
want: "\ngithub.com/pkg/errors.stackTrace\n\t.+/github.com/pkg/errors/stack_test.go:174\ngithub.com/pkg/errors.TestStackTraceFormat\n\t.+/github.com/pkg/errors/stack_test.go:225"
--- FAIL: TestStackTraceFormat (0.00s)
=== RUN ExampleNew
--- PASS: ExampleNew (0.00s)
=== RUN ExampleWithMessage
--- PASS: ExampleWithMessage (0.00s)
=== RUN ExampleWithStack
--- PASS: ExampleWithStack (0.00s)
=== RUN ExampleWrap
--- PASS: ExampleWrap (0.00s)
=== RUN ExampleCause
--- PASS: ExampleCause (0.00s)
=== RUN ExampleWrapf
--- PASS: ExampleWrapf (0.00s)
=== RUN ExampleCause_printf
--- PASS: ExampleCause_printf (0.00s)
FAIL
FAIL github.com/pkg/errors 0.005s
FAIL
Hi,
I have tried to run tests and did not have much luck with it. Few problems are documented below.
How to run tests?
It is not clear how to run them (this is very much skill issue on my part). Usual
go test -vgivesI do not have experience with pre-modules golang, so I am sure there is a way, but would be nice to have it written somewhere. In the end I just followed the instructions and did:
vet complains
So to have the tests pass, one needs to run them with
-vet off.test failures
Some tests just fail: