On baremetal platforms, use simpler test matcher. Fixes #2666.
Uses same matcher in testdata (because now we can't replace it in testdata).
Этот коммит содержится в:
родитель
eed78338e6
коммит
c534fa1b6f
5 изменённых файлов: 47 добавлений и 11 удалений
10
src/testing/is_baremetal.go
Обычный файл
10
src/testing/is_baremetal.go
Обычный файл
|
@ -0,0 +1,10 @@
|
|||
// Copyright 2016 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.
|
||||
//
|
||||
//go:build baremetal
|
||||
// +build baremetal
|
||||
|
||||
package testing
|
||||
|
||||
const isBaremetal = true
|
10
src/testing/is_not_baremetal.go
Обычный файл
10
src/testing/is_not_baremetal.go
Обычный файл
|
@ -0,0 +1,10 @@
|
|||
// Copyright 2016 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.
|
||||
//
|
||||
//go:build !baremetal
|
||||
// +build !baremetal
|
||||
|
||||
package testing
|
||||
|
||||
const isBaremetal = false
|
|
@ -26,6 +26,11 @@ type matcher struct {
|
|||
var matchMutex sync.Mutex
|
||||
|
||||
func newMatcher(matchString func(pat, str string) (bool, error), patterns, name string) *matcher {
|
||||
if isBaremetal {
|
||||
// Probably not enough ram to load regexp, substitute something simpler.
|
||||
matchString = fakeMatchString
|
||||
}
|
||||
|
||||
var filter []string
|
||||
if patterns != "" {
|
||||
filter = splitRegexp(patterns)
|
||||
|
@ -166,3 +171,14 @@ func isSpace(r rune) bool {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// A fake regexp matcher.
|
||||
// Inflexible, but saves 50KB of flash and 50KB of RAM per -size full,
|
||||
// and lets tests pass on cortex-m.
|
||||
func fakeMatchString(pat, str string) (bool, error) {
|
||||
if pat == ".*" {
|
||||
return true, nil
|
||||
}
|
||||
matched := strings.Contains(str, pat)
|
||||
return matched, nil
|
||||
}
|
||||
|
|
18
testdata/testing.go
предоставленный
18
testdata/testing.go
предоставленный
|
@ -6,6 +6,7 @@ import (
|
|||
"errors"
|
||||
"flag"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -32,7 +33,7 @@ func TestAllLowercase(t *testing.T) {
|
|||
"alpha",
|
||||
"BETA",
|
||||
"gamma",
|
||||
"DELTA",
|
||||
"BELTA",
|
||||
}
|
||||
|
||||
for _, name := range names {
|
||||
|
@ -56,23 +57,22 @@ var benchmarks = []testing.InternalBenchmark{}
|
|||
|
||||
var examples = []testing.InternalExample{}
|
||||
|
||||
// A fake regexp matcher that can only handle two patterns.
|
||||
// A fake regexp matcher.
|
||||
// Inflexible, but saves 50KB of flash and 50KB of RAM per -size full,
|
||||
// and lets tests pass on cortex-m3.
|
||||
// and lets tests pass on cortex-m.
|
||||
// Must match the one in src/testing/match.go that is substituted on bare-metal platforms,
|
||||
// or "make test" will fail there.
|
||||
func fakeMatchString(pat, str string) (bool, error) {
|
||||
if pat == ".*" {
|
||||
return true, nil
|
||||
}
|
||||
if pat == "[BD]" {
|
||||
return (str[0] == 'B' || str[0] == 'D'), nil
|
||||
}
|
||||
println("BUG: fakeMatchString does not grok", pat)
|
||||
return false, nil
|
||||
matched := strings.Contains(str, pat)
|
||||
return matched, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
testing.Init()
|
||||
flag.Set("test.run", ".*/[BD]")
|
||||
flag.Set("test.run", ".*/B")
|
||||
m := testing.MainStart(matchStringOnly(fakeMatchString /*regexp.MatchString*/), tests, benchmarks, examples)
|
||||
|
||||
exitcode := m.Run()
|
||||
|
|
4
testdata/testing.txt
предоставленный
4
testdata/testing.txt
предоставленный
|
@ -15,7 +15,7 @@
|
|||
--- FAIL: TestAllLowercase (0.00s)
|
||||
--- FAIL: TestAllLowercase/BETA (0.00s)
|
||||
expected lowercase name, got BETA
|
||||
--- FAIL: TestAllLowercase/DELTA (0.00s)
|
||||
expected lowercase name, got DELTA
|
||||
--- FAIL: TestAllLowercase/BELTA (0.00s)
|
||||
expected lowercase name, got BELTA
|
||||
FAIL
|
||||
exitcode: 1
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче