github.com/rakyll/go@v0.0.0-20170216000551-64c02460d703/src/cmd/compile/internal/gc/ssa_test.go (about) 1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package gc 6 7 import ( 8 "bytes" 9 "internal/testenv" 10 "os/exec" 11 "path/filepath" 12 "strings" 13 "testing" 14 ) 15 16 // TODO: move all these tests elsewhere? 17 // Perhaps teach test/run.go how to run them with a new action verb. 18 func runTest(t *testing.T, filename string) { 19 t.Parallel() 20 doTest(t, filename, "run") 21 } 22 func buildTest(t *testing.T, filename string) { 23 t.Parallel() 24 doTest(t, filename, "build") 25 } 26 func doTest(t *testing.T, filename string, kind string) { 27 testenv.MustHaveGoBuild(t) 28 var stdout, stderr bytes.Buffer 29 cmd := exec.Command(testenv.GoToolPath(t), kind, filepath.Join("testdata", filename)) 30 cmd.Stdout = &stdout 31 cmd.Stderr = &stderr 32 if err := cmd.Run(); err != nil { 33 t.Fatalf("Failed: %v:\nOut: %s\nStderr: %s\n", err, &stdout, &stderr) 34 } 35 if s := stdout.String(); s != "" { 36 t.Errorf("Stdout = %s\nWant empty", s) 37 } 38 if s := stderr.String(); strings.Contains(s, "SSA unimplemented") { 39 t.Errorf("Unimplemented message found in stderr:\n%s", s) 40 } 41 } 42 43 // TestShortCircuit tests OANDAND and OOROR expressions and short circuiting. 44 func TestShortCircuit(t *testing.T) { runTest(t, "short.go") } 45 46 // TestBreakContinue tests that continue and break statements do what they say. 47 func TestBreakContinue(t *testing.T) { runTest(t, "break.go") } 48 49 // TestTypeAssertion tests type assertions. 50 func TestTypeAssertion(t *testing.T) { runTest(t, "assert.go") } 51 52 // TestArithmetic tests that both backends have the same result for arithmetic expressions. 53 func TestArithmetic(t *testing.T) { runTest(t, "arith.go") } 54 55 // TestFP tests that both backends have the same result for floating point expressions. 56 func TestFP(t *testing.T) { runTest(t, "fp.go") } 57 58 // TestArithmeticBoundary tests boundary results for arithmetic operations. 59 func TestArithmeticBoundary(t *testing.T) { runTest(t, "arithBoundary.go") } 60 61 // TestArithmeticConst tests results for arithmetic operations against constants. 62 func TestArithmeticConst(t *testing.T) { runTest(t, "arithConst.go") } 63 64 func TestChan(t *testing.T) { runTest(t, "chan.go") } 65 66 func TestCompound(t *testing.T) { runTest(t, "compound.go") } 67 68 func TestCtl(t *testing.T) { runTest(t, "ctl.go") } 69 70 func TestLoadStore(t *testing.T) { runTest(t, "loadstore.go") } 71 72 func TestMap(t *testing.T) { runTest(t, "map.go") } 73 74 func TestRegalloc(t *testing.T) { runTest(t, "regalloc.go") } 75 76 func TestString(t *testing.T) { runTest(t, "string.go") } 77 78 func TestDeferNoReturn(t *testing.T) { buildTest(t, "deferNoReturn.go") } 79 80 // TestClosure tests closure related behavior. 81 func TestClosure(t *testing.T) { runTest(t, "closure.go") } 82 83 func TestArray(t *testing.T) { runTest(t, "array.go") } 84 85 func TestAppend(t *testing.T) { runTest(t, "append.go") } 86 87 func TestZero(t *testing.T) { runTest(t, "zero.go") } 88 89 func TestAddressed(t *testing.T) { runTest(t, "addressed.go") } 90 91 func TestCopy(t *testing.T) { runTest(t, "copy.go") } 92 93 func TestUnsafe(t *testing.T) { runTest(t, "unsafe.go") } 94 95 func TestPhi(t *testing.T) { runTest(t, "phi.go") } 96 97 func TestSlice(t *testing.T) { runTest(t, "slice.go") } 98 99 func TestNamedReturn(t *testing.T) { runTest(t, "namedReturn.go") } 100 101 func TestDuplicateLoad(t *testing.T) { runTest(t, "dupLoad.go") } 102 103 func TestSqrt(t *testing.T) { runTest(t, "sqrt_const.go") }