godoc: Output "No match found" only if there is no ast or docs included in info.

Fixes golang/go#7499.

R=minux.ma
CC=golang-codereviews
https://golang.org/cl/75400043
This commit is contained in:
Brad Garcia 2014-03-14 10:00:10 -04:00
parent 7c69950f7f
commit a81074af88
3 changed files with 31 additions and 14 deletions

View File

@ -16,32 +16,42 @@ import (
)
var godocTests = []struct {
args []string
matches []string // regular expressions
args []string
matches []string // regular expressions
dontmatch []string // regular expressions
}{
{
[]string{"fmt"},
[]string{
args: []string{"fmt"},
matches: []string{
`import "fmt"`,
`Package fmt implements formatted I/O`,
},
},
{
[]string{"io", "WriteString"},
[]string{
args: []string{"io", "WriteString"},
matches: []string{
`func WriteString\(`,
`WriteString writes the contents of the string s to w`,
},
},
{
[]string{"nonexistingpkg"},
[]string{
args: []string{"nonexistingpkg"},
matches: []string{
`no such file or directory|does not exist`,
},
},
{
[]string{"fmt", "NonexistentSymbol"},
[]string{
args: []string{"fmt", "NonexistentSymbol"},
matches: []string{
`No match found\.`,
},
},
{
args: []string{"-src", "syscall", "Open"},
matches: []string{
`func Open\(`,
},
dontmatch: []string{
`No match found\.`,
},
},
@ -78,5 +88,11 @@ func TestGodoc(t *testing.T) {
t.Errorf("godoc %v =\n%s\nwanted /%v/", strings.Join(test.args, " "), out, pat)
}
}
for _, pat := range test.dontmatch {
re := regexp.MustCompile(pat)
if re.Match(out) {
t.Errorf("godoc %v =\n%s\ndid not want /%v/", strings.Join(test.args, " "), out, pat)
}
}
}
}

View File

@ -7,7 +7,7 @@
---------------------------------------
*/}}{{if and $filtered (not .PDoc)}}No match found.
*/}}{{if and $filtered (not (or .PDoc .PAst))}}No match found.
{{end}}{{with .PDoc}}{{if $.IsMain}}COMMAND DOCUMENTATION
{{comment_text .Doc " " "\t"}}
@ -111,4 +111,4 @@ package {{.Name}}
*/}}{{end}}{{/*
Make sure there is no newline at the end of this file.
perl -i -pe 'chomp if eof' package.txt
*/}}
*/}}

View File

@ -762,7 +762,7 @@ $(document).ready(function() {
---------------------------------------
*/}}{{if and $filtered (not .PDoc)}}No match found.
*/}}{{if and $filtered (not (or .PDoc .PAst))}}No match found.
{{end}}{{with .PDoc}}{{if $.IsMain}}COMMAND DOCUMENTATION
{{comment_text .Doc " " "\t"}}
@ -866,7 +866,8 @@ package {{.Name}}
*/}}{{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.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.