github.com/dannin/go@v0.0.0-20161031215817-d35dfd405eaa/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  	doTest(t, filename, "run")
    20  }
    21  func buildTest(t *testing.T, filename string) {
    22  	doTest(t, filename, "build")
    23  }
    24  func doTest(t *testing.T, filename string, kind string) {
    25  	testenv.MustHaveGoBuild(t)
    26  	var stdout, stderr bytes.Buffer
    27  	cmd := exec.Command(testenv.GoToolPath(t), kind, filepath.Join("testdata", filename))
    28  	cmd.Stdout = &stdout
    29  	cmd.Stderr = &stderr
    30  	if err := cmd.Run(); err != nil {
    31  		t.Fatalf("Failed: %v:\nOut: %s\nStderr: %s\n", err, &stdout, &stderr)
    32  	}
    33  	if s := stdout.String(); s != "" {
    34  		t.Errorf("Stdout = %s\nWant empty", s)
    35  	}
    36  	if s := stderr.String(); strings.Contains(s, "SSA unimplemented") {
    37  		t.Errorf("Unimplemented message found in stderr:\n%s", s)
    38  	}
    39  }
    40  
    41  // TestShortCircuit tests OANDAND and OOROR expressions and short circuiting.
    42  func TestShortCircuit(t *testing.T) { runTest(t, "short.go") }
    43  
    44  // TestBreakContinue tests that continue and break statements do what they say.
    45  func TestBreakContinue(t *testing.T) { runTest(t, "break.go") }
    46  
    47  // TestTypeAssertion tests type assertions.
    48  func TestTypeAssertion(t *testing.T) { runTest(t, "assert.go") }
    49  
    50  // TestArithmetic tests that both backends have the same result for arithmetic expressions.
    51  func TestArithmetic(t *testing.T) { runTest(t, "arith.go") }
    52  
    53  // TestFP tests that both backends have the same result for floating point expressions.
    54  func TestFP(t *testing.T) { runTest(t, "fp.go") }
    55  
    56  // TestArithmeticBoundary tests boundary results for arithmetic operations.
    57  func TestArithmeticBoundary(t *testing.T) { runTest(t, "arithBoundary.go") }
    58  
    59  // TestArithmeticConst tests results for arithmetic operations against constants.
    60  func TestArithmeticConst(t *testing.T) { runTest(t, "arithConst.go") }
    61  
    62  func TestChan(t *testing.T) { runTest(t, "chan.go") }
    63  
    64  func TestCompound(t *testing.T) { runTest(t, "compound.go") }
    65  
    66  func TestCtl(t *testing.T) { runTest(t, "ctl.go") }
    67  
    68  func TestLoadStore(t *testing.T) { runTest(t, "loadstore.go") }
    69  
    70  func TestMap(t *testing.T) { runTest(t, "map.go") }
    71  
    72  func TestRegalloc(t *testing.T) { runTest(t, "regalloc.go") }
    73  
    74  func TestString(t *testing.T) { runTest(t, "string.go") }
    75  
    76  func TestDeferNoReturn(t *testing.T) { buildTest(t, "deferNoReturn.go") }
    77  
    78  // TestClosure tests closure related behavior.
    79  func TestClosure(t *testing.T) { runTest(t, "closure.go") }
    80  
    81  func TestArray(t *testing.T) { runTest(t, "array.go") }
    82  
    83  func TestAppend(t *testing.T) { runTest(t, "append.go") }
    84  
    85  func TestZero(t *testing.T) { runTest(t, "zero.go") }
    86  
    87  func TestAddressed(t *testing.T) { runTest(t, "addressed.go") }
    88  
    89  func TestCopy(t *testing.T) { runTest(t, "copy.go") }
    90  
    91  func TestUnsafe(t *testing.T) { runTest(t, "unsafe.go") }
    92  
    93  func TestPhi(t *testing.T) { runTest(t, "phi.go") }
    94  
    95  func TestSlice(t *testing.T) { runTest(t, "slice.go") }
    96  
    97  func TestNamedReturn(t *testing.T) { runTest(t, "namedReturn.go") }
    98  
    99  func TestDuplicateLoad(t *testing.T) { runTest(t, "dupLoad.go") }
   100  
   101  func TestSqrt(t *testing.T) { runTest(t, "sqrt_const.go") }