mirror of
https://github.com/golang/go
synced 2024-11-05 17:36:15 -07:00
09281b52a1
The original CL 84050044 added a test case, and it happened to be in between various CLI test cases. CLI support was removed from x/tools/cmd/godoc in CL 141397, as part of golang/go#25443. Re-add a test case for this behavior to prevent regressions. Updates golang/go#32092 Updates golang/go#25443 Updates golang/go#5247 Change-Id: I0cea74cfe40d120e398a9005676134c5bad6136c Reviewed-on: https://go-review.googlesource.com/c/tools/+/177737 Reviewed-by: Robert Griesemer <gri@golang.org>
70 lines
1.9 KiB
Go
70 lines
1.9 KiB
Go
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package godoc
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"golang.org/x/tools/godoc/vfs/mapfs"
|
|
)
|
|
|
|
// TestIgnoredGoFiles tests the scenario where a folder has no .go or .c files,
|
|
// but has an ignored go file.
|
|
func TestIgnoredGoFiles(t *testing.T) {
|
|
packagePath := "github.com/package"
|
|
packageComment := "main is documented in an ignored .go file"
|
|
|
|
c := NewCorpus(mapfs.New(map[string]string{
|
|
"src/" + packagePath + "/ignored.go": `// +build ignore
|
|
|
|
// ` + packageComment + `
|
|
package main`}))
|
|
srv := &handlerServer{
|
|
p: &Presentation{
|
|
Corpus: c,
|
|
},
|
|
c: c,
|
|
}
|
|
pInfo := srv.GetPageInfo("/src/"+packagePath, packagePath, NoFiltering, "linux", "amd64")
|
|
|
|
if pInfo.PDoc == nil {
|
|
t.Error("pInfo.PDoc = nil; want non-nil.")
|
|
} else {
|
|
if got, want := pInfo.PDoc.Doc, packageComment+"\n"; got != want {
|
|
t.Errorf("pInfo.PDoc.Doc = %q; want %q.", got, want)
|
|
}
|
|
if got, want := pInfo.PDoc.Name, "main"; got != want {
|
|
t.Errorf("pInfo.PDoc.Name = %q; want %q.", got, want)
|
|
}
|
|
if got, want := pInfo.PDoc.ImportPath, packagePath; got != want {
|
|
t.Errorf("pInfo.PDoc.ImportPath = %q; want %q.", got, want)
|
|
}
|
|
}
|
|
if pInfo.FSet == nil {
|
|
t.Error("pInfo.FSet = nil; want non-nil.")
|
|
}
|
|
}
|
|
|
|
func TestIssue5247(t *testing.T) {
|
|
const packagePath = "example.com/p"
|
|
c := NewCorpus(mapfs.New(map[string]string{
|
|
"src/" + packagePath + "/p.go": `package p
|
|
|
|
//line notgen.go:3
|
|
// F doc //line 1 should appear
|
|
// line 2 should appear
|
|
func F()
|
|
//line foo.go:100`})) // No newline at end to check corner cases.
|
|
|
|
srv := &handlerServer{
|
|
p: &Presentation{Corpus: c},
|
|
c: c,
|
|
}
|
|
pInfo := srv.GetPageInfo("/src/"+packagePath, packagePath, 0, "linux", "amd64")
|
|
if got, want := pInfo.PDoc.Funcs[0].Doc, "F doc //line 1 should appear\nline 2 should appear\n"; got != want {
|
|
t.Errorf("pInfo.PDoc.Funcs[0].Doc = %q; want %q", got, want)
|
|
}
|
|
}
|