synctest and test examples

37 views
Skip to first unread message

Pierre Durand

unread,
Sep 5, 2025, 2:19:36 PM (10 hours ago) Sep 5
to golang-nuts
Using synctest requires to have access to a *testing.T
This is not available from an example testing function.

Should we automatically run examples in a synctest time bubble ?

Jason E. Aten

unread,
Sep 5, 2025, 4:13:57 PM (9 hours ago) Sep 5
to golang-nuts
Since synctest runs on a fake clock, doing anything 
"automatically" with it seems like a bad idea.
You very much want to know when you are 
using it, and most Examples to this point
(presumably a sizable set), have no 
idea about synctest, since it didn't exist when
they were written, that would risk breaking alot of things.

Moreover its easy to just write a regular test. I would just write a regular 
Test func and put the word "Example" in a comment above it.
Same result, no?

Axel Wagner

unread,
12:19 AM (29 minutes ago) 12:19 AM
to Jason E. Aten, golang-nuts
On Fri, 5 Sept 2025 at 22:14, Jason E. Aten <j.e....@gmail.com> wrote:
Moreover its easy to just write a regular test. I would just write a regular 
Test func and put the word "Example" in a comment above it.
Same result, no?

No, example functions are exposed in package docs (with `go doc -http` or on pkg.go.dev) and can be run directly from the browser: https://go.dev/blog/examples

I agree with you that we don't want to do it automatically, but it would be useful to have a way to do it at all.
 

On Friday, September 5, 2025 at 7:19:36 PM UTC+1 Pierre Durand wrote:
Using synctest requires to have access to a *testing.T
This is not available from an example testing function.

Should we automatically run examples in a synctest time bubble ?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/a088adf2-f4f8-47eb-879b-222714670be5n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages