godoc: Remove bogus messages referring to "/target".
Fix package text display spacing. Fixes golang/go#7395. R=bradfitz, sameer CC=golang-codereviews https://golang.org/cl/68210043
This commit is contained in:
parent
246da56072
commit
aaca3a4f95
|
@ -11,6 +11,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -32,6 +33,18 @@ var godocTests = []struct {
|
||||||
`WriteString writes the contents of the string s to w`,
|
`WriteString writes the contents of the string s to w`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
[]string{"nonexistingpkg"},
|
||||||
|
[]string{
|
||||||
|
`no such file or directory`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
[]string{"fmt", "NonexistentSymbol"},
|
||||||
|
[]string{
|
||||||
|
`No match found\.`,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Basic regression test for godoc command-line tool.
|
// Basic regression test for godoc command-line tool.
|
||||||
|
@ -59,15 +72,10 @@ func TestGodoc(t *testing.T) {
|
||||||
t.Errorf("Running with args %#v: %v", test.args, err)
|
t.Errorf("Running with args %#v: %v", test.args, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
logged := false
|
|
||||||
for _, pat := range test.matches {
|
for _, pat := range test.matches {
|
||||||
re := regexp.MustCompile(pat)
|
re := regexp.MustCompile(pat)
|
||||||
if !re.Match(out) {
|
if !re.Match(out) {
|
||||||
if !logged {
|
t.Errorf("godoc %v =\n%s\nwanted /%v/", strings.Join(test.args, " "), out, pat)
|
||||||
t.Logf("Output of running with args %#v:\n%s", test.args, out)
|
|
||||||
logged = true
|
|
||||||
}
|
|
||||||
t.Errorf("Did not match /%v/", pat)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,11 @@ func CommandLine(w io.Writer, fs vfs.NameSpace, pres *Presentation, args []strin
|
||||||
// contains only subdirectory information
|
// contains only subdirectory information
|
||||||
if info.PAst == nil && info.PDoc == nil {
|
if info.PAst == nil && info.PDoc == nil {
|
||||||
info = cinfo
|
info = cinfo
|
||||||
} else {
|
} else if relpath != target {
|
||||||
|
// The above check handles the case where an operating system path
|
||||||
|
// is provided (see documentation for paths below). In that case,
|
||||||
|
// relpath is set to "/target" (in anticipation of accessing packages there),
|
||||||
|
// and is therefore not expected to match a command.
|
||||||
fmt.Fprintf(w, "use 'godoc %s%s' for documentation on the %s command \n\n", cmdPrefix, relpath, relpath)
|
fmt.Fprintf(w, "use 'godoc %s%s' for documentation on the %s command \n\n", cmdPrefix, relpath, relpath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,12 +168,18 @@ func First() {
|
||||||
// Second function is second.
|
// Second function is second.
|
||||||
func Second() {
|
func Second() {
|
||||||
}
|
}
|
||||||
|
`,
|
||||||
|
"src/pkg/vet/vet.go": `// Package vet
|
||||||
|
package vet
|
||||||
`,
|
`,
|
||||||
"src/cmd/go/doc.go": `// The go command
|
"src/cmd/go/doc.go": `// The go command
|
||||||
package main
|
package main
|
||||||
`,
|
`,
|
||||||
"src/cmd/gofmt/doc.go": `// The gofmt command
|
"src/cmd/gofmt/doc.go": `// The gofmt command
|
||||||
package main
|
package main
|
||||||
|
`,
|
||||||
|
"src/cmd/vet/vet.go": `// The vet command
|
||||||
|
package main
|
||||||
`,
|
`,
|
||||||
})
|
})
|
||||||
fs := make(vfs.NameSpace)
|
fs := make(vfs.NameSpace)
|
||||||
|
@ -209,6 +215,11 @@ package main
|
||||||
args: []string{"foo", "First"},
|
args: []string{"foo", "First"},
|
||||||
exp: "PACKAGE \nfunc First()\n First function is first.\n",
|
exp: "PACKAGE \nfunc First()\n First function is first.\n",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "package w. bad filter",
|
||||||
|
args: []string{"foo", "DNE"},
|
||||||
|
exp: "PACKAGE ",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
desc: "source mode",
|
desc: "source mode",
|
||||||
args: []string{"src/bar"},
|
args: []string{"src/bar"},
|
||||||
|
@ -234,6 +245,16 @@ package main
|
||||||
args: []string{"doesnotexist"},
|
args: []string{"doesnotexist"},
|
||||||
err: true,
|
err: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "both command and package",
|
||||||
|
args: []string{"vet"},
|
||||||
|
exp: "use 'godoc cmd/vet' for documentation on the vet command \n\nPACKAGE Package vet\n",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "root directory",
|
||||||
|
args: []string{"/"},
|
||||||
|
exp: "",
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
w := new(bytes.Buffer)
|
w := new(bytes.Buffer)
|
||||||
err := CommandLine(w, fs, p, tc.args)
|
err := CommandLine(w, fs, p, tc.args)
|
||||||
|
|
|
@ -208,9 +208,17 @@ func comment_htmlFunc(comment string) string {
|
||||||
// want to avoid that mistake here.
|
// want to avoid that mistake here.
|
||||||
const punchCardWidth = 80
|
const punchCardWidth = 80
|
||||||
|
|
||||||
|
func containsOnlySpace(buf []byte) bool {
|
||||||
|
isNotSpace := func(r rune) bool { return !unicode.IsSpace(r) }
|
||||||
|
return bytes.IndexFunc(buf, isNotSpace) == -1
|
||||||
|
}
|
||||||
|
|
||||||
func comment_textFunc(comment, indent, preIndent string) string {
|
func comment_textFunc(comment, indent, preIndent string) string {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
doc.ToText(&buf, comment, indent, preIndent, punchCardWidth-2*len(indent))
|
doc.ToText(&buf, comment, indent, preIndent, punchCardWidth-2*len(indent))
|
||||||
|
if containsOnlySpace(buf.Bytes()) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
|
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
*/}}{{with .PDoc}}{{if $.IsMain}}COMMAND DOCUMENTATION
|
*/}}{{if and $filtered (not .PDoc)}}No match found.
|
||||||
|
{{end}}{{with .PDoc}}{{if $.IsMain}}COMMAND DOCUMENTATION
|
||||||
|
|
||||||
{{comment_text .Doc " " "\t"}}
|
{{comment_text .Doc " " "\t"}}
|
||||||
{{else}}{{if not $filtered}}PACKAGE DOCUMENTATION
|
{{else}}{{if not $filtered}}PACKAGE DOCUMENTATION
|
||||||
|
@ -20,8 +21,7 @@ package {{.Name}}
|
||||||
|
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
*/}}{{with .Consts}}{{if not $filtered}}
|
*/}}{{with .Consts}}{{if not $filtered}}CONSTANTS
|
||||||
CONSTANTS
|
|
||||||
|
|
||||||
{{end}}{{range .}}{{node $ .Decl}}
|
{{end}}{{range .}}{{node $ .Decl}}
|
||||||
{{comment_text .Doc " " "\t"}}
|
{{comment_text .Doc " " "\t"}}
|
||||||
|
@ -29,8 +29,7 @@ CONSTANTS
|
||||||
|
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
*/}}{{with .Vars}}{{if not $filtered}}
|
*/}}{{with .Vars}}{{if not $filtered}}VARIABLES
|
||||||
VARIABLES
|
|
||||||
|
|
||||||
{{end}}{{range .}}{{node $ .Decl}}
|
{{end}}{{range .}}{{node $ .Decl}}
|
||||||
{{comment_text .Doc " " "\t"}}
|
{{comment_text .Doc " " "\t"}}
|
||||||
|
@ -38,8 +37,7 @@ VARIABLES
|
||||||
|
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
*/}}{{with .Funcs}}{{if not $filtered}}
|
*/}}{{with .Funcs}}{{if not $filtered}}FUNCTIONS
|
||||||
FUNCTIONS
|
|
||||||
|
|
||||||
{{end}}{{range .}}{{node $ .Decl}}
|
{{end}}{{range .}}{{node $ .Decl}}
|
||||||
{{comment_text .Doc " " "\t"}}
|
{{comment_text .Doc " " "\t"}}
|
||||||
|
@ -47,23 +45,48 @@ FUNCTIONS
|
||||||
|
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
*/}}{{with .Types}}{{if not $filtered}}
|
*/}}{{with .Types}}{{if not $filtered}}TYPES
|
||||||
TYPES
|
|
||||||
|
|
||||||
{{end}}{{range .}}{{$tname := .Name}}{{node $ .Decl}}
|
{{end}}{{range .}}{{$tname := .Name}}{{node $ .Decl}}
|
||||||
{{comment_text .Doc " " "\t"}}
|
{{comment_text .Doc " " "\t"}}
|
||||||
{{range .Consts}}{{node $ .Decl}}
|
{{/*
|
||||||
|
|
||||||
|
---------------------------------------
|
||||||
|
|
||||||
|
*/}}{{if .Consts}}{{range .Consts}}{{node $ .Decl}}
|
||||||
{{comment_text .Doc " " "\t"}}
|
{{comment_text .Doc " " "\t"}}
|
||||||
{{end}}{{range .Vars}}{{node $ .Decl}}
|
{{end}}{{end}}{{/*
|
||||||
|
|
||||||
|
---------------------------------------
|
||||||
|
|
||||||
|
*/}}{{if .Vars}}{{range .Vars}}{{node $ .Decl}}
|
||||||
{{comment_text .Doc " " "\t"}}
|
{{comment_text .Doc " " "\t"}}
|
||||||
{{end}}{{example_text $ .Name " "}}
|
{{example_text $ .Name " "}}{{end}}{{end}}{{/*
|
||||||
{{range .Funcs}}{{node $ .Decl}}
|
|
||||||
|
---------------------------------------
|
||||||
|
|
||||||
|
*/}}{{if .Funcs}}{{range .Funcs}}{{node $ .Decl}}
|
||||||
{{comment_text .Doc " " "\t"}}
|
{{comment_text .Doc " " "\t"}}
|
||||||
{{example_text $ .Name " "}}
|
{{example_text $ .Name " "}}{{end}}{{end}}{{/*
|
||||||
{{end}}{{range .Methods}}{{node $ .Decl}}
|
|
||||||
|
---------------------------------------
|
||||||
|
|
||||||
|
*/}}{{if .Methods}}{{range .Methods}}{{node $ .Decl}}
|
||||||
{{comment_text .Doc " " "\t"}}
|
{{comment_text .Doc " " "\t"}}
|
||||||
{{$name := printf "%s_%s" $tname .Name}}{{example_text $ $name " "}}{{end}}
|
{{$name := printf "%s_%s" $tname .Name}}{{example_text $ $name " "}}{{end}}{{end}}{{/*
|
||||||
{{end}}{{end}}{{end}}{{/*
|
|
||||||
|
---------------------------------------
|
||||||
|
|
||||||
|
*/}}{{end}}{{end}}{{/*
|
||||||
|
|
||||||
|
---------------------------------------
|
||||||
|
|
||||||
|
*/}}{{if and $filtered (not (or .Consts (or .Vars (or .Funcs .Types))))}}No match found.
|
||||||
|
{{end}}{{/*
|
||||||
|
|
||||||
|
---------------------------------------
|
||||||
|
|
||||||
|
*/}}{{end}}{{/*
|
||||||
|
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
|
@ -76,10 +99,16 @@ TYPES
|
||||||
|
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
*/}}{{with .Dirs}}
|
*/}}{{if not $filtered}}{{with .Dirs}}SUBDIRECTORIES
|
||||||
SUBDIRECTORIES
|
|
||||||
{{if $.DirFlat}}{{range .List}}{{if .HasPkg}}
|
{{if $.DirFlat}}{{range .List}}{{if .HasPkg}}
|
||||||
{{.Path}}{{end}}{{end}}
|
{{.Path}}{{end}}{{end}}
|
||||||
{{else}}{{range .List}}
|
{{else}}{{range .List}}
|
||||||
{{repeat `. ` .Depth}}{{.Name}}{{end}}
|
{{repeat `. ` .Depth}}{{.Name}}{{end}}
|
||||||
{{end}}{{end}}
|
{{end}}{{end}}{{/*
|
||||||
|
|
||||||
|
---------------------------------------
|
||||||
|
|
||||||
|
*/}}{{end}}{{/*
|
||||||
|
Make sure there is no newline at the end of this file.
|
||||||
|
perl -i -pe 'chomp if eof' package.txt
|
||||||
|
*/}}
|
|
@ -762,7 +762,8 @@ $(document).ready(function() {
|
||||||
|
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
*/}}{{with .PDoc}}{{if $.IsMain}}COMMAND DOCUMENTATION
|
*/}}{{if and $filtered (not .PDoc)}}No match found.
|
||||||
|
{{end}}{{with .PDoc}}{{if $.IsMain}}COMMAND DOCUMENTATION
|
||||||
|
|
||||||
{{comment_text .Doc " " "\t"}}
|
{{comment_text .Doc " " "\t"}}
|
||||||
{{else}}{{if not $filtered}}PACKAGE DOCUMENTATION
|
{{else}}{{if not $filtered}}PACKAGE DOCUMENTATION
|
||||||
|
@ -775,8 +776,7 @@ package {{.Name}}
|
||||||
|
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
*/}}{{with .Consts}}{{if not $filtered}}
|
*/}}{{with .Consts}}{{if not $filtered}}CONSTANTS
|
||||||
CONSTANTS
|
|
||||||
|
|
||||||
{{end}}{{range .}}{{node $ .Decl}}
|
{{end}}{{range .}}{{node $ .Decl}}
|
||||||
{{comment_text .Doc " " "\t"}}
|
{{comment_text .Doc " " "\t"}}
|
||||||
|
@ -784,8 +784,7 @@ CONSTANTS
|
||||||
|
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
*/}}{{with .Vars}}{{if not $filtered}}
|
*/}}{{with .Vars}}{{if not $filtered}}VARIABLES
|
||||||
VARIABLES
|
|
||||||
|
|
||||||
{{end}}{{range .}}{{node $ .Decl}}
|
{{end}}{{range .}}{{node $ .Decl}}
|
||||||
{{comment_text .Doc " " "\t"}}
|
{{comment_text .Doc " " "\t"}}
|
||||||
|
@ -793,8 +792,7 @@ VARIABLES
|
||||||
|
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
*/}}{{with .Funcs}}{{if not $filtered}}
|
*/}}{{with .Funcs}}{{if not $filtered}}FUNCTIONS
|
||||||
FUNCTIONS
|
|
||||||
|
|
||||||
{{end}}{{range .}}{{node $ .Decl}}
|
{{end}}{{range .}}{{node $ .Decl}}
|
||||||
{{comment_text .Doc " " "\t"}}
|
{{comment_text .Doc " " "\t"}}
|
||||||
|
@ -802,23 +800,48 @@ FUNCTIONS
|
||||||
|
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
*/}}{{with .Types}}{{if not $filtered}}
|
*/}}{{with .Types}}{{if not $filtered}}TYPES
|
||||||
TYPES
|
|
||||||
|
|
||||||
{{end}}{{range .}}{{$tname := .Name}}{{node $ .Decl}}
|
{{end}}{{range .}}{{$tname := .Name}}{{node $ .Decl}}
|
||||||
{{comment_text .Doc " " "\t"}}
|
{{comment_text .Doc " " "\t"}}
|
||||||
{{range .Consts}}{{node $ .Decl}}
|
{{/*
|
||||||
|
|
||||||
|
---------------------------------------
|
||||||
|
|
||||||
|
*/}}{{if .Consts}}{{range .Consts}}{{node $ .Decl}}
|
||||||
{{comment_text .Doc " " "\t"}}
|
{{comment_text .Doc " " "\t"}}
|
||||||
{{end}}{{range .Vars}}{{node $ .Decl}}
|
{{end}}{{end}}{{/*
|
||||||
|
|
||||||
|
---------------------------------------
|
||||||
|
|
||||||
|
*/}}{{if .Vars}}{{range .Vars}}{{node $ .Decl}}
|
||||||
{{comment_text .Doc " " "\t"}}
|
{{comment_text .Doc " " "\t"}}
|
||||||
{{end}}{{example_text $ .Name " "}}
|
{{example_text $ .Name " "}}{{end}}{{end}}{{/*
|
||||||
{{range .Funcs}}{{node $ .Decl}}
|
|
||||||
|
---------------------------------------
|
||||||
|
|
||||||
|
*/}}{{if .Funcs}}{{range .Funcs}}{{node $ .Decl}}
|
||||||
{{comment_text .Doc " " "\t"}}
|
{{comment_text .Doc " " "\t"}}
|
||||||
{{example_text $ .Name " "}}
|
{{example_text $ .Name " "}}{{end}}{{end}}{{/*
|
||||||
{{end}}{{range .Methods}}{{node $ .Decl}}
|
|
||||||
|
---------------------------------------
|
||||||
|
|
||||||
|
*/}}{{if .Methods}}{{range .Methods}}{{node $ .Decl}}
|
||||||
{{comment_text .Doc " " "\t"}}
|
{{comment_text .Doc " " "\t"}}
|
||||||
{{$name := printf "%s_%s" $tname .Name}}{{example_text $ $name " "}}{{end}}
|
{{$name := printf "%s_%s" $tname .Name}}{{example_text $ $name " "}}{{end}}{{end}}{{/*
|
||||||
{{end}}{{end}}{{end}}{{/*
|
|
||||||
|
---------------------------------------
|
||||||
|
|
||||||
|
*/}}{{end}}{{end}}{{/*
|
||||||
|
|
||||||
|
---------------------------------------
|
||||||
|
|
||||||
|
*/}}{{if and $filtered (not (or .Consts (or .Vars (or .Funcs .Types))))}}No match found.
|
||||||
|
{{end}}{{/*
|
||||||
|
|
||||||
|
---------------------------------------
|
||||||
|
|
||||||
|
*/}}{{end}}{{/*
|
||||||
|
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
|
@ -831,14 +854,19 @@ TYPES
|
||||||
|
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
*/}}{{with .Dirs}}
|
*/}}{{if not $filtered}}{{with .Dirs}}SUBDIRECTORIES
|
||||||
SUBDIRECTORIES
|
|
||||||
{{if $.DirFlat}}{{range .List}}{{if .HasPkg}}
|
{{if $.DirFlat}}{{range .List}}{{if .HasPkg}}
|
||||||
{{.Path}}{{end}}{{end}}
|
{{.Path}}{{end}}{{end}}
|
||||||
{{else}}{{range .List}}
|
{{else}}{{range .List}}
|
||||||
{{repeat ` + "`" + `. ` + "`" + ` .Depth}}{{.Name}}{{end}}
|
{{repeat ` + "`" + `. ` + "`" + ` .Depth}}{{.Name}}{{end}}
|
||||||
{{end}}{{end}}
|
{{end}}{{end}}{{/*
|
||||||
`,
|
|
||||||
|
---------------------------------------
|
||||||
|
|
||||||
|
*/}}{{end}}{{/*
|
||||||
|
Make sure there is no newline at the end of this file.
|
||||||
|
perl -i -pe 'chomp if eof' package.txt
|
||||||
|
*/}}`,
|
||||||
"play.js": `// Copyright 2012 The Go Authors. All rights reserved.
|
"play.js": `// Copyright 2012 The Go Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
Loading…
Reference in New Issue