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
|
var matchMutex sync.Mutex
|
||||||
|
|
||||||
func newMatcher(matchString func(pat, str string) (bool, error), patterns, name string) *matcher {
|
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
|
var filter []string
|
||||||
if patterns != "" {
|
if patterns != "" {
|
||||||
filter = splitRegexp(patterns)
|
filter = splitRegexp(patterns)
|
||||||
|
@ -166,3 +171,14 @@ func isSpace(r rune) bool {
|
||||||
}
|
}
|
||||||
return false
|
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"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"io"
|
"io"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ func TestAllLowercase(t *testing.T) {
|
||||||
"alpha",
|
"alpha",
|
||||||
"BETA",
|
"BETA",
|
||||||
"gamma",
|
"gamma",
|
||||||
"DELTA",
|
"BELTA",
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
|
@ -56,23 +57,22 @@ var benchmarks = []testing.InternalBenchmark{}
|
||||||
|
|
||||||
var examples = []testing.InternalExample{}
|
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,
|
// 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) {
|
func fakeMatchString(pat, str string) (bool, error) {
|
||||||
if pat == ".*" {
|
if pat == ".*" {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
if pat == "[BD]" {
|
matched := strings.Contains(str, pat)
|
||||||
return (str[0] == 'B' || str[0] == 'D'), nil
|
return matched, nil
|
||||||
}
|
|
||||||
println("BUG: fakeMatchString does not grok", pat)
|
|
||||||
return false, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
testing.Init()
|
testing.Init()
|
||||||
flag.Set("test.run", ".*/[BD]")
|
flag.Set("test.run", ".*/B")
|
||||||
m := testing.MainStart(matchStringOnly(fakeMatchString /*regexp.MatchString*/), tests, benchmarks, examples)
|
m := testing.MainStart(matchStringOnly(fakeMatchString /*regexp.MatchString*/), tests, benchmarks, examples)
|
||||||
|
|
||||||
exitcode := m.Run()
|
exitcode := m.Run()
|
||||||
|
|
4
testdata/testing.txt
предоставленный
4
testdata/testing.txt
предоставленный
|
@ -15,7 +15,7 @@
|
||||||
--- FAIL: TestAllLowercase (0.00s)
|
--- FAIL: TestAllLowercase (0.00s)
|
||||||
--- FAIL: TestAllLowercase/BETA (0.00s)
|
--- FAIL: TestAllLowercase/BETA (0.00s)
|
||||||
expected lowercase name, got BETA
|
expected lowercase name, got BETA
|
||||||
--- FAIL: TestAllLowercase/DELTA (0.00s)
|
--- FAIL: TestAllLowercase/BELTA (0.00s)
|
||||||
expected lowercase name, got DELTA
|
expected lowercase name, got BELTA
|
||||||
FAIL
|
FAIL
|
||||||
exitcode: 1
|
exitcode: 1
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче