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: default avatarDavid Chase <drchase@google.com>
parent 45e7e668
...@@ -227,19 +227,6 @@ func TestCode(t *testing.T) { ...@@ -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. // TestArithmeticBoundary tests boundary results for arithmetic operations.
func TestArithmeticBoundary(t *testing.T) { runTest(t, "arithBoundary.go") } func TestArithmeticBoundary(t *testing.T) { runTest(t, "arithBoundary.go") }
......
// run
// Copyright 2015 The Go Authors. All rights reserved. // Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
...@@ -9,13 +7,13 @@ ...@@ -9,13 +7,13 @@
package main package main
import ( import (
"fmt"
"runtime" "runtime"
"testing"
) )
type ( type (
S struct{} S struct{}
T struct{} U struct{}
I interface { I interface {
F() F()
...@@ -24,124 +22,107 @@ type ( ...@@ -24,124 +22,107 @@ type (
var ( var (
s *S s *S
t *T u *U
) )
func (s *S) F() {} func (s *S) F() {}
func (t *T) F() {} func (u *U) F() {}
func e2t_ssa(e interface{}) *T { func e2t_ssa(e interface{}) *U {
return e.(*T) return e.(*U)
} }
func i2t_ssa(i I) *T { func i2t_ssa(i I) *U {
return i.(*T) return i.(*U)
} }
func testAssertE2TOk() { func testAssertE2TOk(t *testing.T) {
if got := e2t_ssa(t); got != t { if got := e2t_ssa(u); got != u {
fmt.Printf("e2t_ssa(t)=%v want %v", got, t) t.Errorf("e2t_ssa(u)=%v want %v", got, u)
failed = true
} }
} }
func testAssertE2TPanic() { func testAssertE2TPanic(t *testing.T) {
var got *T var got *U
defer func() { defer func() {
if got != nil { if got != nil {
fmt.Printf("e2t_ssa(s)=%v want nil", got) t.Errorf("e2t_ssa(s)=%v want nil", got)
failed = true
} }
e := recover() e := recover()
err, ok := e.(*runtime.TypeAssertionError) err, ok := e.(*runtime.TypeAssertionError)
if !ok { if !ok {
fmt.Printf("e2t_ssa(s) panic type %T", e) t.Errorf("e2t_ssa(s) panic type %T", e)
failed = true
} }
want := "interface conversion: interface {} is *main.S, not *main.T" want := "interface conversion: interface {} is *main.S, not *main.U"
if err.Error() != want { if err.Error() != want {
fmt.Printf("e2t_ssa(s) wrong error, want '%s', got '%s'\n", want, err.Error()) t.Errorf("e2t_ssa(s) wrong error, want '%s', got '%s'", want, err.Error())
failed = true
} }
}() }()
got = e2t_ssa(s) got = e2t_ssa(s)
fmt.Printf("e2t_ssa(s) should panic") t.Errorf("e2t_ssa(s) should panic")
failed = true
} }
func testAssertI2TOk() { func testAssertI2TOk(t *testing.T) {
if got := i2t_ssa(t); got != t { if got := i2t_ssa(u); got != u {
fmt.Printf("i2t_ssa(t)=%v want %v", got, t) t.Errorf("i2t_ssa(u)=%v want %v", got, u)
failed = true
} }
} }
func testAssertI2TPanic() { func testAssertI2TPanic(t *testing.T) {
var got *T var got *U
defer func() { defer func() {
if got != nil { if got != nil {
fmt.Printf("i2t_ssa(s)=%v want nil", got) t.Errorf("i2t_ssa(s)=%v want nil", got)
failed = true
} }
e := recover() e := recover()
err, ok := e.(*runtime.TypeAssertionError) err, ok := e.(*runtime.TypeAssertionError)
if !ok { if !ok {
fmt.Printf("i2t_ssa(s) panic type %T", e) t.Errorf("i2t_ssa(s) panic type %T", e)
failed = true
} }
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 { if err.Error() != want {
fmt.Printf("i2t_ssa(s) wrong error, want '%s', got '%s'\n", want, err.Error()) t.Errorf("i2t_ssa(s) wrong error, want '%s', got '%s'", want, err.Error())
failed = true
} }
}() }()
got = i2t_ssa(s) got = i2t_ssa(s)
fmt.Printf("i2t_ssa(s) should panic") t.Errorf("i2t_ssa(s) should panic")
failed = true
} }
func e2t2_ssa(e interface{}) (*T, bool) { func e2t2_ssa(e interface{}) (*U, bool) {
t, ok := e.(*T) u, ok := e.(*U)
return t, ok return u, ok
} }
func i2t2_ssa(i I) (*T, bool) { func i2t2_ssa(i I) (*U, bool) {
t, ok := i.(*T) u, ok := i.(*U)
return t, ok return u, ok
} }
func testAssertE2T2() { func testAssertE2T2(t *testing.T) {
if got, ok := e2t2_ssa(t); !ok || got != t { if got, ok := e2t2_ssa(u); !ok || got != u {
fmt.Printf("e2t2_ssa(t)=(%v, %v) want (%v, %v)", got, ok, t, true) t.Errorf("e2t2_ssa(u)=(%v, %v) want (%v, %v)", got, ok, u, true)
failed = true
} }
if got, ok := e2t2_ssa(s); ok || got != nil { if got, ok := e2t2_ssa(s); ok || got != nil {
fmt.Printf("e2t2_ssa(s)=(%v, %v) want (%v, %v)", got, ok, nil, false) t.Errorf("e2t2_ssa(s)=(%v, %v) want (%v, %v)", got, ok, nil, false)
failed = true
} }
} }
func testAssertI2T2() { func testAssertI2T2(t *testing.T) {
if got, ok := i2t2_ssa(t); !ok || got != t { if got, ok := i2t2_ssa(u); !ok || got != u {
fmt.Printf("i2t2_ssa(t)=(%v, %v) want (%v, %v)", got, ok, t, true) t.Errorf("i2t2_ssa(u)=(%v, %v) want (%v, %v)", got, ok, u, true)
failed = true
} }
if got, ok := i2t2_ssa(s); ok || got != nil { if got, ok := i2t2_ssa(s); ok || got != nil {
fmt.Printf("i2t2_ssa(s)=(%v, %v) want (%v, %v)", got, ok, nil, false) t.Errorf("i2t2_ssa(s)=(%v, %v) want (%v, %v)", got, ok, nil, false)
failed = true
} }
} }
var failed = false // TestTypeAssertion tests type assertions.
func TestTypeAssertion(t *testing.T) {
func main() { testAssertE2TOk(t)
testAssertE2TOk() testAssertE2TPanic(t)
testAssertE2TPanic() testAssertI2TOk(t)
testAssertI2TOk() testAssertI2TPanic(t)
testAssertI2TPanic() testAssertE2T2(t)
testAssertE2T2() testAssertI2T2(t)
testAssertI2T2()
if failed {
panic("failed")
}
} }
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