Fixes #51269
Change-Id: I06747db18ca078c1f1bda9b7bc60006f53191f4d
Reviewed-on: https://go-review.googlesource.com/c/go/+/627035
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
--- /dev/null
+# Tests that crlf in the output of examples are handled.
+# Verifies golang.org/issue/51269
+go test x_test.go
+
+-- x_test.go --
+package x
+
+import (
+ "io"
+ "fmt"
+ "os"
+ "runtime"
+)
+
+func Example_lf() {
+ fmt.Print("foo", "\n", "bar")
+ // Output:
+ // foo
+ // bar
+}
+
+func Example_println() {
+ fmt.Println("foo")
+ fmt.Println("bar")
+ // Output:
+ // foo
+ // bar
+}
+
+func Example_crlf() {
+ if runtime.GOOS == "windows" {
+ io.WriteString(os.Stdout, "foo\r\nbar\r\n")
+ } else {
+ io.WriteString(os.Stdout, "foo\nbar\n")
+ }
+ // Output:
+ // foo
+ // bar
+}
import (
"fmt"
+ "runtime"
"slices"
"strings"
"time"
var fail string
got := strings.TrimSpace(stdout)
want := strings.TrimSpace(eg.Output)
+ if runtime.GOOS == "windows" {
+ got = strings.ReplaceAll(got, "\r\n", "\n")
+ want = strings.ReplaceAll(want, "\r\n", "\n")
+ }
if eg.Unordered {
if sortLines(got) != sortLines(want) && recovered == nil {
fail = fmt.Sprintf("got:\n%s\nwant (unordered):\n%s\n", stdout, eg.Output)