From a81074af8874d353468e1f2ab2475a7a3bbfdb20 Mon Sep 17 00:00:00 2001 From: Brad Garcia Date: Fri, 14 Mar 2014 10:00:10 -0400 Subject: [PATCH] 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 --- cmd/godoc/godoc_test.go | 36 ++++++++++++++++++++++++++---------- godoc/static/package.txt | 4 ++-- godoc/static/static.go | 5 +++-- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/cmd/godoc/godoc_test.go b/cmd/godoc/godoc_test.go index 1227e079..4eec5894 100644 --- a/cmd/godoc/godoc_test.go +++ b/cmd/godoc/godoc_test.go @@ -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) + } + } } } diff --git a/godoc/static/package.txt b/godoc/static/package.txt index d2086169..ec4ef1cc 100644 --- a/godoc/static/package.txt +++ b/godoc/static/package.txt @@ -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 -*/}} \ No newline at end of file +*/}} diff --git a/godoc/static/static.go b/godoc/static/static.go index 09b37ddb..3a5f89ea 100644 --- a/godoc/static/static.go +++ b/godoc/static/static.go @@ -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.