Skip to content

Commit fefda1a

Browse files
dmitshurgopherbot
authored andcommitted
internal/texttest: remove Run and Bench helpers
Versions of Go whose testing package doesn't yet support subtests and sub-benchmarks are no longer supported. Drop an intermediate layer of compatibility from the ./internal/texttest package. The initial version of this change was git-generate'd with the script: rm internal/testtext/go1_{6,7}.go gofmt -r 'testtext.Run(t, n, f) -> t.Run(n, f)' -w . gofmt -r 'testtext.Bench(b, n, f) -> b.Run(n, f)' -w . goimports -w . Unfortunately it seems gofmt -r dropped inner comments inside f, and also added some spurious blank lines. So it was manually amended not to include those changes. Change-Id: I5bcb553b90ce392aada7896d576194be479f2616 Reviewed-on: https://go-review.googlesource.com/c/text/+/621575 Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
1 parent a457f47 commit fefda1a

18 files changed

+35
-86
lines changed

cases/context_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"testing"
1010
"unicode"
1111

12-
"golang.org/x/text/internal/testtext"
1312
"golang.org/x/text/language"
1413
"golang.org/x/text/transform"
1514
"golang.org/x/text/unicode/norm"
@@ -214,7 +213,7 @@ func TestCCC(t *testing.T) {
214213
func TestWordBreaks(t *testing.T) {
215214
for _, tt := range breakTest {
216215
desc := norm.NFC.String(tt)
217-
testtext.Run(t, desc, func(t *testing.T) {
216+
t.Run(desc, func(t *testing.T) {
218217
parts := strings.Split(tt, "|")
219218
want := ""
220219
for _, s := range parts {

cases/icu_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"strings"
1212
"testing"
1313

14-
"golang.org/x/text/internal/testtext"
1514
"golang.org/x/text/language"
1615
"golang.org/x/text/unicode/norm"
1716
)
@@ -83,7 +82,7 @@ func TestICUConformance(t *testing.T) {
8382
if exclude(c, tag, s) {
8483
continue
8584
}
86-
testtext.Run(t, path.Join(c, tag, s), func(t *testing.T) {
85+
t.Run(path.Join(c, tag, s), func(t *testing.T) {
8786
want := doICU(tag, c, s)
8887
got := doGo(tag, c, s)
8988
if norm.NFC.String(got) != norm.NFC.String(want) {

cases/map_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func TestAlloc(t *testing.T) {
205205
// func() Caser { return Title(language.Und) },
206206
// func() Caser { return Title(language.Und, HandleFinalSigma(false)) },
207207
} {
208-
testtext.Run(t, "", func(t *testing.T) {
208+
t.Run("", func(t *testing.T) {
209209
var c Caser
210210
v := testtext.AllocsPerRun(10, func() {
211211
c = f()
@@ -234,7 +234,7 @@ func testHandover(t *testing.T, c Caser, src string) {
234234

235235
// Test handover for each substring of the prefix.
236236
for i := 0; i < pSrc; i++ {
237-
testtext.Run(t, fmt.Sprint("interleave/", i), func(t *testing.T) {
237+
t.Run(fmt.Sprint("interleave/", i), func(t *testing.T) {
238238
dst := make([]byte, 4*len(src))
239239
c.Reset()
240240
nSpan, _ := c.Span([]byte(src[:i]), false)
@@ -299,7 +299,7 @@ func TestHandover(t *testing.T) {
299299
"'", "n bietje",
300300
}}
301301
for _, tc := range testCases {
302-
testtext.Run(t, tc.desc, func(t *testing.T) {
302+
t.Run(tc.desc, func(t *testing.T) {
303303
src := tc.first + tc.second
304304
want := tc.t.String(src)
305305
tc.t.Reset()
@@ -601,7 +601,7 @@ func init() {
601601

602602
func TestShortBuffersAndOverflow(t *testing.T) {
603603
for i, tt := range bufferTests {
604-
testtext.Run(t, tt.desc, func(t *testing.T) {
604+
t.Run(tt.desc, func(t *testing.T) {
605605
buf := make([]byte, tt.dstSize)
606606
got := []byte{}
607607
var nSrc, nDst int
@@ -827,7 +827,7 @@ func TestSpan(t *testing.T) {
827827
err: transform.ErrEndOfSpan,
828828
t: Title(language.Afrikaans),
829829
}} {
830-
testtext.Run(t, tt.desc, func(t *testing.T) {
830+
t.Run(tt.desc, func(t *testing.T) {
831831
for p := 0; p < len(tt.want); p += utf8.RuneLen([]rune(tt.src[p:])[0]) {
832832
tt.t.Reset()
833833
n, err := tt.t.Span([]byte(tt.src[:p]), false)
@@ -901,7 +901,7 @@ func BenchmarkCasers(b *testing.B) {
901901
{"title", bytes.ToTitle},
902902
{"upper", bytes.ToUpper},
903903
} {
904-
testtext.Bench(b, path.Join(s.name, "bytes", f.name), func(b *testing.B) {
904+
b.Run(path.Join(s.name, "bytes", f.name), func(b *testing.B) {
905905
b.SetBytes(int64(len(src)))
906906
for i := 0; i < b.N; i++ {
907907
f.fn(src)
@@ -921,7 +921,7 @@ func BenchmarkCasers(b *testing.B) {
921921
} {
922922
c := Caser{t.caser}
923923
dst := make([]byte, len(src))
924-
testtext.Bench(b, path.Join(s.name, t.name, "transform"), func(b *testing.B) {
924+
b.Run(path.Join(s.name, t.name, "transform"), func(b *testing.B) {
925925
b.SetBytes(int64(len(src)))
926926
for i := 0; i < b.N; i++ {
927927
c.Reset()
@@ -934,7 +934,7 @@ func BenchmarkCasers(b *testing.B) {
934934
continue
935935
}
936936
spanSrc := c.Bytes(src)
937-
testtext.Bench(b, path.Join(s.name, t.name, "span"), func(b *testing.B) {
937+
b.Run(path.Join(s.name, t.name, "span"), func(b *testing.B) {
938938
c.Reset()
939939
if n, _ := c.Span(spanSrc, true); n < len(spanSrc) {
940940
b.Fatalf("spanner is not recognizing text %q as done (at %d)", spanSrc, n)

internal/export/idna/idna_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func doTest(t *testing.T, f func(string) (string, error), name, input, want, err
8181
in = strings.Replace(in, `\U`, "#", -1)
8282
name = fmt.Sprintf("%s/%s/%s", name, in, test)
8383

84-
testtext.Run(t, name, func(t *testing.T) {
84+
t.Run(name, func(t *testing.T) {
8585
got, err := f(input)
8686

8787
if err != nil {

internal/number/number_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99
"testing"
1010

11-
"golang.org/x/text/internal/testtext"
1211
"golang.org/x/text/language"
1312
)
1413

@@ -93,7 +92,7 @@ func TestFormats(t *testing.T) {
9392
{"zgh", "#,##0 %", tagToPercent},
9493
}
9594
for _, tc := range testCases {
96-
testtext.Run(t, tc.lang, func(t *testing.T) {
95+
t.Run(tc.lang, func(t *testing.T) {
9796
got := formatForLang(language.MustParse(tc.lang), tc.index)
9897
want, _ := ParsePattern(tc.pattern)
9998
if *got != *want {

internal/testtext/go1_6.go

-23
This file was deleted.

internal/testtext/go1_7.go

-17
This file was deleted.

language/display/display_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"testing"
1212
"unicode"
1313

14-
"golang.org/x/text/internal/testtext"
1514
"golang.org/x/text/language"
1615
"golang.org/x/text/message"
1716
)
@@ -40,7 +39,7 @@ func TestValues(t *testing.T) {
4039
// checkDefined checks that a value exists in a Namer.
4140
checkDefined := func(x interface{}, namers []testcase) {
4241
for _, n := range namers {
43-
testtext.Run(t, fmt.Sprintf("%s.Name(%s)", n.kind, x), func(t *testing.T) {
42+
t.Run(fmt.Sprintf("%s.Name(%s)", n.kind, x), func(t *testing.T) {
4443
if n.n.Name(x) == "" {
4544
// As of version 28 there is no data for az-Arab in English,
4645
// although there is useful data in other languages.
@@ -449,7 +448,7 @@ func TestLanguage(t *testing.T) {
449448
{"en", "sr-Latn-ME", "Serbo-Croatian"}, // See comments in TestTag.
450449
}
451450
for _, tt := range tests {
452-
testtext.Run(t, tt.dict+"/"+tt.tag, func(t *testing.T) {
451+
t.Run(tt.dict+"/"+tt.tag, func(t *testing.T) {
453452
name, fmtName := splitName(tt.name)
454453
dict := language.MustParse(tt.dict)
455454
tag := language.Raw.MustParse(tt.tag)

runes/runes_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -626,15 +626,15 @@ func doBench(b *testing.B, t Transformer) {
626626
dst := make([]byte, 2*len(bc.data))
627627
src := []byte(bc.data)
628628

629-
testtext.Bench(b, bc.name+"/transform", func(b *testing.B) {
629+
b.Run(bc.name+"/transform", func(b *testing.B) {
630630
b.SetBytes(int64(len(src)))
631631
for i := 0; i < b.N; i++ {
632632
t.Transform(dst, src, true)
633633
}
634634
})
635635
src = t.Bytes(src)
636636
t.Reset()
637-
testtext.Bench(b, bc.name+"/span", func(b *testing.B) {
637+
b.Run(bc.name+"/span", func(b *testing.B) {
638638
b.SetBytes(int64(len(src)))
639639
for i := 0; i < b.N; i++ {
640640
t.Span(src, true)

secure/bidirule/bench_test.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ package bidirule
66

77
import (
88
"testing"
9-
10-
"golang.org/x/text/internal/testtext"
119
)
1210

1311
var benchData = []struct{ name, data string }{
@@ -18,7 +16,7 @@ var benchData = []struct{ name, data string }{
1816

1917
func doBench(b *testing.B, fn func(b *testing.B, data string)) {
2018
for _, d := range benchData {
21-
testtext.Bench(b, d.name, func(b *testing.B) { fn(b, d.data) })
19+
b.Run(d.name, func(b *testing.B) { fn(b, d.data) })
2220
}
2321
}
2422

secure/bidirule/bidirule_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99
"testing"
1010

11-
"golang.org/x/text/internal/testtext"
1211
"golang.org/x/text/unicode/bidi"
1312
"golang.org/x/text/unicode/norm"
1413
)
@@ -57,7 +56,7 @@ func doTests(t *testing.T, fn func(t *testing.T, tc ruleTest)) {
5756
for rule, cases := range testCases {
5857
for i, tc := range cases {
5958
name := fmt.Sprintf("%d/%d:%+q:%[3]s", rule, i, norm.NFC.String(tc.in))
60-
testtext.Run(t, name, func(t *testing.T) {
59+
t.Run(name, func(t *testing.T) {
6160
fn(t, tc)
6261
})
6362
}

secure/precis/benchmark_test.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ package precis
88

99
import (
1010
"testing"
11-
12-
"golang.org/x/text/internal/testtext"
1311
)
1412

1513
var benchData = []struct{ name, str string }{
@@ -33,7 +31,7 @@ var benchProfiles = []struct {
3331
func doBench(b *testing.B, f func(b *testing.B, p *Profile, s string)) {
3432
for _, bp := range benchProfiles {
3533
for _, d := range benchData {
36-
testtext.Bench(b, bp.name+"/"+d.name, func(b *testing.B) {
34+
b.Run(bp.name+"/"+d.name, func(b *testing.B) {
3735
f(b, bp.p, d.str)
3836
})
3937
}

secure/precis/enforce_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func doTests(t *testing.T, fn func(t *testing.T, p *Profile, tc testCase)) {
2424
for _, g := range enforceTestCases {
2525
for i, tc := range g.cases {
2626
name := fmt.Sprintf("%s:%d:%+q", g.name, i, tc.input)
27-
testtext.Run(t, name, func(t *testing.T) {
27+
t.Run(name, func(t *testing.T) {
2828
fn(t, g.p, tc)
2929
})
3030
}

secure/precis/profile_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"testing"
1111
"unicode"
1212

13-
"golang.org/x/text/internal/testtext"
1413
"golang.org/x/text/transform"
1514
)
1615

@@ -114,7 +113,7 @@ func doCompareTests(t *testing.T, fn func(t *testing.T, p *Profile, tc compareTe
114113
for _, g := range compareTestCases {
115114
for i, tc := range g.cases {
116115
name := fmt.Sprintf("%s:%d:%+q", g.name, i, tc.a)
117-
testtext.Run(t, name, func(t *testing.T) {
116+
t.Run(name, func(t *testing.T) {
118117
fn(t, g.p, tc)
119118
})
120119
}

transform/transform_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ var testCases = []testCase{
642642

643643
func TestReader(t *testing.T) {
644644
for _, tc := range testCases {
645-
testtext.Run(t, tc.desc, func(t *testing.T) {
645+
t.Run(tc.desc, func(t *testing.T) {
646646
r := NewReader(strings.NewReader(tc.src), tc.t)
647647
// Differently sized dst and src buffers are not part of the
648648
// exported API. We override them manually.
@@ -665,7 +665,7 @@ func TestWriter(t *testing.T) {
665665
sizes = []int{tc.ioSize}
666666
}
667667
for _, sz := range sizes {
668-
testtext.Run(t, fmt.Sprintf("%s/%d", tc.desc, sz), func(t *testing.T) {
668+
t.Run(fmt.Sprintf("%s/%d", tc.desc, sz), func(t *testing.T) {
669669
bb := &bytes.Buffer{}
670670
w := NewWriter(bb, tc.t)
671671
// Differently sized dst and src buffers are not part of the
@@ -1149,7 +1149,7 @@ func testString(t *testing.T, f func(Transformer, string) (string, int, error))
11491149
// The result string will be different.
11501150
continue
11511151
}
1152-
testtext.Run(t, tt.desc, func(t *testing.T) {
1152+
t.Run(tt.desc, func(t *testing.T) {
11531153
got, n, err := f(tt.t, tt.src)
11541154
if tt.wantErr != err {
11551155
t.Errorf("error: got %v; want %v", err, tt.wantErr)
@@ -1193,7 +1193,7 @@ func TestAppend(t *testing.T) {
11931193
}
11941194

11951195
func TestString(t *testing.T) {
1196-
testtext.Run(t, "transform", func(t *testing.T) { testString(t, String) })
1196+
t.Run("transform", func(t *testing.T) { testString(t, String) })
11971197

11981198
// Overrun the internal destination buffer.
11991199
for i, s := range []string{
@@ -1211,7 +1211,7 @@ func TestString(t *testing.T) {
12111211
aaa[:1*initialBufSize+0] + "A",
12121212
aaa[:1*initialBufSize+1] + "A",
12131213
} {
1214-
testtext.Run(t, fmt.Sprint("dst buffer test using lower/", i), func(t *testing.T) {
1214+
t.Run(fmt.Sprint("dst buffer test using lower/", i), func(t *testing.T) {
12151215
got, _, _ := String(lowerCaseASCII{}, s)
12161216
if want := strings.ToLower(s); got != want {
12171217
t.Errorf("got %s (%d); want %s (%d)", got, len(got), want, len(want))
@@ -1228,7 +1228,7 @@ func TestString(t *testing.T) {
12281228
aaa[:2*initialBufSize+0],
12291229
aaa[:2*initialBufSize+1],
12301230
} {
1231-
testtext.Run(t, fmt.Sprint("src buffer test using rleEncode/", i), func(t *testing.T) {
1231+
t.Run(fmt.Sprint("src buffer test using rleEncode/", i), func(t *testing.T) {
12321232
got, _, _ := String(rleEncode{}, s)
12331233
if want := fmt.Sprintf("%da", len(s)); got != want {
12341234
t.Errorf("got %s (%d); want %s (%d)", got, len(got), want, len(want))
@@ -1246,7 +1246,7 @@ func TestString(t *testing.T) {
12461246
aaa[:initialBufSize+1],
12471247
aaa[:10*initialBufSize],
12481248
} {
1249-
testtext.Run(t, fmt.Sprint("alloc/", i), func(t *testing.T) {
1249+
t.Run(fmt.Sprint("alloc/", i), func(t *testing.T) {
12501250
if n := testtext.AllocsPerRun(5, func() { String(&lowerCaseASCIILookahead{}, s) }); n > 1 {
12511251
t.Errorf("#allocs was %f; want 1", n)
12521252
}

unicode/cldr/collate_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ func TestRuleProcessor(t *testing.T) {
164164
},
165165
{
166166
desc: "err empty anchor",
167-
in: " & ",
168-
out: "E:1: missing string",
167+
in: " & ",
168+
out: "E:1: missing string",
169169
},
170170
{
171171
desc: "err anchor invalid special 1",
172-
in: " & [ foo ",
173-
out: "E:1: unmatched bracket",
172+
in: " & [ foo ",
173+
out: "E:1: unmatched bracket",
174174
},
175175
{
176176
desc: "err anchor invalid special 2",

0 commit comments

Comments
 (0)