aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata
diff options
context:
space:
mode:
authorDan Kegel <[email protected]>2022-01-16 20:04:34 -0800
committerRon Evans <[email protected]>2022-01-17 21:54:20 +0100
commitdd6adcacb634e485d45fb77f3b3fc16c642d6a03 (patch)
treed0e30d86804d83f3728f3b7372007bfbf733c49e /testdata
parent610a20c4d5fdef42e462ffde30fae41f2ba832c4 (diff)
downloadtinygo-dd6adcacb634e485d45fb77f3b3fc16c642d6a03.tar.gz
tinygo-dd6adcacb634e485d45fb77f3b3fc16c642d6a03.zip
testing: --run now allows filtering of subtests
Also fix typo in error message in sub_test.go from upstream, and move a few members from B to common where they belonged. Note that testdata/testing.go seems to be pushing the edge of what the emulated cortex-m3 target can handle; using regexp in that test causes it to fail on that target with an out of memory error. TODO: once tinygo supports runtime.Goexit, consider just using upstream's testing directory...
Diffstat (limited to 'testdata')
-rw-r--r--testdata/testing.go54
-rw-r--r--testdata/testing.txt5
2 files changed, 51 insertions, 8 deletions
diff --git a/testdata/testing.go b/testdata/testing.go
index 9e0a018d1..4a1f67c49 100644
--- a/testdata/testing.go
+++ b/testdata/testing.go
@@ -4,6 +4,7 @@ package main
import (
"errors"
+ "flag"
"io"
"testing"
)
@@ -26,15 +27,60 @@ func TestBar(t *testing.T) {
t.Log("log Bar end")
}
+func TestAllLowercase(t *testing.T) {
+ names := []string {
+ "alpha",
+ "BETA",
+ "gamma",
+ "DELTA",
+ }
+
+ for _, name := range names {
+ t.Run(name, func(t *testing.T) {
+ if 'a' <= name[0] && name[0] <= 'a' {
+ t.Logf("expected lowercase name, and got one, so I'm happy")
+ } else {
+ t.Errorf("expected lowercase name, got %s", name)
+ }
+ })
+ }
+}
+
var tests = []testing.InternalTest{
{"TestFoo", TestFoo},
{"TestBar", TestBar},
+ {"TestAllLowercase", TestAllLowercase},
}
var benchmarks = []testing.InternalBenchmark{}
var examples = []testing.InternalExample{}
+// A fake regexp matcher that can only handle two patterns.
+// Inflexible, but saves 50KB of flash and 50KB of RAM per -size full,
+// and lets tests pass on cortex-m3.
+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
+}
+
+func main() {
+ testing.Init()
+ flag.Set("test.run", ".*/[BD]")
+ m := testing.MainStart(matchStringOnly(fakeMatchString /*regexp.MatchString*/), tests, benchmarks, examples)
+
+ exitcode := m.Run()
+ if exitcode != 0 {
+ println("exitcode:", exitcode)
+ }
+}
+
var errMain = errors.New("testing: unexpected use of func Main")
// matchStringOnly is part of upstream, and is used below to provide a dummy deps to pass to MainStart
@@ -50,11 +96,3 @@ func (f matchStringOnly) ImportPath() string { return "
func (f matchStringOnly) StartTestLog(io.Writer) {}
func (f matchStringOnly) StopTestLog() error { return errMain }
func (f matchStringOnly) SetPanicOnExit0(bool) {}
-
-func main() {
- m := testing.MainStart(matchStringOnly(nil), tests, benchmarks, examples)
- exitcode := m.Run()
- if exitcode != 0 {
- println("exitcode:", exitcode)
- }
-}
diff --git a/testdata/testing.txt b/testdata/testing.txt
index 814ddff3b..ff124de14 100644
--- a/testdata/testing.txt
+++ b/testdata/testing.txt
@@ -12,5 +12,10 @@
failed
after failed
log Bar end
+--- 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
exitcode: 1