Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(84)

Issue 5137041: code review 5137041: go/doc, godoc, gotest: support for reading example docu... (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years, 6 months ago by adg
Modified:
12 years, 6 months ago
Reviewers:
rog
CC:
gri, r, rsc, golang-dev
Visibility:
Public.

Description

go/doc, godoc, gotest: support for reading example documentation This CL introduces the go.Example type and go.Examples functions that are used to represent and extract code samples from Go source. They should be of the form: // Output of this function. func ExampleFoo() { fmt.Println("Output of this function.") } It also modifies godoc to read example code from _test.go files, and include them in the HTML output with JavaScript-driven toggles. It also implements testing of example functions with gotest. The stdout/stderr is compared against the output comment on the function. This CL includes examples for the sort.Ints function and the sort.SortInts type. After patching this CL in and re-building go/doc and godoc, try godoc -http=localhost:6060 and visit http://localhost:6060/pkg/sort/

Patch Set 1 #

Patch Set 2 : diff -r 7bd0e2975cff https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r 7bd0e2975cff https://go.googlecode.com/hg/ #

Patch Set 4 : diff -r 7bd0e2975cff https://go.googlecode.com/hg/ #

Total comments: 13

Patch Set 5 : diff -r 1fb56f387a76 https://go.googlecode.com/hg/ #

Total comments: 1

Patch Set 6 : diff -r 1fb56f387a76 https://go.googlecode.com/hg/ #

Total comments: 2

Patch Set 7 : diff -r 1fb56f387a76 https://go.googlecode.com/hg/ #

Patch Set 8 : diff -r 1fb56f387a76 https://go.googlecode.com/hg/ #

Patch Set 9 : diff -r bef8a4920e15 https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+292 lines, -24 lines) Patch
M doc/all.css View 1 2 1 chunk +9 lines, -0 lines 0 comments Download
M doc/godocs.js View 1 2 2 chunks +22 lines, -0 lines 0 comments Download
A lib/godoc/example.html View 1 2 1 chunk +11 lines, -0 lines 0 comments Download
M lib/godoc/package.html View 1 2 3 4 5 6 7 2 chunks +6 lines, -0 lines 0 comments Download
M src/cmd/godoc/godoc.go View 1 2 3 4 5 6 7 chunks +51 lines, -10 lines 0 comments Download
M src/cmd/gotest/gotest.go View 1 2 3 4 6 chunks +23 lines, -2 lines 0 comments Download
M src/pkg/go/doc/Makefile View 1 chunk +1 line, -0 lines 0 comments Download
A src/pkg/go/doc/example.go View 1 2 3 4 5 1 chunk +56 lines, -0 lines 0 comments Download
A src/pkg/sort/example_test.go View 1 2 3 4 5 6 1 chunk +17 lines, -0 lines 0 comments Download
M src/pkg/testing/Makefile View 1 1 chunk +1 line, -0 lines 0 comments Download
A src/pkg/testing/example.go View 1 2 3 4 5 6 7 8 1 chunk +84 lines, -0 lines 0 comments Download
M src/pkg/testing/testing.go View 1 2 3 4 5 6 7 8 3 chunks +11 lines, -12 lines 0 comments Download

Messages

