Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve panic stack trace (#96) #96

Merged
merged 1 commit into from
Oct 30, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: 1.23.2
cache: false

- name: Checkout code
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export GOPATH ?= $(shell $(GO) env GOPATH)
export GOBIN ?= $(GOPATH)/bin

# Setup go-make version to use desired build and config scripts.
GOMAKE_DEP ?= github.com/tkrop/[email protected].106
GOMAKE_DEP ?= github.com/tkrop/[email protected].108
INSTALL_FLAGS ?= -mod=readonly -buildvcs=auto
# Request targets from go-make targets target.
TARGETS := $(shell command -v $(GOBIN)/go-make >/dev/null || \
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.21
0.0.22
16 changes: 7 additions & 9 deletions test/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package test

import (
"math"
"regexp"
"runtime"
"runtime/debug"
"strings"
gosync "sync"
"sync/atomic"
"testing"
Expand Down Expand Up @@ -450,10 +450,10 @@ func (t *Context) Failed() bool {
return t.failed.Load()
}

// Offset fr original stack in case of panic handling.
//
// TODO: check offset or/and find a better solution to handle panic stack.
const panicOriginStackOffset = 10
// regexPanic is a regular expression to extract the actual important panic
// stack trace removing the distracting parts from the test framework.
var regexPanic = regexp.MustCompile(`(?m)\nruntime\/debug\.Stack\(\)` +
`(\n|.)*runtime\/panic\.go:([0-9]+)[^\n]*\n`)

// Panic handles failure notifications of panics that also abort the test
// execution immediately.
Expand All @@ -469,10 +469,8 @@ func (t *Context) Panic(arg any) {
defer t.unlock()

if t.expect == Success {
stack := strings.SplitN(string(debug.Stack()),
"\n", panicOriginStackOffset)
t.Fatalf("panic: %v\n%s\n%s", arg, stack[0],
stack[panicOriginStackOffset-1])
stack := regexPanic.Split(string(debug.Stack()), -1)
t.Fatalf("panic: %v\n%s\n%s", arg, stack[0], stack[1])
} else if t.reporter != nil {
t.reporter.Panic(arg)
}
Expand Down
1 change: 0 additions & 1 deletion test/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ type TestDeadlineParam struct {
failure test.Expect
}

// TODO: fix unit test for deadline!!
var TestDeadlineParams = map[string]TestDeadlineParam{
"failed": {
time: 0,
Expand Down
Loading