Skip to content

Commit 937f872

Browse files
committed
stack: make stdlib src link work even on devel Go build
Process the development Go version to extract the git commit and use this as a reference. Obviously this won't work if the commit is not upstream but for people testing public code, this may be useful. Make unit test pass on non-release Go build.
1 parent 7dc7e59 commit 937f872

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

internal/internaltest/internaltest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ var (
148148
// Ignores the revision (go1.<minor>.<revision>).
149149
func GetGoMinorVersion() int {
150150
ver := runtime.Version()
151-
if strings.HasPrefix(ver, "devel ") {
151+
if strings.HasPrefix(ver, "devel +") {
152152
return 0
153153
}
154154
if !strings.HasPrefix(ver, "go1.") {

stack/html.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,12 @@ func getSrcBranchURL(c *Call) (template.URL, template.URL) {
134134
if c.Location == Stdlib {
135135
// TODO(maruel): This is not strictly speaking correct. The remote could be
136136
// running a different Go version from the current executable.
137-
tag = url.QueryEscape(runtime.Version())
137+
ver := runtime.Version()
138+
const devel = "devel +"
139+
if strings.HasPrefix(ver, devel) {
140+
ver = ver[len(devel) : len(devel)+10]
141+
}
142+
tag = url.QueryEscape(ver)
138143
return template.URL(fmt.Sprintf("https://github.com/golang/go/blob/%s/src/%s#L%d", tag, escape(c.RelSrcPath), c.Line)), template.URL(tag)
139144
}
140145
// TODO(maruel): Leverage Location.

stack/html_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"html/template"
1111
"io"
1212
"io/ioutil"
13+
"net/url"
1314
"regexp"
1415
"runtime"
1516
"strings"
@@ -81,6 +82,11 @@ func TestGenerate(t *testing.T) {
8182
func TestGetSrcBranchURL(t *testing.T) {
8283
t.Parallel()
8384
ver := runtime.Version()
85+
const prefix = "devel +"
86+
if strings.HasPrefix(ver, prefix) {
87+
ver = ver[len(prefix) : len(prefix)+10]
88+
}
89+
ver = url.QueryEscape(ver)
8490
data := []struct {
8591
name string
8692
c Call

0 commit comments

Comments
 (0)