Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Go tests

on:
push:
branches: [master]
pull_request:

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache-dependency-path: go.sum
Comment thread
kennytm marked this conversation as resolved.
Resolved
- run: go vet ./...
- run: go test -cover -coverprofile=coverage.out ./...
- name: Check coverage # TODO: increase minimum after adding more tests
run: |
awk -v minimum=0 '
NR > 1 {
total += $2
if ($3 > 0) covered += $2
}
END {
if (total == 0) {
print "No statement coverage data"
exit 1
}
printf "Total statement coverage: %.2f%% (minimum: %d%%)\n", 100 * covered / total, minimum
exit (100 * covered < minimum * total)
}
' coverage.out
44 changes: 22 additions & 22 deletions format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestFormatNew(t *testing.T) {
"%+v",
"error\n" +
"github.com/pingcap/errors.TestFormatNew\n" +
"\t.+/pingcap/errors/format_test.go:26",
"\t.+/format_test.go:26",
}, {
New("error"),
"%q",
Expand Down Expand Up @@ -57,7 +57,7 @@ func TestFormatErrorf(t *testing.T) {
"%+v",
"error\n" +
"github.com/pingcap/errors.TestFormatErrorf\n" +
"\t.+/pingcap/errors/format_test.go:56",
"\t.+/format_test.go:56",
}}

for i, tt := range tests {
Expand All @@ -83,7 +83,7 @@ func TestFormatWrap(t *testing.T) {
"%+v",
"error\n" +
"github.com/pingcap/errors.TestFormatWrap\n" +
"\t.+/pingcap/errors/format_test.go:82",
"\t.+/format_test.go:82",
}, {
Annotate(io.EOF, "error"),
"%s",
Expand All @@ -98,14 +98,14 @@ func TestFormatWrap(t *testing.T) {
"EOF\n" +
"error\n" +
"github.com/pingcap/errors.TestFormatWrap\n" +
"\t.+/pingcap/errors/format_test.go:96",
"\t.+/format_test.go:96",
}, {
Annotate(Annotate(io.EOF, "error1"), "error2"),
"%+v",
"EOF\n" +
"error1\n" +
"github.com/pingcap/errors.TestFormatWrap\n" +
"\t.+/pingcap/errors/format_test.go:103\n",
"\t.+/format_test.go:103\n",
}, {
Annotate(New("error with space"), "context"),
"%q",
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestFormatWrapf(t *testing.T) {
"EOF\n" +
"error2\n" +
"github.com/pingcap/errors.TestFormatWrapf\n" +
"\t.+/pingcap/errors/format_test.go:134",
"\t.+/format_test.go:134",
}, {
Annotatef(New("error"), "error%d", 2),
"%s",
Expand All @@ -150,7 +150,7 @@ func TestFormatWrapf(t *testing.T) {
"%+v",
"error\n" +
"github.com/pingcap/errors.TestFormatWrapf\n" +
"\t.+/pingcap/errors/format_test.go:149",
"\t.+/format_test.go:149",
}}

for i, tt := range tests {
Expand All @@ -176,7 +176,7 @@ func TestFormatWithStack(t *testing.T) {
"%+v",
[]string{"EOF",
"github.com/pingcap/errors.TestFormatWithStack\n" +
"\t.+/pingcap/errors/format_test.go:175"},
"\t.+/format_test.go:175"},
}, {
WithStack(New("error")),
"%s",
Expand All @@ -190,36 +190,36 @@ func TestFormatWithStack(t *testing.T) {
"%+v",
[]string{"error",
"github.com/pingcap/errors.TestFormatWithStack\n" +
"\t.+/pingcap/errors/format_test.go:189",
"\t.+/format_test.go:189",
"github.com/pingcap/errors.TestFormatWithStack\n" +
"\t.+/pingcap/errors/format_test.go:189"},
"\t.+/format_test.go:189"},
}, {
WithStack(WithStack(io.EOF)),
"%+v",
[]string{"EOF",
"github.com/pingcap/errors.TestFormatWithStack\n" +
"\t.+/pingcap/errors/format_test.go:197",
"\t.+/format_test.go:197",
"github.com/pingcap/errors.TestFormatWithStack\n" +
"\t.+/pingcap/errors/format_test.go:197"},
"\t.+/format_test.go:197"},
}, {
WithStack(WithStack(Annotatef(io.EOF, "message"))),
"%+v",
[]string{"EOF",
"message",
"github.com/pingcap/errors.TestFormatWithStack\n" +
"\t.+/pingcap/errors/format_test.go:205",
"\t.+/format_test.go:205",
"github.com/pingcap/errors.TestFormatWithStack\n" +
"\t.+/pingcap/errors/format_test.go:205",
"\t.+/format_test.go:205",
"github.com/pingcap/errors.TestFormatWithStack\n" +
"\t.+/pingcap/errors/format_test.go:205"},
"\t.+/format_test.go:205"},
}, {
WithStack(Errorf("error%d", 1)),
"%+v",
[]string{"error1",
"github.com/pingcap/errors.TestFormatWithStack\n" +
"\t.+/pingcap/errors/format_test.go:216",
"\t.+/format_test.go:216",
"github.com/pingcap/errors.TestFormatWithStack\n" +
"\t.+/pingcap/errors/format_test.go:216"},
"\t.+/format_test.go:216"},
}}

