From e08209d4e6fa2ddbe519530d165ea4b043b49c24 Mon Sep 17 00:00:00 2001 From: Alexander Yastrebov Date: Wed, 28 Jun 2023 22:49:32 +0200 Subject: [PATCH] internal/godoc/dochtml: omit "Output" section for examples with no output Fixes golang/go#60986 --- internal/godoc/dochtml/dochtml_test.go | 26 +++++++++++++++++++ .../godoc/dochtml/testdata/example_test.go | 4 +++ static/doc/example.tmpl | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/internal/godoc/dochtml/dochtml_test.go b/internal/godoc/dochtml/dochtml_test.go index b563e1c91..388e22b8c 100644 --- a/internal/godoc/dochtml/dochtml_test.go +++ b/internal/godoc/dochtml/dochtml_test.go @@ -178,6 +178,32 @@ func main() { 0 1 + +
+ + + + +
`, + }, + { + name: "Example without output", + htmlID: "example-package-NoOutput", + want: `
+Example (NoOutput) +
+ +
package main
+
+import (
+	"fmt"
+)
+
+func main() {
+	fmt.Println("hello")
+}
+
+
diff --git a/internal/godoc/dochtml/testdata/example_test.go b/internal/godoc/dochtml/testdata/example_test.go index 83b615e1c..c4249b1a8 100644 --- a/internal/godoc/dochtml/testdata/example_test.go +++ b/internal/godoc/dochtml/testdata/example_test.go @@ -46,3 +46,7 @@ func Example_stringsCompare() { // 0 // 1 } + +func Example_noOutput() { + fmt.Println("hello") +} diff --git a/static/doc/example.tmpl b/static/doc/example.tmpl index d5cb76d3c..b1504f563 100644 --- a/static/doc/example.tmpl +++ b/static/doc/example.tmpl @@ -15,7 +15,7 @@

Open in Go playground »

{{"\n" -}} {{- end -}} {{render_code .Example}}{{"\n" -}} -
Output:{{"\n\n"}}{{- .Output -}}
{{"\n" -}} + {{- if .Output -}}
Output:{{"\n\n"}}{{- .Output -}}
{{"\n" -}}{{- end -}}
{{"\n" -}} {{- if .Play -}}