t.Parallel()
doTest(t, filename, "run", flags...)
}
-func buildTest(t *testing.T, filename string, flags ...string) {
- t.Parallel()
- doTest(t, filename, "build", flags...)
-}
func doTest(t *testing.T, filename string, kind string, flags ...string) {
testenv.MustHaveGoBuild(t)
gotool := testenv.GoToolPath(t)
}
}
-func TestChan(t *testing.T) { runTest(t, "chan.go") }
-
-func TestCompound(t *testing.T) { runTest(t, "compound.go") }
-
-func TestCtl(t *testing.T) { runTest(t, "ctl.go") }
-
-func TestLoadStore(t *testing.T) { runTest(t, "loadstore.go") }
-
-func TestMap(t *testing.T) { runTest(t, "map.go") }
-
-func TestRegalloc(t *testing.T) { runTest(t, "regalloc.go") }
-
-func TestString(t *testing.T) { runTest(t, "string.go") }
-
-func TestDeferNoReturn(t *testing.T) { buildTest(t, "deferNoReturn.go") }
-
// TestClosure tests closure related behavior.
func TestClosure(t *testing.T) { runTest(t, "closure.go") }
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// chan_ssa.go tests chan operations.
+// chan.go tests chan operations.
package main
-import "fmt"
-
-var failed = false
+import "testing"
//go:noinline
func lenChan_ssa(v chan int) int {
return cap(v)
}
-func testLenChan() {
+func testLenChan(t *testing.T) {
v := make(chan int, 10)
v <- 1
v <- 1
if want, got := 3, lenChan_ssa(v); got != want {
- fmt.Printf("expected len(chan) = %d, got %d", want, got)
- failed = true
+ t.Errorf("expected len(chan) = %d, got %d", want, got)
}
}
-func testLenNilChan() {
+func testLenNilChan(t *testing.T) {
var v chan int
if want, got := 0, lenChan_ssa(v); got != want {
- fmt.Printf("expected len(nil) = %d, got %d", want, got)
- failed = true
+ t.Errorf("expected len(nil) = %d, got %d", want, got)
}
}
-func testCapChan() {
+func testCapChan(t *testing.T) {
v := make(chan int, 25)
if want, got := 25, capChan_ssa(v); got != want {
- fmt.Printf("expected cap(chan) = %d, got %d", want, got)
- failed = true
+ t.Errorf("expected cap(chan) = %d, got %d", want, got)
}
}
-func testCapNilChan() {
+func testCapNilChan(t *testing.T) {
var v chan int
if want, got := 0, capChan_ssa(v); got != want {
- fmt.Printf("expected cap(nil) = %d, got %d", want, got)
- failed = true
+ t.Errorf("expected cap(nil) = %d, got %d", want, got)
}
}
-func main() {
- testLenChan()
- testLenNilChan()
-
- testCapChan()
- testCapNilChan()
+func TestChan(t *testing.T) {
+ testLenChan(t)
+ testLenNilChan(t)
- if failed {
- panic("failed")
- }
+ testCapChan(t)
+ testCapNilChan(t)
}
-// run
-
// 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 main
-import "fmt"
+import (
+ "testing"
+)
func string_ssa(a, b string, x bool) string {
s := ""
return s
}
-func testString() {
+func testString(t *testing.T) {
a := "foo"
b := "barz"
if want, got := a, string_ssa(a, b, true); got != want {
- fmt.Printf("string_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
- failed = true
+ t.Errorf("string_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
}
if want, got := b, string_ssa(a, b, false); got != want {
- fmt.Printf("string_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want)
- failed = true
+ t.Errorf("string_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want)
}
}
return c
}
-func testComplex64() {
+func testComplex64(t *testing.T) {
var a complex64 = 1 + 2i
var b complex64 = 3 + 4i
if want, got := a, complex64_ssa(a, b, true); got != want {
- fmt.Printf("complex64_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
- failed = true
+ t.Errorf("complex64_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
}
if want, got := b, complex64_ssa(a, b, false); got != want {
- fmt.Printf("complex64_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
- failed = true
+ t.Errorf("complex64_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
}
}
-func testComplex128() {
+func testComplex128(t *testing.T) {
var a complex128 = 1 + 2i
var b complex128 = 3 + 4i
if want, got := a, complex128_ssa(a, b, true); got != want {
- fmt.Printf("complex128_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
- failed = true
+ t.Errorf("complex128_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
}
if want, got := b, complex128_ssa(a, b, false); got != want {
- fmt.Printf("complex128_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
- failed = true
+ t.Errorf("complex128_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
}
}
return s
}
-func testSlice() {
+func testSlice(t *testing.T) {
a := []byte{3, 4, 5}
b := []byte{7, 8, 9}
if want, got := byte(3), slice_ssa(a, b, true)[0]; got != want {
- fmt.Printf("slice_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
- failed = true
+ t.Errorf("slice_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
}
if want, got := byte(7), slice_ssa(a, b, false)[0]; got != want {
- fmt.Printf("slice_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want)
- failed = true
+ t.Errorf("slice_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want)
}
}
return s
}
-func testInterface() {
+func testInterface(t *testing.T) {
a := interface{}(3)
b := interface{}(4)
if want, got := 3, interface_ssa(a, b, true).(int); got != want {
- fmt.Printf("interface_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
- failed = true
+ t.Errorf("interface_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
}
if want, got := 4, interface_ssa(a, b, false).(int); got != want {
- fmt.Printf("interface_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want)
- failed = true
+ t.Errorf("interface_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want)
}
}
-var failed = false
-
-func main() {
- testString()
- testSlice()
- testInterface()
- testComplex64()
- testComplex128()
- if failed {
- panic("failed")
- }
+func TestCompound(t *testing.T) {
+ testString(t)
+ testSlice(t)
+ testInterface(t)
+ testComplex64(t)
+ testComplex128(t)
}
-// run
-
// 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 main
+import "testing"
+
// nor_ssa calculates NOR(a, b).
// It is implemented in a way that generates
// phi control values.
return true
}
-func testPhiControl() {
+func testPhiControl(t *testing.T) {
tests := [...][3]bool{ // a, b, want
{false, false, true},
{true, false, false},
got := nor_ssa(a, b)
want := test[2]
if want != got {
- print("nor(", a, ", ", b, ")=", want, " got ", got, "\n")
- failed = true
+ t.Errorf("nor(%t, %t)=%t got %t", a, b, want, got)
}
}
}
return true
}
-func testEmptyRange() {
+func testEmptyRange(t *testing.T) {
if !emptyRange_ssa([]byte{}) {
- println("emptyRange_ssa([]byte{})=false, want true")
- failed = true
+ t.Errorf("emptyRange_ssa([]byte{})=false, want true")
}
}
}
-func testFallthrough() {
+func testFallthrough(t *testing.T) {
for i := 0; i < 6; i++ {
if got := fallthrough_ssa(i); got != i {
- println("fallthrough_ssa(i) =", got, "wanted", i)
- failed = true
+ t.Errorf("fallthrough_ssa(i) = %d, wanted %d", got, i)
}
}
}
-func testSwitch() {
+func testSwitch(t *testing.T) {
for i := 0; i < 6; i++ {
if got := switch_ssa(i); got != i {
- println("switch_ssa(i) =", got, "wanted", i)
- failed = true
+ t.Errorf("switch_ssa(i) = %d, wanted %d", got, i)
}
}
}
return 3
}
-func testFlagOverwrite() {
+func testFlagOverwrite(t *testing.T) {
j := junk{}
if got := flagOverwrite_ssa(&j, ' '); got != 3 {
- println("flagOverwrite_ssa =", got, "wanted 3")
- failed = true
+ t.Errorf("flagOverwrite_ssa = %d, wanted 3", got)
}
}
-var failed = false
-
-func main() {
- testPhiControl()
- testEmptyRange()
+func TestCtl(t *testing.T) {
+ testPhiControl(t)
+ testEmptyRange(t)
- testSwitch()
- testFallthrough()
+ testSwitch(t)
+ testFallthrough(t)
- testFlagOverwrite()
-
- if failed {
- panic("failed")
- }
+ testFlagOverwrite(t)
}
-// compile
-
// 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.
// Test that a defer in a function with no return
// statement will compile correctly.
-package foo
+package main
+
+import "testing"
func deferNoReturn_ssa() {
defer func() { println("returned") }()
println("loop")
}
}
+
+func TestDeferNoReturn(t *testing.T) {
+ // This is a compile-time test, no runtime testing required.
+}
-// run
-
// 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 main
-import "fmt"
+import "testing"
// testLoadStoreOrder tests for reordering of stores/loads.
-func testLoadStoreOrder() {
+func testLoadStoreOrder(t *testing.T) {
z := uint32(1000)
if testLoadStoreOrder_ssa(&z, 100) == 0 {
- println("testLoadStoreOrder failed")
- failed = true
+ t.Errorf("testLoadStoreOrder failed")
}
}
return 0
}
-func testStoreSize() {
+func testStoreSize(t *testing.T) {
a := [4]uint16{11, 22, 33, 44}
testStoreSize_ssa(&a[0], &a[2], 77)
want := [4]uint16{77, 22, 33, 44}
if a != want {
- fmt.Println("testStoreSize failed. want =", want, ", got =", a)
- failed = true
+ t.Errorf("testStoreSize failed. want = %d, got = %d", want, a)
}
}
}
}
-var failed = false
-
//go:noinline
func testExtStore_ssa(p *byte, b bool) int {
x := *p
return 0
}
-func testExtStore() {
+func testExtStore(t *testing.T) {
const start = 8
var b byte = start
if got := testExtStore_ssa(&b, true); got != start {
- fmt.Println("testExtStore failed. want =", start, ", got =", got)
- failed = true
+ t.Errorf("testExtStore failed. want = %d, got = %d", start, got)
}
}
return
}
-func testDeadStorePanic() {
+func testDeadStorePanic(t *testing.T) {
if want, got := 2, testDeadStorePanic_ssa(1); want != got {
- fmt.Println("testDeadStorePanic failed. want =", want, ", got =", got)
- failed = true
+ t.Errorf("testDeadStorePanic failed. want = %d, got = %d", want, got)
}
}
return uint64(*p) // load and cast
}
-func testLoadHitStore() {
+func testLoadHitStore(t *testing.T) {
// Test that sign/zero extensions are kept when a load-hit-store
// is replaced by a register-register move.
{
got := loadHitStore8(in, &p)
want := int32(in * in)
if got != want {
- fmt.Println("testLoadHitStore (int8) failed. want =", want, ", got =", got)
- failed = true
+ t.Errorf("testLoadHitStore (int8) failed. want = %d, got = %d", want, got)
}
}
{
got := loadHitStoreU8(in, &p)
want := uint32(in * in)
if got != want {
- fmt.Println("testLoadHitStore (uint8) failed. want =", want, ", got =", got)
- failed = true
+ t.Errorf("testLoadHitStore (uint8) failed. want = %d, got = %d", want, got)
}
}
{
got := loadHitStore16(in, &p)
want := int32(in * in)
if got != want {
- fmt.Println("testLoadHitStore (int16) failed. want =", want, ", got =", got)
- failed = true
+ t.Errorf("testLoadHitStore (int16) failed. want = %d, got = %d", want, got)
}
}
{
got := loadHitStoreU16(in, &p)
want := uint32(in * in)
if got != want {
- fmt.Println("testLoadHitStore (uint16) failed. want =", want, ", got =", got)
- failed = true
+ t.Errorf("testLoadHitStore (uint16) failed. want = %d, got = %d", want, got)
}
}
{
got := loadHitStore32(in, &p)
want := int64(in * in)
if got != want {
- fmt.Println("testLoadHitStore (int32) failed. want =", want, ", got =", got)
- failed = true
+ t.Errorf("testLoadHitStore (int32) failed. want = %d, got = %d", want, got)
}
}
{
got := loadHitStoreU32(in, &p)
want := uint64(in * in)
if got != want {
- fmt.Println("testLoadHitStore (uint32) failed. want =", want, ", got =", got)
- failed = true
+ t.Errorf("testLoadHitStore (uint32) failed. want = %d, got = %d", want, got)
}
}
}
-func main() {
-
- testLoadStoreOrder()
- testStoreSize()
- testExtStore()
- testDeadStorePanic()
- testLoadHitStore()
-
- if failed {
- panic("failed")
- }
+func TestLoadStore(t *testing.T) {
+ testLoadStoreOrder(t)
+ testStoreSize(t)
+ testExtStore(t)
+ testDeadStorePanic(t)
+ testLoadHitStore(t)
}
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// map_ssa.go tests map operations.
+// map.go tests map operations.
package main
-import "fmt"
-
-var failed = false
+import "testing"
//go:noinline
func lenMap_ssa(v map[int]int) int {
return len(v)
}
-func testLenMap() {
+func testLenMap(t *testing.T) {
v := make(map[int]int)
v[0] = 0
v[2] = 0
if want, got := 3, lenMap_ssa(v); got != want {
- fmt.Printf("expected len(map) = %d, got %d", want, got)
- failed = true
+ t.Errorf("expected len(map) = %d, got %d", want, got)
}
}
-func testLenNilMap() {
+func testLenNilMap(t *testing.T) {
var v map[int]int
if want, got := 0, lenMap_ssa(v); got != want {
- fmt.Printf("expected len(nil) = %d, got %d", want, got)
- failed = true
+ t.Errorf("expected len(nil) = %d, got %d", want, got)
}
}
-func main() {
- testLenMap()
- testLenNilMap()
-
- if failed {
- panic("failed")
- }
+func TestMap(t *testing.T) {
+ testLenMap(t)
+ testLenNilMap(t)
}
--- /dev/null
+// Copyright 2018 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.
+
+// This file exists just to convince vet not to check this directory.
+// (vet will not check a directory with two different packages in it.)
+// TODO: remove this hack & add failing tests to the whitelist.
+
+package foo
-// run
-
// 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 main
+import "testing"
+
func phiOverwrite_ssa() int {
var n int
for i := 0; i < 10; i++ {
return n
}
-func phiOverwrite() {
+func phiOverwrite(t *testing.T) {
want := 5
got := phiOverwrite_ssa()
if got != want {
- println("phiOverwrite_ssa()=", want, ", got", got)
- failed = true
+ t.Errorf("phiOverwrite_ssa()= %d, got %d", want, got)
}
}
return a*1 + b*2 + c*3 + d*4 + e*5 + f*6 + g*7 + h*8 + i*9 + j*10 + k*11 + l*12 + m*13 + n*14 + o*15 + p*16 + q*17 + r*18 + s*19 + t*20 + u*21 + v*22 + w*23 + x*24 + y*25 + z*26
}
-func phiOverwriteBig() {
+func phiOverwriteBig(t *testing.T) {
want := 1
got := phiOverwriteBig_ssa()
if got != want {
- println("phiOverwriteBig_ssa()=", want, ", got", got)
- failed = true
+ t.Errorf("phiOverwriteBig_ssa()= %d, got %d", want, got)
}
}
-var failed = false
-
-func main() {
- phiOverwrite()
- phiOverwriteBig()
- if failed {
- panic("failed")
- }
+func TestRegalloc(t *testing.T) {
+ phiOverwrite(t)
+ phiOverwriteBig(t)
}
// string_ssa.go tests string operations.
package main
-var failed = false
+import "testing"
//go:noinline
func testStringSlice1_ssa(a string, i, j int) string {
return a[i:j]
}
-func testStringSlice() {
+func testStringSlice(t *testing.T) {
tests := [...]struct {
fn func(string, int, int) string
s string
{testStringSlice12_ssa, "", 0, 0, ""},
}
- for i, t := range tests {
- if got := t.fn(t.s, t.low, t.high); t.want != got {
- println("#", i, " ", t.s, "[", t.low, ":", t.high, "] = ", got, " want ", t.want)
- failed = true
+ for i, test := range tests {
+ if got := test.fn(test.s, test.low, test.high); test.want != got {
+ t.Errorf("#%d %s[%d,%d] = %s, want %s", i, test.s, test.low, test.high, got, test.want)
}
}
}
}
//go:noinline
-func testStructSlice() {
+func testStructSlice(t *testing.T) {
p := &prefix{"prefix"}
p.slice_ssa()
if "pre" != p.prefix {
- println("wrong field slice: wanted %s got %s", "pre", p.prefix)
- failed = true
+ t.Errorf("wrong field slice: wanted %s got %s", "pre", p.prefix)
}
}
-func testStringSlicePanic() {
+func testStringSlicePanic(t *testing.T) {
defer func() {
if r := recover(); r != nil {
- println("panicked as expected")
+ //println("panicked as expected")
}
}()
str := "foobar"
- println("got ", testStringSlice12_ssa(str, 3, 9))
- println("expected to panic, but didn't")
- failed = true
+ t.Errorf("got %s and expected to panic, but didn't", testStringSlice12_ssa(str, 3, 9))
}
const _Accuracy_name = "BelowExactAbove"
return _Accuracy_name[_Accuracy_index[i]:_Accuracy_index[i+1]]
}
-func testSmallIndexType() {
+func testSmallIndexType(t *testing.T) {
tests := []struct {
i int
want string
{2, "Above"},
}
- for i, t := range tests {
- if got := testSmallIndexType_ssa(t.i); got != t.want {
- println("#", i, "got ", got, ", wanted", t.want)
- failed = true
+ for i, test := range tests {
+ if got := testSmallIndexType_ssa(test.i); got != test.want {
+ t.Errorf("#%d got %s wanted %s", i, got, test.want)
}
}
}
return s[i:j]
}
-func testInt64Index() {
+func testInt64Index(t *testing.T) {
tests := []struct {
i int64
j int64
}
str := "BelowExactAbove"
- for i, t := range tests {
- if got := testInt64Index_ssa(str, t.i); got != t.b {
- println("#", i, "got ", got, ", wanted", t.b)
- failed = true
+ for i, test := range tests {
+ if got := testInt64Index_ssa(str, test.i); got != test.b {
+ t.Errorf("#%d got %d wanted %d", i, got, test.b)
}
- if got := testInt64Slice_ssa(str, t.i, t.j); got != t.s {
- println("#", i, "got ", got, ", wanted", t.s)
- failed = true
+ if got := testInt64Slice_ssa(str, test.i, test.j); got != test.s {
+ t.Errorf("#%d got %s wanted %s", i, got, test.s)
}
}
}
-func testInt64IndexPanic() {
+func testInt64IndexPanic(t *testing.T) {
defer func() {
if r := recover(); r != nil {
- println("panicked as expected")
+ //println("panicked as expected")
}
}()
str := "foobar"
- println("got ", testInt64Index_ssa(str, 1<<32+1))
- println("expected to panic, but didn't")
- failed = true
+ t.Errorf("got %d and expected to panic, but didn't", testInt64Index_ssa(str, 1<<32+1))
}
-func testInt64SlicePanic() {
+func testInt64SlicePanic(t *testing.T) {
defer func() {
if r := recover(); r != nil {
- println("panicked as expected")
+ //println("panicked as expected")
}
}()
str := "foobar"
- println("got ", testInt64Slice_ssa(str, 1<<32, 1<<32+1))
- println("expected to panic, but didn't")
- failed = true
+ t.Errorf("got %s and expected to panic, but didn't", testInt64Slice_ssa(str, 1<<32, 1<<32+1))
}
//go:noinline
return s[i]
}
-func testStringElem() {
+func testStringElem(t *testing.T) {
tests := []struct {
s string
i int
{"foobar", 0, 102},
{"foobar", 5, 114},
}
- for _, t := range tests {
- if got := testStringElem_ssa(t.s, t.i); got != t.n {
- print("testStringElem \"", t.s, "\"[", t.i, "]=", got, ", wanted ", t.n, "\n")
- failed = true
+ for _, test := range tests {
+ if got := testStringElem_ssa(test.s, test.i); got != test.n {
+ t.Errorf("testStringElem \"%s\"[%d] = %d, wanted %d", test.s, test.i, got, test.n)
}
}
}
return s[i]
}
-func testStringElemConst() {
+func testStringElemConst(t *testing.T) {
if got := testStringElemConst_ssa(3); got != 98 {
- println("testStringElemConst=", got, ", wanted 98")
- failed = true
+ t.Errorf("testStringElemConst= %d, wanted 98", got)
}
}
-func main() {
- testStringSlice()
- testStringSlicePanic()
- testStructSlice()
- testSmallIndexType()
- testStringElem()
- testStringElemConst()
- testInt64Index()
- testInt64IndexPanic()
- testInt64SlicePanic()
-
- if failed {
- panic("failed")
- }
+func TestString(t *testing.T) {
+ testStringSlice(t)
+ testStringSlicePanic(t)
+ testStructSlice(t)
+ testSmallIndexType(t)
+ testStringElem(t)
+ testStringElemConst(t)
+ testInt64Index(t)
+ testInt64IndexPanic(t)
+ testInt64SlicePanic(t)
}