Skip to content

Commit c9c78c0

Browse files
committed
strconv: embed testdata in test
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>
1 parent 8f74f9d commit c9c78c0

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/strconv/fp_test.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ package strconv_test
66

77
import (
88
"bufio"
9+
_ "embed"
910
"fmt"
10-
"os"
1111
"strconv"
1212
"strings"
1313
"testing"
@@ -92,15 +92,11 @@ func myatof32(s string) (f float32, ok bool) {
9292
return f1, true
9393
}
9494

95-
func TestFp(t *testing.T) {
96-
f, err := os.Open("testdata/testfp.txt")
97-
if err != nil {
98-
t.Fatal("testfp: open testdata/testfp.txt:", err)
99-
}
100-
defer f.Close()
101-
102-
s := bufio.NewScanner(f)
95+
//go:embed testdata/testfp.txt
96+
var testfp string
10397

98+
func TestFp(t *testing.T) {
99+
s := bufio.NewScanner(strings.NewReader(testfp))
104100
for lineno := 1; s.Scan(); lineno++ {
105101
line := s.Text()
106102
if len(line) == 0 || line[0] == '#' {

0 commit comments

Comments
 (0)