for i, tt := range tests {
Expand All @@ -246,7 +246,7 @@ func TestFormatWithMessage(t *testing.T) {
[]string{
"error",
"github.com/pingcap/errors.TestFormatWithMessage\n" +
"\t.+/pingcap/errors/format_test.go:244",
"\t.+/format_test.go:244",
"error2"},
}, {
WithMessage(io.EOF, "addition1"),
Expand All @@ -273,29 +273,29 @@ func TestFormatWithMessage(t *testing.T) {
"%+v",
[]string{"EOF", "error1", "error2",
"github.com/pingcap/errors.TestFormatWithMessage\n" +
"\t.+/pingcap/errors/format_test.go:272"},
"\t.+/format_test.go:272"},
}, {
WithMessage(Errorf("error%d", 1), "error2"),
"%+v",
[]string{"error1",
"github.com/pingcap/errors.TestFormatWithMessage\n" +
"\t.+/pingcap/errors/format_test.go:278",
"\t.+/format_test.go:278",
"error2"},
}, {
WithMessage(WithStack(io.EOF), "error"),
"%+v",
[]string{
"EOF",
"github.com/pingcap/errors.TestFormatWithMessage\n" +
"\t.+/pingcap/errors/format_test.go:285",
"\t.+/format_test.go:285",
"error"},
}, {
WithMessage(Annotate(WithStack(io.EOF), "inside-error"), "outside-error"),
"%+v",
[]string{
"EOF",
"github.com/pingcap/errors.TestFormatWithMessage\n" +
"\t.+/pingcap/errors/format_test.go:293",
"\t.+/format_test.go:293",
"inside-error",
"outside-error"},
}}
Expand Down
24 changes: 12 additions & 12 deletions stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestFrameFormat(t *testing.T) {
Frame(initpc),
"%+s",
"github.com/pingcap/errors.init\n" +
"\t.+/pingcap/errors/stack_test.go",
"\t.+/stack_test.go",
}, {
Frame(0),
"%s",
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestFrameFormat(t *testing.T) {
Frame(initpc),
"%+v",
"github.com/pingcap/errors.init\n" +
"\t.+/pingcap/errors/stack_test.go:11",
"\t.+/stack_test.go:11",
}, {
Frame(0),
"%v",
Expand Down Expand Up @@ -155,24 +155,24 @@ func TestStackTrace(t *testing.T) {
}{{
New("ooh"), []string{
"github.com/pingcap/errors.TestStackTrace\n" +
"\t.+/pingcap/errors/stack_test.go",
"\t.+/stack_test.go",
},
}, {
Annotate(New("ooh"), "ahh"), []string{
"github.com/pingcap/errors.TestStackTrace\n" +
"\t.+/pingcap/errors/stack_test.go", // this is the stack of Wrap, not New
"\t.+/stack_test.go", // this is the stack of Wrap, not New
},
}, {
Cause(Annotate(New("ooh"), "ahh")), []string{
"github.com/pingcap/errors.TestStackTrace\n" +
"\t.+/pingcap/errors/stack_test.go", // this is the stack of New
"\t.+/stack_test.go", // this is the stack of New
},
}, {
func() error { return New("ooh") }(), []string{
`github.com/pingcap/errors.(func·009|TestStackTrace.func1)` +
"\n\t.+/pingcap/errors/stack_test.go", // this is the stack of New
"\n\t.+/stack_test.go", // this is the stack of New
"github.com/pingcap/errors.TestStackTrace\n" +
"\t.+/pingcap/errors/stack_test.go", // this is the stack of New's caller
"\t.+/stack_test.go", // this is the stack of New's caller
},
}, {
Cause(func() error {
Expand All @@ -183,11 +183,11 @@ func TestStackTrace(t *testing.T) {
// go 1.23 when Debug its suffix is "TestStackTrace.func2.1", it's
// "TestStackTrace.TestStackTrace.func2.func3" when Run
`github.com/pingcap/errors.(func·010|TestStackTrace.func2.1|TestStackTrace.TestStackTrace.func2.func3)` +
"\n\t.+/pingcap/errors/stack_test.go", // this is the stack of Errorf
"\n\t.+/stack_test.go", // this is the stack of Errorf
`github.com/pingcap/errors.(func·011|TestStackTrace.func2)` +
"\n\t.+/pingcap/errors/stack_test.go", // this is the stack of Errorf's caller
"\n\t.+/stack_test.go", // this is the stack of Errorf's caller
"github.com/pingcap/errors.TestStackTrace\n" +
"\t.+/pingcap/errors/stack_test.go", // this is the stack of Errorf's caller's caller
"\t.+/stack_test.go", // this is the stack of Errorf's caller's caller
},
}}
for i, tt := range tests {
Expand Down Expand Up @@ -266,9 +266,9 @@ func TestStackTraceFormat(t *testing.T) {
"%+v",
"\n" +
"github.com/pingcap/errors.stackTrace\n" +
"\t.+/pingcap/errors/stack_test.go:\\d+\n" +
"\t.+/stack_test.go:\\d+\n" +
"github.com/pingcap/errors.TestStackTraceFormat\n" +
"\t.+/pingcap/errors/stack_test.go:\\d+",
"\t.+/stack_test.go:\\d+",
}, {
stackTrace()[:2],
"%#v",
Expand Down
Loading