Commit ed21535a authored by Keith Randall's avatar Keith Randall Committed by Keith Randall

cmd/compile: move over more compiler tests to new test infrastructure

R=go1.12

Update #26469

Change-Id: Iad75edfc194f8391a8ead09bfa68d446155e84ac
Reviewed-on: https://go-review.googlesource.com/127055
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarDavid Chase <drchase@google.com>
parent 45e7e668
......@@ -227,19 +227,6 @@ func TestCode(t *testing.T) {
}
}
// TestTypeAssertion tests type assertions.
func TestTypeAssertion(t *testing.T) { runTest(t, "assert.go") }
// TestArithmetic tests that both backends have the same result for arithmetic expressions.
func TestArithmetic(t *testing.T) { runTest(t, "arith.go") }
// TestFP tests that both backends have the same result for floating point expressions.
func TestFP(t *testing.T) { runTest(t, "fp.go") }
func TestFPSoftFloat(t *testing.T) {
runTest(t, "fp.go", "-gcflags=-d=softfloat,ssa/check/on")
}
// TestArithmeticBoundary tests boundary results for arithmetic operations.
func TestArithmeticBoundary(t *testing.T) { runTest(t, "arithBoundary.go") }
......
// 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.
......@@ -9,13 +7,13 @@
package main
import (
"fmt"
"runtime"
"testing"
)
type (
S struct{}
T struct{}
U struct{}
I interface {
F()
......@@ -24,124 +22,107 @@ type (
var (
s *S
t *T
u *U
)
func (s *S) F() {}
func (t *T) F() {}
func (u *U) F() {}
func e2t_ssa(e interface{}) *T {
return e.(*T)
func e2t_ssa(e interface{}) *U {
return e.(*U)
}
func i2t_ssa(i I) *T {
return i.(*T)
func i2t_ssa(i I) *U {
return i.(*U)
}
func testAssertE2TOk() {
if got := e2t_ssa(t); got != t {
fmt.Printf("e2t_ssa(t)=%v want %v", got, t)
failed = true
func testAssertE2TOk(t *testing.T) {
if got := e2t_ssa(u); got != u {
t.Errorf("e2t_ssa(u)=%v want %v", got, u)
}
}
func testAssertE2TPanic() {
var got *T
func testAssertE2TPanic(t *testing.T) {
var got *U
defer func() {
if got != nil {
fmt.Printf("e2t_ssa(s)=%v want nil", got)
failed = true
t.Errorf("e2t_ssa(s)=%v want nil", got)
}
e := recover()
err, ok := e.(*runtime.TypeAssertionError)
if !ok {
fmt.Printf("e2t_ssa(s) panic type %T", e)
failed = true
t.Errorf("e2t_ssa(s) panic type %T", e)
}
want := "interface conversion: interface {} is *main.S, not *main.T"
want := "interface conversion: interface {} is *main.S, not *main.U"
if err.Error() != want {
fmt.Printf("e2t_ssa(s) wrong error, want '%s', got '%s'\n", want, err.Error())
failed = true
t.Errorf("e2t_ssa(s) wrong error, want '%s', got '%s'", want, err.Error())
}
}()
got = e2t_ssa(s)
fmt.Printf("e2t_ssa(s) should panic")
failed = true
t.Errorf("e2t_ssa(s) should panic")
}
func testAssertI2TOk() {
if got := i2t_ssa(t); got != t {
fmt.Printf("i2t_ssa(t)=%v want %v", got, t)
failed = true
func testAssertI2TOk(t *testing.T) {
if got := i2t_ssa(u); got != u {
t.Errorf("i2t_ssa(u)=%v want %v", got, u)
}
}
func testAssertI2TPanic() {
var got *T
func testAssertI2TPanic(t *testing.T) {
var got *U
defer func() {
if got != nil {
fmt.Printf("i2t_ssa(s)=%v want nil", got)
failed = true
t.Errorf("i2t_ssa(s)=%v want nil", got)
}
e := recover()
err, ok := e.(*runtime.TypeAssertionError)
if !ok {
fmt.Printf("i2t_ssa(s) panic type %T", e)
failed = true
t.Errorf("i2t_ssa(s) panic type %T", e)
}
want := "interface conversion: main.I is *main.S, not *main.T"
want := "interface conversion: main.I is *main.S, not *main.U"
if err.Error() != want {
fmt.Printf("i2t_ssa(s) wrong error, want '%s', got '%s'\n", want, err.Error())
failed = true
t.Errorf("i2t_ssa(s) wrong error, want '%s', got '%s'", want, err.Error())
}
}()
got = i2t_ssa(s)
fmt.Printf("i2t_ssa(s) should panic")
failed = true
t.Errorf("i2t_ssa(s) should panic")
}
func e2t2_ssa(e interface{}) (*T, bool) {
t, ok := e.(*T)
return t, ok
func e2t2_ssa(e interface{}) (*U, bool) {
u, ok := e.(*U)
return u, ok
}
func i2t2_ssa(i I) (*T, bool) {
t, ok := i.(*T)
return t, ok
func i2t2_ssa(i I) (*U, bool) {
u, ok := i.(*U)
return u, ok
}
func testAssertE2T2() {
if got, ok := e2t2_ssa(t); !ok || got != t {
fmt.Printf("e2t2_ssa(t)=(%v, %v) want (%v, %v)", got, ok, t, true)
failed = true
func testAssertE2T2(t *testing.T) {
if got, ok := e2t2_ssa(u); !ok || got != u {
t.Errorf("e2t2_ssa(u)=(%v, %v) want (%v, %v)", got, ok, u, true)
}
if got, ok := e2t2_ssa(s); ok || got != nil {
fmt.Printf("e2t2_ssa(s)=(%v, %v) want (%v, %v)", got, ok, nil, false)
failed = true
t.Errorf("e2t2_ssa(s)=(%v, %v) want (%v, %v)", got, ok, nil, false)
}
}
func testAssertI2T2() {
if got, ok := i2t2_ssa(t); !ok || got != t {
fmt.Printf("i2t2_ssa(t)=(%v, %v) want (%v, %v)", got, ok, t, true)
failed = true
func testAssertI2T2(t *testing.T) {
if got, ok := i2t2_ssa(u); !ok || got != u {
t.Errorf("i2t2_ssa(u)=(%v, %v) want (%v, %v)", got, ok, u, true)
}
if got, ok := i2t2_ssa(s); ok || got != nil {
fmt.Printf("i2t2_ssa(s)=(%v, %v) want (%v, %v)", got, ok, nil, false)
failed = true
t.Errorf("i2t2_ssa(s)=(%v, %v) want (%v, %v)", got, ok, nil, false)
}
}
var failed = false
func main() {
testAssertE2TOk()
testAssertE2TPanic()
testAssertI2TOk()
testAssertI2TPanic()
testAssertE2T2()
testAssertI2T2()
if failed {
panic("failed")
}
// TestTypeAssertion tests type assertions.
func TestTypeAssertion(t *testing.T) {
testAssertE2TOk(t)
testAssertE2TPanic(t)
testAssertI2TOk(t)
testAssertI2TPanic(t)
testAssertE2T2(t)
testAssertI2T2(t)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment