Skip to content

Commit a888d62

Browse files
dkegel-fastlydeadprogram
authored andcommitted
testing: replace spaces with underscores in test/benchmark names, as upstream does
1 parent f80efa5 commit a888d62

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

src/testing/benchmark.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ func (b *B) processBench(ctx *benchContext) {
329329
// least once will not be measured itself and will be called once with N=1.
330330
func (b *B) Run(name string, f func(b *B)) bool {
331331
if b.level > 0 {
332-
name = b.name + "/" + name
332+
name = b.name + "/" + rewrite(name)
333333
}
334334
b.hasSub = true
335335
sub := &B{

src/testing/match.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2015 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package testing
6+
7+
import (
8+
"strconv"
9+
)
10+
11+
// rewrite rewrites a subname to having only printable characters and no white
12+
// space.
13+
func rewrite(s string) string {
14+
b := []byte{}
15+
for _, r := range s {
16+
switch {
17+
case isSpace(r):
18+
b = append(b, '_')
19+
case !strconv.IsPrint(r):
20+
s := strconv.QuoteRune(r)
21+
b = append(b, s[1:len(s)-1]...)
22+
default:
23+
b = append(b, string(r)...)
24+
}
25+
}
26+
return string(b)
27+
}
28+
29+
func isSpace(r rune) bool {
30+
if r < 0x2000 {
31+
switch r {
32+
// Note: not the same as Unicode Z class.
33+
case '\t', '\n', '\v', '\f', '\r', ' ', 0x85, 0xA0, 0x1680:
34+
return true
35+
}
36+
} else {
37+
if r <= 0x200a {
38+
return true
39+
}
40+
switch r {
41+
case 0x2028, 0x2029, 0x202f, 0x205f, 0x3000:
42+
return true
43+
}
44+
}
45+
return false
46+
}

src/testing/testing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func (t *T) Run(name string, f func(t *T)) bool {
211211
// Create a subtest.
212212
sub := T{
213213
common: common{
214-
name: t.name + "/" + name,
214+
name: t.name + "/" + rewrite(name),
215215
indent: t.indent + " ",
216216
},
217217
}

0 commit comments

Comments
 (0)