testing: replace spaces with underscores in test/benchmark names, as upstream does
Этот коммит содержится в:
родитель
f80efa5b8b
коммит
a888d6245d
3 изменённых файлов: 48 добавлений и 2 удалений
|
@ -329,7 +329,7 @@ func (b *B) processBench(ctx *benchContext) {
|
|||
// least once will not be measured itself and will be called once with N=1.
|
||||
func (b *B) Run(name string, f func(b *B)) bool {
|
||||
if b.level > 0 {
|
||||
name = b.name + "/" + name
|
||||
name = b.name + "/" + rewrite(name)
|
||||
}
|
||||
b.hasSub = true
|
||||
sub := &B{
|
||||
|
|
46
src/testing/match.go
Обычный файл
46
src/testing/match.go
Обычный файл
|
@ -0,0 +1,46 @@
|
|||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package testing
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// rewrite rewrites a subname to having only printable characters and no white
|
||||
// space.
|
||||
func rewrite(s string) string {
|
||||
b := []byte{}
|
||||
for _, r := range s {
|
||||
switch {
|
||||
case isSpace(r):
|
||||
b = append(b, '_')
|
||||
case !strconv.IsPrint(r):
|
||||
s := strconv.QuoteRune(r)
|
||||
b = append(b, s[1:len(s)-1]...)
|
||||
default:
|
||||
b = append(b, string(r)...)
|
||||
}
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func isSpace(r rune) bool {
|
||||
if r < 0x2000 {
|
||||
switch r {
|
||||
// Note: not the same as Unicode Z class.
|
||||
case '\t', '\n', '\v', '\f', '\r', ' ', 0x85, 0xA0, 0x1680:
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
if r <= 0x200a {
|
||||
return true
|
||||
}
|
||||
switch r {
|
||||
case 0x2028, 0x2029, 0x202f, 0x205f, 0x3000:
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
|
@ -211,7 +211,7 @@ func (t *T) Run(name string, f func(t *T)) bool {
|
|||
// Create a subtest.
|
||||
sub := T{
|
||||
common: common{
|
||||
name: t.name + "/" + name,
|
||||
name: t.name + "/" + rewrite(name),
|
||||
indent: t.indent + " ",
|
||||
},
|
||||
}
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче