Radar · Go · Archive · Week 28 · Jul 6 – 12, 2026
testing: allow examples with any signature
Worth knowingtooling
- What changed
- Example functions (
ExampleXxx) that take and/or return parameters are now allowed. They will be shown bygo docbut are not runnable via the playground and cannot contain an// Output:comment. - Production impact
- The source does not say.
- Try it
- Write an
ExampleFoothat takes a*testing.Tand rungo docto see it listed. - Source
- github.com/golang/go/issues/79808
Understand it, then run it
Example functions in Go are special functions that start with Example. They are normally used to show how a package works and can be run automatically by the go test tool. The change allows these example functions to have input parameters or return values. They will still appear in the documentation generated by go doc, but they will not be runnable in the playground and cannot contain an // Output: comment. The idea is to let developers write examples that call other functions or return values, while keeping the examples simple to read in the docs.
Run it now
// This program demonstrates that example functions with parameters are now
// allowed in Go. The functions are defined with the `Example` prefix and
// take arguments, but they are not executed automatically by the testing
// framework. We call them manually from main to show that they compile
// and run as normal functions.
package main
import "fmt"
// Example_in_and_out is an example function that takes two integers and
// returns their sum as a string. It is named with the Example prefix,
// so tools like `go doc` will display it as documentation, but it is not
// runnable by the testing package.
func Example_in_and_out(a, b int) string {
return fmt.Sprintf("%d", a+b)
}
func main() {
// Call the example function directly.
fmt.Println(Example_in_and_out(2, 3)) // prints 5
}
What it printed when we ran it on Go 1.27.1
5
Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.
Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed