Skip to content

Commit 25ea4e5

Browse files
committed
cmd/compile: move more compiler tests to new test infrastructure
Update #26469 Change-Id: I1188e49cde1bda11506afef6b6e3f34c6ff45ea5 Reviewed-on: https://go-review.googlesource.com/127115 Run-TryBot: Keith Randall <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent 78ce3a0 commit 25ea4e5

File tree

10 files changed

+155
-249
lines changed

10 files changed

+155
-249
lines changed

src/cmd/compile/internal/gc/ssa_test.go

-20
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ func runTest(t *testing.T, filename string, flags ...string) {
2626
t.Parallel()
2727
doTest(t, filename, "run", flags...)
2828
}
29-
func buildTest(t *testing.T, filename string, flags ...string) {
30-
t.Parallel()
31-
doTest(t, filename, "build", flags...)
32-
}
3329
func doTest(t *testing.T, filename string, kind string, flags ...string) {
3430
testenv.MustHaveGoBuild(t)
3531
gotool := testenv.GoToolPath(t)
@@ -227,22 +223,6 @@ func TestCode(t *testing.T) {
227223
}
228224
}
229225

230-
func TestChan(t *testing.T) { runTest(t, "chan.go") }
231-
232-
func TestCompound(t *testing.T) { runTest(t, "compound.go") }
233-
234-
func TestCtl(t *testing.T) { runTest(t, "ctl.go") }
235-
236-
func TestLoadStore(t *testing.T) { runTest(t, "loadstore.go") }
237-
238-
func TestMap(t *testing.T) { runTest(t, "map.go") }
239-
240-
func TestRegalloc(t *testing.T) { runTest(t, "regalloc.go") }
241-
242-
func TestString(t *testing.T) { runTest(t, "string.go") }
243-
244-
func TestDeferNoReturn(t *testing.T) { buildTest(t, "deferNoReturn.go") }
245-
246226
// TestClosure tests closure related behavior.
247227
func TestClosure(t *testing.T) { runTest(t, "closure.go") }
248228

src/cmd/compile/internal/gc/testdata/chan.go renamed to src/cmd/compile/internal/gc/testdata/chan_test.go

+15-25
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// chan_ssa.go tests chan operations.
5+
// chan.go tests chan operations.
66
package main
77

8-
import "fmt"
9-
10-
var failed = false
8+
import "testing"
119

1210
//go:noinline
1311
func lenChan_ssa(v chan int) int {
@@ -19,55 +17,47 @@ func capChan_ssa(v chan int) int {
1917
return cap(v)
2018
}
2119

22-
func testLenChan() {
20+
func testLenChan(t *testing.T) {
2321

2422
v := make(chan int, 10)
2523
v <- 1
2624
v <- 1
2725
v <- 1
2826

2927
if want, got := 3, lenChan_ssa(v); got != want {
30-
fmt.Printf("expected len(chan) = %d, got %d", want, got)
31-
failed = true
28+
t.Errorf("expected len(chan) = %d, got %d", want, got)
3229
}
3330
}
3431

35-
func testLenNilChan() {
32+
func testLenNilChan(t *testing.T) {
3633

3734
var v chan int
3835
if want, got := 0, lenChan_ssa(v); got != want {
39-
fmt.Printf("expected len(nil) = %d, got %d", want, got)
40-
failed = true
36+
t.Errorf("expected len(nil) = %d, got %d", want, got)
4137
}
4238
}
4339

44-
func testCapChan() {
40+
func testCapChan(t *testing.T) {
4541

4642
v := make(chan int, 25)
4743

4844
if want, got := 25, capChan_ssa(v); got != want {
49-
fmt.Printf("expected cap(chan) = %d, got %d", want, got)
50-
failed = true
45+
t.Errorf("expected cap(chan) = %d, got %d", want, got)
5146
}
5247
}
5348

54-
func testCapNilChan() {
49+
func testCapNilChan(t *testing.T) {
5550

5651
var v chan int
5752
if want, got := 0, capChan_ssa(v); got != want {
58-
fmt.Printf("expected cap(nil) = %d, got %d", want, got)
59-
failed = true
53+
t.Errorf("expected cap(nil) = %d, got %d", want, got)
6054
}
6155
}
6256

63-
func main() {
64-
testLenChan()
65-
testLenNilChan()
66-
67-
testCapChan()
68-
testCapNilChan()
57+
func TestChan(t *testing.T) {
58+
testLenChan(t)
59+
testLenNilChan(t)
6960

70-
if failed {
71-
panic("failed")
72-
}
61+
testCapChan(t)
62+
testCapNilChan(t)
7363
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// run
2-
31
// Copyright 2015 The Go Authors. All rights reserved.
42
// Use of this source code is governed by a BSD-style
53
// license that can be found in the LICENSE file.
@@ -8,7 +6,9 @@
86

97
package main
108

11-
import "fmt"
9+
import (
10+
"testing"
11+
)
1212

1313
func string_ssa(a, b string, x bool) string {
1414
s := ""
@@ -20,16 +20,14 @@ func string_ssa(a, b string, x bool) string {
2020
return s
2121
}
2222

23-
func testString() {
23+
func testString(t *testing.T) {
2424
a := "foo"
2525
b := "barz"
2626
if want, got := a, string_ssa(a, b, true); got != want {
27-
fmt.Printf("string_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
28-
failed = true
27+
t.Errorf("string_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
2928
}
3029
if want, got := b, string_ssa(a, b, false); got != want {
31-
fmt.Printf("string_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want)
32-
failed = true
30+
t.Errorf("string_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want)
3331
}
3432
}
3533

@@ -55,31 +53,27 @@ func complex128_ssa(a, b complex128, x bool) complex128 {
5553
return c
5654
}
5755

58-
func testComplex64() {
56+
func testComplex64(t *testing.T) {
5957
var a complex64 = 1 + 2i
6058
var b complex64 = 3 + 4i
6159

6260
if want, got := a, complex64_ssa(a, b, true); got != want {
63-
fmt.Printf("complex64_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
64-
failed = true
61+
t.Errorf("complex64_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
6562
}
6663
if want, got := b, complex64_ssa(a, b, false); got != want {
67-
fmt.Printf("complex64_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
68-
failed = true
64+
t.Errorf("complex64_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
6965
}
7066
}
7167

72-
func testComplex128() {
68+
func testComplex128(t *testing.T) {
7369
var a complex128 = 1 + 2i
7470
var b complex128 = 3 + 4i
7571

7672
if want, got := a, complex128_ssa(a, b, true); got != want {
77-
fmt.Printf("complex128_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
78-
failed = true
73+
t.Errorf("complex128_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
7974
}
8075
if want, got := b, complex128_ssa(a, b, false); got != want {
81-
fmt.Printf("complex128_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
82-
failed = true
76+
t.Errorf("complex128_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
8377
}
8478
}
8579

@@ -93,16 +87,14 @@ func slice_ssa(a, b []byte, x bool) []byte {
9387
return s
9488
}
9589

96-
func testSlice() {
90+
func testSlice(t *testing.T) {
9791
a := []byte{3, 4, 5}
9892
b := []byte{7, 8, 9}
9993
if want, got := byte(3), slice_ssa(a, b, true)[0]; got != want {
100-
fmt.Printf("slice_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
101-
failed = true
94+
t.Errorf("slice_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
10295
}
10396
if want, got := byte(7), slice_ssa(a, b, false)[0]; got != want {
104-
fmt.Printf("slice_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want)
105-
failed = true
97+
t.Errorf("slice_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want)
10698
}
10799
}
108100

@@ -116,28 +108,21 @@ func interface_ssa(a, b interface{}, x bool) interface{} {
116108
return s
117109
}
118110

119-
func testInterface() {
111+
func testInterface(t *testing.T) {
120112
a := interface{}(3)
121113
b := interface{}(4)
122114
if want, got := 3, interface_ssa(a, b, true).(int); got != want {
123-
fmt.Printf("interface_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
124-
failed = true
115+
t.Errorf("interface_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)
125116
}
126117
if want, got := 4, interface_ssa(a, b, false).(int); got != want {
127-
fmt.Printf("interface_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want)
128-
failed = true
118+
t.Errorf("interface_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want)
129119
}
130120
}
131121

132-
var failed = false
133-
134-
func main() {
135-
testString()
136-
testSlice()
137-
testInterface()
138-
testComplex64()
139-
testComplex128()
140-
if failed {
141-
panic("failed")
142-
}
122+
func TestCompound(t *testing.T) {
123+
testString(t)
124+
testSlice(t)
125+
testInterface(t)
126+
testComplex64(t)
127+
testComplex128(t)
143128
}

src/cmd/compile/internal/gc/testdata/ctl.go renamed to src/cmd/compile/internal/gc/testdata/ctl_test.go

+18-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// run
2-
31
// Copyright 2015 The Go Authors. All rights reserved.
42
// Use of this source code is governed by a BSD-style
53
// license that can be found in the LICENSE file.
@@ -8,6 +6,8 @@
86

97
package main
108

9+
import "testing"
10+
1111
// nor_ssa calculates NOR(a, b).
1212
// It is implemented in a way that generates
1313
// phi control values.
@@ -25,7 +25,7 @@ func nor_ssa(a, b bool) bool {
2525
return true
2626
}
2727

28-
func testPhiControl() {
28+
func testPhiControl(t *testing.T) {
2929
tests := [...][3]bool{ // a, b, want
3030
{false, false, true},
3131
{true, false, false},
@@ -37,8 +37,7 @@ func testPhiControl() {
3737
got := nor_ssa(a, b)
3838
want := test[2]
3939
if want != got {
40-
print("nor(", a, ", ", b, ")=", want, " got ", got, "\n")
41-
failed = true
40+
t.Errorf("nor(%t, %t)=%t got %t", a, b, want, got)
4241
}
4342
}
4443
}
@@ -50,10 +49,9 @@ func emptyRange_ssa(b []byte) bool {
5049
return true
5150
}
5251

53-
func testEmptyRange() {
52+
func testEmptyRange(t *testing.T) {
5453
if !emptyRange_ssa([]byte{}) {
55-
println("emptyRange_ssa([]byte{})=false, want true")
56-
failed = true
54+
t.Errorf("emptyRange_ssa([]byte{})=false, want true")
5755
}
5856
}
5957

@@ -97,20 +95,18 @@ func fallthrough_ssa(a int) int {
9795

9896
}
9997

100-
func testFallthrough() {
98+
func testFallthrough(t *testing.T) {
10199
for i := 0; i < 6; i++ {
102100
if got := fallthrough_ssa(i); got != i {
103-
println("fallthrough_ssa(i) =", got, "wanted", i)
104-
failed = true
101+
t.Errorf("fallthrough_ssa(i) = %d, wanted %d", got, i)
105102
}
106103
}
107104
}
108105

109-
func testSwitch() {
106+
func testSwitch(t *testing.T) {
110107
for i := 0; i < 6; i++ {
111108
if got := switch_ssa(i); got != i {
112-
println("switch_ssa(i) =", got, "wanted", i)
113-
failed = true
109+
t.Errorf("switch_ssa(i) = %d, wanted %d", got, i)
114110
}
115111
}
116112
}
@@ -135,26 +131,19 @@ func flagOverwrite_ssa(s *junk, c int) int {
135131
return 3
136132
}
137133

138-
func testFlagOverwrite() {
134+
func testFlagOverwrite(t *testing.T) {
139135
j := junk{}
140136
if got := flagOverwrite_ssa(&j, ' '); got != 3 {
141-
println("flagOverwrite_ssa =", got, "wanted 3")
142-
failed = true
137+
t.Errorf("flagOverwrite_ssa = %d, wanted 3", got)
143138
}
144139
}
145140

146-
var failed = false
147-
148-
func main() {
149-
testPhiControl()
150-
testEmptyRange()
141+
func TestCtl(t *testing.T) {
142+
testPhiControl(t)
143+
testEmptyRange(t)
151144

152-
testSwitch()
153-
testFallthrough()
145+
testSwitch(t)
146+
testFallthrough(t)
154147

155-
testFlagOverwrite()
156-
157-
if failed {
158-
panic("failed")
159-
}
148+
testFlagOverwrite(t)
160149
}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
// compile
2-
31
// Copyright 2015 The Go Authors. All rights reserved.
42
// Use of this source code is governed by a BSD-style
53
// license that can be found in the LICENSE file.
64

75
// Test that a defer in a function with no return
86
// statement will compile correctly.
97

10-
package foo
8+
package main
9+
10+
import "testing"
1111

1212
func deferNoReturn_ssa() {
1313
defer func() { println("returned") }()
1414
for {
1515
println("loop")
1616
}
1717
}
18+
19+
func TestDeferNoReturn(t *testing.T) {
20+
// This is a compile-time test, no runtime testing required.
21+
}

0 commit comments

Comments
 (0)