Total messages: 14
adg
Hello gri (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
12 years, 6 months ago (2011-09-25 08:13:44 UTC) #1
gri
This looks reasonable to me as well. I think a toggle (per rsc's suggestion) makes ...
12 years, 6 months ago (2011-09-26 22:22:06 UTC) #2
adg
I've updated the CL with modifications to gotest, also, and now show the examples in ...
12 years, 6 months ago (2011-09-27 04:22:09 UTC) #3
adg
Hello gri@golang.org, r@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
12 years, 6 months ago (2011-09-28 00:02:52 UTC) #4
rsc
Seems reasonable. Examples should be a slice, not a map. The order is important: they ...
12 years, 6 months ago (2011-10-05 15:29:00 UTC) #5
adg
Hello gri@golang.org, r@golang.org, rsc@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
12 years, 6 months ago (2011-10-05 23:07:15 UTC) #6
gri
http://codereview.appspot.com/5137041/diff/7001/src/cmd/godoc/godoc.go File src/cmd/godoc/godoc.go (right): http://codereview.appspot.com/5137041/diff/7001/src/cmd/godoc/godoc.go#newcode470 src/cmd/godoc/godoc.go:470: // unindent and remove surrounding braces This is very ...
12 years, 6 months ago (2011-10-05 23:16:40 UTC) #7
adg
http://codereview.appspot.com/5137041/diff/7001/src/cmd/godoc/godoc.go File src/cmd/godoc/godoc.go (right): http://codereview.appspot.com/5137041/diff/7001/src/cmd/godoc/godoc.go#newcode470 src/cmd/godoc/godoc.go:470: // unindent and remove surrounding braces On 2011/10/05 23:16:41, ...
12 years, 6 months ago (2011-10-05 23:29:55 UTC) #8
r
testing stuff LGTM but can maybe be refactored. http://codereview.appspot.com/5137041/diff/11001/src/pkg/testing/example.go File src/pkg/testing/example.go (right): http://codereview.appspot.com/5137041/diff/11001/src/pkg/testing/example.go#newcode22 src/pkg/testing/example.go:22: func ...
12 years, 6 months ago (2011-10-05 23:30:59 UTC) #9
gri
LGTM rsc may want to comment on the testing changes. http://codereview.appspot.com/5137041/diff/7001/src/cmd/godoc/godoc.go File src/cmd/godoc/godoc.go (right): http://codereview.appspot.com/5137041/diff/7001/src/cmd/godoc/godoc.go#newcode470 ...
12 years, 6 months ago (2011-10-06 00:03:05 UTC) #10
adg
http://codereview.appspot.com/5137041/diff/14002/src/cmd/godoc/godoc.go File src/cmd/godoc/godoc.go (right): http://codereview.appspot.com/5137041/diff/14002/src/cmd/godoc/godoc.go#newcode995 src/cmd/godoc/godoc.go:995: return PageInfo{Dirname: abspath, Err: err} On 2011/10/06 00:03:05, gri ...
12 years, 6 months ago (2011-10-06 00:39:14 UTC) #11
rsc
LGTM
12 years, 6 months ago (2011-10-06 17:40:52 UTC) #12
adg
*** Submitted as http://code.google.com/p/go/source/detail?r=e23057584c65 *** go/doc, godoc, gotest: support for reading example documentation This CL ...
12 years, 6 months ago (2011-10-06 18:56:22 UTC) #13
rog
12 years, 6 months ago (2011-10-07 08:40:28 UTC) #14
sorry for this late comment, but i've only just got
around to looking at this. looks really good, but a few
small remarks:

- ironically, this feature doesn't seem to be mentioned anywhere
in the documentation (although i've quite possibly missed something),
so if you haven't seen this CL go by, you might not know how to do examples.

- if there was such documentation, it should probably mention
that the name of the example is used to decide what type
or function to attach it to (perhaps i should have found that
obvious, but i didn't)

- for examples that use several features from a package,
it would be nice if there was some way of attaching examples
to the top of a godoc page rather than to a specific function
or type. Perhaps if the example name was not recognised,
the example could go at the top, preceded by the doc comments
for that example function. that would also make it obvious when
you have misspelled an example and so left it out accidentally.

- even though the source is shown directly, it might be nice
to link to the source code in context anyway.

On 6 October 2011 19:56,  <adg@golang.org> wrote:
> *** Submitted as
> http://code.google.com/p/go/source/detail?r=e23057584c65 ***
>
> go/doc, godoc, gotest: support for reading example documentation
>
> This CL introduces the go.Example type and go.Examples functions that
> are used to represent and extract code samples from Go source.
>
> They should be of the form:
>
> // Output of this function.
> func ExampleFoo() {
>        fmt.Println("Output of this function.")
> }
>
> It also modifies godoc to read example code from _test.go files,
> and include them in the HTML output with JavaScript-driven toggles.
>
> It also implements testing of example functions with gotest.
> The stdout/stderr is compared against the output comment on the
> function.
>
> This CL includes examples for the sort.Ints function and the
> sort.SortInts type. After patching this CL in and re-building go/doc
> and godoc, try
>        godoc -http=localhost:6060
> and visit http://localhost:6060/pkg/sort/
>
> R=gri, r, rsc
> CC=golang-dev
> http://codereview.appspot.com/5137041
>
>
> http://codereview.appspot.com/5137041/
>
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b