github.com/sanprasirt/go@v0.0.0-20170607001320-a027466e4b6d/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 // TestComparisonsConst tests results for comparison operations against constants. 67 func TestComparisonsConst(t *testing.T) { runTest(t, "cmpConst.go") } 68 69 func TestCompound(t *testing.T) { runTest(t, "compound.go") } 70 71 func TestCtl(t *testing.T) { runTest(t, "ctl.go") } 72 73 func TestLoadStore(t *testing.T) { runTest(t, "loadstore.go") } 74 75 func TestMap(t *testing.T) { runTest(t, "map.go") } 76 77 func TestRegalloc(t *testing.T) { runTest(t, "regalloc.go") } 78 79 func TestString(t *testing.T) { runTest(t, "string.go") } 80 81 func TestDeferNoReturn(t *testing.T) { buildTest(t, "deferNoReturn.go") } 82 83 // TestClosure tests closure related behavior. 84 func TestClosure(t *testing.T) { runTest(t, "closure.go") } 85 86 func TestArray(t *testing.T) { runTest(t, "array.go") } 87 88 func TestAppend(t *testing.T) { runTest(t, "append.go") } 89 90 func TestZero(t *testing.T) { runTest(t, "zero.go") } 91 92 func TestAddressed(t *testing.T) { runTest(t, "addressed.go") } 93 94 func TestCopy(t *testing.T) { runTest(t, "copy.go") } 95 96 func TestUnsafe(t *testing.T) { runTest(t, "unsafe.go") } 97 98 func TestPhi(t *testing.T) { runTest(t, "phi.go") } 99 100 func TestSlice(t *testing.T) { runTest(t, "slice.go") } 101 102 func TestNamedReturn(t *testing.T) { runTest(t, "namedReturn.go") } 103 104 func TestDuplicateLoad(t *testing.T) { runTest(t, "dupLoad.go") } 105 106 func TestSqrt(t *testing.T) { runTest(t, "sqrt_const.go") }