Proposal Details
In #17509, @rsc rejected this exact proposal:
Godoc is about showing the exported API from
a package. Test files are not part of the
exported API.
go doc has since greatly expanded in both its
intended scope alongside its unintended consumers,
namely large language models. The evolution of
go doc convinces me it's worth revisiting:
go doc provides deterministic access to
information that is otherwise a few tool
calls, potentially with network round trips
as well. For LLM agents, it also provides
more token efficient output.
While I cannot prove this conjecture to be
true, I propose that we add a -test flag
to go doc.
Proposal
go doc -test [package] [symbol]
When specified, include symbols from *_test.go.
Both *_test packages and non-test packages with
testing symbols are in scope.
It composes with existing flags:
-test -src: full source of test declarations
-test -u: unexported test-file symbols
-test -all: test symbols in the full listing
Without -test, the go doc behavior is unchanged.
Examples
% go doc -test crypto/mlkem
package mlkem // import "crypto/mlkem"
Package mlkem implements the quantum-resistant key encapsulation method ML-KEM
(formerly known as Kyber), as specified in NIST FIPS 203.
Most applications should use the ML-KEM-768 parameter set, as implemented by
DecapsulationKey768 and EncapsulationKey768.
[NIST FIPS 203]: https://doi.org/10.6028/NIST.FIPS.203
const SharedKeySize = 32 ...
type DecapsulationKey1024 struct{ ... }
func GenerateKey1024() (*DecapsulationKey1024, error)
func NewDecapsulationKey1024(seed []byte) (*DecapsulationKey1024, error)
type DecapsulationKey768 struct{ ... }
func GenerateKey768() (*DecapsulationKey768, error)
func NewDecapsulationKey768(seed []byte) (*DecapsulationKey768, error)
type EncapsulationKey1024 struct{ ... }
func NewEncapsulationKey1024(encapsulationKey []byte) (*EncapsulationKey1024, error)
type EncapsulationKey768 struct{ ... }
func NewEncapsulationKey768(encapsulationKey []byte) (*EncapsulationKey768, error)
package mlkem_test // external test package
func BenchmarkDecaps(b *testing.B)
func BenchmarkEncaps(b *testing.B)
func BenchmarkKeyGen(b *testing.B)
func BenchmarkRoundTrip(b *testing.B)
func Bob(encapsulationKey []byte) (ciphertext []byte)
func Example()
func TestAccumulated(t *testing.T)
func TestBadLengths(t *testing.T)
func TestConstantSizes(t *testing.T)
func TestRoundTrip(t *testing.T)
% go doc -src -test crypto/mlkem BenchmarkKeyGen
package mlkem_test // external test package
func BenchmarkKeyGen(b *testing.B) {
var d, z [32]byte
rand.Read(d[:])
rand.Read(z[:])
b.ResetTimer()
for i := 0; i < b.N; i++ {
dk := mlkem.GenerateKeyInternal768(&d, &z)
sink ^= dk.EncapsulationKey().Bytes()[0]
}
}
/cc @golang/proposal-review
Proposal Details
In #17509, @rsc rejected this exact proposal:
go dochas since greatly expanded in both itsintended scope alongside its unintended consumers,
namely large language models. The evolution of
go docconvinces me it's worth revisiting:go doc-cmd-src-all-short-http(#68106)-ex(#26715)-json(#34293)go docprovides deterministic access toinformation that is otherwise a few tool
calls, potentially with network round trips
as well. For LLM agents, it also provides
more token efficient output.
While I cannot prove this conjecture to be
true, I propose that we add a
-testflagto
go doc.Proposal
When specified, include symbols from
*_test.go.Both
*_testpackages and non-test packages withtesting symbols are in scope.
It composes with existing flags:
-test -src: full source of test declarations-test -u: unexported test-file symbols-test -all: test symbols in the full listingWithout
-test, thego docbehavior is unchanged.Examples
/cc @golang/proposal-review