Skip to content

Commit

Permalink
Check version manually without external packages
Browse files Browse the repository at this point in the history
  • Loading branch information
DariaKunoichi committed Feb 19, 2024
1 parent 36e411d commit e004cea
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
23 changes: 9 additions & 14 deletions v2/errors/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"
"testing"

"github.com/hashicorp/go-version"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -51,26 +50,22 @@ func TestParsePanicStack(t *testing.T) {
StackFrame{Name: "gopanic"},
}

golangVersion, verr := version.NewVersion(strings.TrimPrefix(runtime.Version(), "go"))
if verr != nil {
t.Errorf("Failed to check golang version")
}
golangVersion := runtime.Version()

// TODO remove this after dropping support for Golang 1.11
// Golang version < 1.12 cannot unwrap inlined functions correctly.
constraints, verr := version.NewConstraint("< 1.12")
if constraints.Check(golangVersion) {
if strings.HasPrefix(golangVersion, "go1.11") {
expected = append(expected,
StackFrame{Name: "a", File: "errors/error_test.go", LineNumber: 30},
StackFrame{Name: "a", File: "errors/error_test.go", LineNumber: 30},
StackFrame{Name: "a", File: "errors/error_test.go", LineNumber: 17},
StackFrame{Name: "a", File: "errors/error_test.go", LineNumber: 29},
StackFrame{Name: "a", File: "errors/error_test.go", LineNumber: 29},
StackFrame{Name: "a", File: "errors/error_test.go", LineNumber: 16},
)
} else {
// For versions >= 1.12 inlined functions show normally
expected = append(expected,
StackFrame{Name: "c", File: "errors/error_test.go", LineNumber: 30},
StackFrame{Name: "b", File: "errors/error_test.go", LineNumber: 24},
StackFrame{Name: "a", File: "errors/error_test.go", LineNumber: 17},
StackFrame{Name: "c", File: "errors/error_test.go", LineNumber: 29},
StackFrame{Name: "b", File: "errors/error_test.go", LineNumber: 23},
StackFrame{Name: "a", File: "errors/error_test.go", LineNumber: 16},
)
}

Expand Down Expand Up @@ -116,7 +111,7 @@ func TestSkipWorks(t *testing.T) {
}

expected := []StackFrame{
StackFrame{Name: "a", File: "errors/error_test.go", LineNumber: 17},
StackFrame{Name: "a", File: "errors/error_test.go", LineNumber: 16},
}

assertStacksMatch(t, expected, err.StackFrames())
Expand Down
1 change: 0 additions & 1 deletion v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/bitly/go-simplejson v0.5.1
github.com/bugsnag/panicwrap v1.3.4
github.com/google/uuid v1.6.0
github.com/hashicorp/go-version v1.6.0
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
github.com/pkg/errors v0.9.1
)
2 changes: 0 additions & 2 deletions v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ github.com/bugsnag/panicwrap v1.3.4 h1:A6sXFtDGsgU/4BLf5JT0o5uYg3EeKgGx3Sfs+/uk3
github.com/bugsnag/panicwrap v1.3.4/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down

0 comments on commit e004cea

Please sign in to comment.