]> Cypherpunks repositories - gostls13.git/commitdiff
strconv: embed testdata in test
authorRuss Cox <rsc@golang.org>
Fri, 17 Oct 2025 03:21:14 +0000 (23:21 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 21 Oct 2025 18:33:43 +0000 (11:33 -0700)
This makes it easier to run test binaries on remote machines.

Change-Id: I3e5bc6cf10272a6743fd5d16ab1089d46f53232c
Reviewed-on: https://go-review.googlesource.com/c/go/+/712660
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/strconv/fp_test.go

index fd73958c97d29eb174e19044c714ed0e31b75f1e..376e8f591c6deeb2528dfc31ab93f440797d752c 100644 (file)
@@ -6,8 +6,8 @@ package strconv_test
 
 import (
        "bufio"
+       _ "embed"
        "fmt"
-       "os"
        "strconv"
        "strings"
        "testing"
@@ -92,15 +92,11 @@ func myatof32(s string) (f float32, ok bool) {
        return f1, true
 }
 
-func TestFp(t *testing.T) {
-       f, err := os.Open("testdata/testfp.txt")
-       if err != nil {
-               t.Fatal("testfp: open testdata/testfp.txt:", err)
-       }
-       defer f.Close()
-
-       s := bufio.NewScanner(f)
+//go:embed testdata/testfp.txt
+var testfp string
 
+func TestFp(t *testing.T) {
+       s := bufio.NewScanner(strings.NewReader(testfp))
        for lineno := 1; s.Scan(); lineno++ {
                line := s.Text()
                if len(line) == 0 || line[0] == '#' {