]> Cypherpunks repositories - gostls13.git/commit
go/doc, godoc, gotest: support for reading example documentation
authorAndrew Gerrand <adg@golang.org>
Thu, 6 Oct 2011 18:56:17 +0000 (11:56 -0700)
committerAndrew Gerrand <adg@golang.org>
Thu, 6 Oct 2011 18:56:17 +0000 (11:56 -0700)
commitaf1ae438b9218d5dbdb0bf0c756de1e3d4691551
tree1fd06392c4af7dd6d4900661e8b4988913d92609
parent155e21cc7f37ade106171ac53fd6826869811001
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
https://golang.org/cl/5137041
12 files changed:
doc/all.css
doc/godocs.js
lib/godoc/example.html [new file with mode: 0644]
lib/godoc/package.html
src/cmd/godoc/godoc.go
src/cmd/gotest/gotest.go
src/pkg/go/doc/Makefile
src/pkg/go/doc/example.go [new file with mode: 0644]
src/pkg/sort/example_test.go [new file with mode: 0644]
src/pkg/testing/Makefile
src/pkg/testing/example.go [new file with mode: 0644]
src/pkg/testing/testing.go