all: drop support for Go 1.16 and Go 1.17

This commit is contained in:
Ayke van Laethem
2022-06-11 17:24:54 +02:00
committed by Ron Evans
parent f094e895c5
commit 4695da83b7
33 changed files with 249 additions and 628 deletions
-34
View File
@@ -1,34 +0,0 @@
package main
// Test new language features introduced in Go 1.17:
// https://tip.golang.org/doc/go1.17#language
// Once this becomes the minimum Go version of TinyGo, these tests should be
// merged with the regular slice tests.
import "unsafe"
func main() {
// Test conversion from array to slice.
slice1 := []int{1, 2, 3, 4}
arr1 := (*[4]int)(slice1)
arr1[1] = -2
arr1[2] = 20
println("slice to array pointer:", arr1[0], arr1[1], arr1[2], arr1[3])
// Test unsafe.Add.
arr2 := [...]int{1, 2, 3, 4}
*(*int)(unsafe.Add(unsafe.Pointer(&arr2[0]), unsafe.Sizeof(int(1))*1)) = 5
*addInt(&arr2[0], 2) = 8
println("unsafe.Add array:", arr2[0], arr2[1], arr2[2], arr2[3])
// Test unsafe.Slice.
arr3 := [...]int{1, 2, 3, 4}
slice3 := unsafe.Slice(&arr3[1], 3)
slice3[0] = 9
slice3[1] = 15
println("unsafe.Slice array:", len(slice3), cap(slice3), slice3[0], slice3[1], slice3[2])
}
func addInt(ptr *int, index uintptr) *int {
return (*int)(unsafe.Add(unsafe.Pointer(ptr), unsafe.Sizeof(int(1))*index))
}
-3
View File
@@ -1,3 +0,0 @@
slice to array pointer: 1 -2 20 4
unsafe.Add array: 1 5 8 4
unsafe.Slice array: 3 3 9 15 4
+26
View File
@@ -1,5 +1,7 @@
package main
import "unsafe"
type MySlice [32]byte
type myUint8 uint8
@@ -130,6 +132,26 @@ func main() {
}
println()
// Test conversion from array to slice.
slice1 := []int{1, 2, 3, 4}
arr1 := (*[4]int)(slice1)
arr1[1] = -2
arr1[2] = 20
println("slice to array pointer:", arr1[0], arr1[1], arr1[2], arr1[3])
// Test unsafe.Add.
arr2 := [...]int{1, 2, 3, 4}
*(*int)(unsafe.Add(unsafe.Pointer(&arr2[0]), unsafe.Sizeof(int(1))*1)) = 5
*addInt(&arr2[0], 2) = 8
println("unsafe.Add array:", arr2[0], arr2[1], arr2[2], arr2[3])
// Test unsafe.Slice.
arr3 := [...]int{1, 2, 3, 4}
slice3 := unsafe.Slice(&arr3[1], 3)
slice3[0] = 9
slice3[1] = 15
println("unsafe.Slice array:", len(slice3), cap(slice3), slice3[0], slice3[1], slice3[2])
// Verify the fix in https://github.com/tinygo-org/tinygo/pull/119
var unnamed [32]byte
var named MySlice
@@ -177,3 +199,7 @@ func makeUint32(x uint32) uint32 { return x }
func makeUint64(x uint64) uint64 { return x }
func makeUintptr(x uintptr) uintptr { return x }
func makeMyUint8(x myUint8) myUint8 { return x }
func addInt(ptr *int, index uintptr) *int {
return (*int)(unsafe.Add(unsafe.Pointer(ptr), unsafe.Sizeof(int(1))*index))
}
+3
View File
@@ -13,3 +13,6 @@ grow: len=7 cap=8 data: 42 -1 -2 1 2 4 5
grow: len=7 cap=8 data: 42 -1 -2 1 2 4 5
grow: len=14 cap=16 data: 42 -1 -2 1 2 4 5 42 -1 -2 1 2 4 5
bytes: len=6 cap=6 data: 1 2 3 102 111 111
slice to array pointer: 1 -2 20 4
unsafe.Add array: 1 5 8 4
unsafe.Slice array: 3 3 9 15 4
+3 -1
View File
@@ -55,6 +55,8 @@ var tests = []testing.InternalTest{
var benchmarks = []testing.InternalBenchmark{}
var fuzzes = []testing.InternalFuzzTarget{}
var examples = []testing.InternalExample{}
// A fake regexp matcher.
@@ -73,7 +75,7 @@ func fakeMatchString(pat, str string) (bool, error) {
func main() {
testing.Init()
flag.Set("test.run", ".*/B")
m := testing.MainStart(matchStringOnly(fakeMatchString /*regexp.MatchString*/), tests, benchmarks, examples)
m := testing.MainStart(matchStringOnly(fakeMatchString /*regexp.MatchString*/), tests, benchmarks, fuzzes, examples)
exitcode := m.Run()
if exitcode != 0 {
-100
View File
@@ -1,100 +0,0 @@
package main
// TODO: also test the verbose version.
import (
"errors"
"flag"
"io"
"strings"
"testing"
)
func TestFoo(t *testing.T) {
t.Log("log Foo.a")
t.Log("log Foo.b")
}
func TestBar(t *testing.T) {
t.Log("log Bar")
t.Log("log g\nh\ni\n")
t.Run("Bar1", func(t *testing.T) {})
t.Run("Bar2", func(t *testing.T) {
t.Log("log Bar2\na\nb\nc")
t.Error("failed")
t.Log("after failed")
})
t.Run("Bar3", func(t *testing.T) {})
t.Log("log Bar end")
}
func TestAllLowercase(t *testing.T) {
names := []string {
"alpha",
"BETA",
"gamma",
"BELTA",
}
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 fuzzes = []testing.InternalFuzzTarget{}
var examples = []testing.InternalExample{}
// A fake regexp matcher.
// Inflexible, but saves 50KB of flash and 50KB of RAM per -size full,
// 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
}
matched := strings.Contains(str, pat)
return matched, nil
}
func main() {
testing.Init()
flag.Set("test.run", ".*/B")
m := testing.MainStart(matchStringOnly(fakeMatchString /*regexp.MatchString*/), tests, benchmarks, fuzzes, 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
// so it can be run with go (tested with go 1.16) to provide a baseline for the regression test.
// See c56cc9b3b57276. Unfortunately, testdeps is internal, so we can't just use &testdeps.TestDeps{}.
type matchStringOnly func(pat, str string) (bool, error)
func (f matchStringOnly) MatchString(pat, str string) (bool, error) { return f(pat, str) }
func (f matchStringOnly) StartCPUProfile(w io.Writer) error { return errMain }
func (f matchStringOnly) StopCPUProfile() {}
func (f matchStringOnly) WriteProfileTo(string, io.Writer, int) error { return errMain }
func (f matchStringOnly) ImportPath() string { return "" }
func (f matchStringOnly) StartTestLog(io.Writer) {}
func (f matchStringOnly) StopTestLog() error { return errMain }
func (f matchStringOnly) SetPanicOnExit0(bool) {}
-21
View File
@@ -1,21 +0,0 @@
--- FAIL: TestBar (0.00s)
log Bar
log g
h
i
--- FAIL: TestBar/Bar2 (0.00s)
log Bar2
a
b
c
failed
after failed
log Bar end
--- FAIL: TestAllLowercase (0.00s)
--- FAIL: TestAllLowercase/BETA (0.00s)
expected lowercase name, got BETA
--- FAIL: TestAllLowercase/BELTA (0.00s)
expected lowercase name, got BELTA
FAIL
exitcode: 1