Skip to content

Commit bfb5194

Browse files
committed
Revert "godoc: skip build tag annotations when displaying examples"
This reverts commit faa8a71. Reason for revert: +build tag in test causes build to fail :( Change-Id: I8942a6dcc29faaceada23b63ba80ea881b3b2ca6 Reviewed-on: https://go-review.googlesource.com/126195 Reviewed-by: Andrew Bonventre <[email protected]> Run-TryBot: Andrew Bonventre <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent faa8a71 commit bfb5194

File tree

2 files changed

+0
-63
lines changed

2 files changed

+0
-63
lines changed

godoc/godoc.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,6 @@ func (p *Presentation) example_htmlFunc(info *PageInfo, funcName string) string
666666
play := ""
667667
if eg.Play != nil && p.ShowPlayground {
668668
var buf bytes.Buffer
669-
eg.Play.Comments = filterOutBuildAnnotations(eg.Play.Comments)
670669
if err := format.Node(&buf, info.FSet, eg.Play); err != nil {
671670
log.Print(err)
672671
} else {
@@ -695,23 +694,6 @@ func (p *Presentation) example_htmlFunc(info *PageInfo, funcName string) string
695694
return buf.String()
696695
}
697696

698-
func filterOutBuildAnnotations(cg []*ast.CommentGroup) []*ast.CommentGroup {
699-
if len(cg) == 0 {
700-
return cg
701-
}
702-
703-
for i := range cg {
704-
if !strings.HasPrefix(cg[i].Text(), "+build ") {
705-
// Found the first non-build tag, return from here until the end
706-
// of the slice.
707-
return cg[i:]
708-
}
709-
}
710-
711-
// There weren't any non-build tags, return an empty slice.
712-
return []*ast.CommentGroup{}
713-
}
714-
715697
// example_nameFunc takes an example function name and returns its display
716698
// name. For example, "Foo_Bar_quux" becomes "Foo.Bar (Quux)".
717699
func (p *Presentation) example_nameFunc(s string) string {

godoc/godoc_test.go

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -321,48 +321,3 @@ func TestSrcToPkgLinkFunc(t *testing.T) {
321321
}
322322
}
323323
}
324-
325-
func TestFilterOutBuildAnnotations(t *testing.T) {
326-
src := []byte(`
327-
// +build !foo
328-
// +build !anothertag
329-
330-
// non-tag comment
331-
332-
package foo
333-
334-
func bar() int {
335-
return 42
336-
}`)
337-
338-
fset := token.NewFileSet()
339-
af, err := parser.ParseFile(fset, "foo.go", src, parser.ParseComments)
340-
if err != nil {
341-
t.Fatal(err)
342-
}
343-
344-
var found bool
345-
for _, cg := range af.Comments {
346-
if strings.HasPrefix(cg.Text(), "+build ") {
347-
found = true
348-
break
349-
}
350-
}
351-
if !found {
352-
t.Errorf("TestFilterOutBuildAnnotations is broken: missing build tag in test input")
353-
}
354-
355-
found = false
356-
for _, cg := range filterOutBuildAnnotations(af.Comments) {
357-
if strings.HasPrefix(cg.Text(), "+build ") {
358-
t.Errorf("filterOutBuildAnnotations failed to filter build tag")
359-
}
360-
361-
if strings.Contains(cg.Text(), "non-tag comment") {
362-
found = true
363-
}
364-
}
365-
if !found {
366-
t.Errorf("filterOutBuildAnnotations should not remove non-build tag comment")
367-
}
368-
}

0 commit comments

Comments
 (0)