github.com/miolini/go@v0.0.0-20160405192216-fca68c8cb408/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  	"runtime"
    13  	"strings"
    14  	"testing"
    15  )
    16  
    17  // TODO: move all these tests elsewhere?
    18  // Perhaps teach test/run.go how to run them with a new action verb.
    19  func runTest(t *testing.T, filename string) {
    20  	doTest(t, filename, "run")
    21  }
    22  func buildTest(t *testing.T, filename string) {
    23  	doTest(t, filename, "build")
    24  }
    25  func doTest(t *testing.T, filename string, kind string) {
    26  	if runtime.GOARCH != "amd64" {
    27  		t.Skipf("skipping SSA tests on %s for now", runtime.GOARCH)
    28  	}
    29  	testenv.MustHaveGoBuild(t)
    30  	var stdout, stderr bytes.Buffer
    31  	cmd := exec.Command("go", kind, filepath.Join("testdata", filename))
    32  	cmd.Stdout = &stdout
    33  	cmd.Stderr = &stderr
    34  	if err := cmd.Run(); err != nil {
    35  		t.Fatalf("Failed: %v:\nOut: %s\nStderr: %s\n", err, &stdout, &stderr)
    36  	}
    37  	if s := stdout.String(); s != "" {
    38  		t.Errorf("Stdout = %s\nWant empty", s)
    39  	}
    40  	if s := stderr.String(); strings.Contains(s, "SSA unimplemented") {
    41  		t.Errorf("Unimplemented message found in stderr:\n%s", s)
    42  	}
    43  }
    44  
    45  // TestShortCircuit tests OANDAND and OOROR expressions and short circuiting.
    46  func TestShortCircuit(t *testing.T) { runTest(t, "short_ssa.go") }
    47  
    48  // TestBreakContinue tests that continue and break statements do what they say.
    49  func TestBreakContinue(t *testing.T) { runTest(t, "break_ssa.go") }
    50  
    51  // TestTypeAssertion tests type assertions.
    52  func TestTypeAssertion(t *testing.T) { runTest(t, "assert_ssa.go") }
    53  
    54  // TestArithmetic tests that both backends have the same result for arithmetic expressions.
    55  func TestArithmetic(t *testing.T) { runTest(t, "arith_ssa.go") }
    56  
    57  // TestFP tests that both backends have the same result for floating point expressions.
    58  func TestFP(t *testing.T) { runTest(t, "fp_ssa.go") }
    59  
    60  // TestArithmeticBoundary tests boundary results for arithmetic operations.
    61  func TestArithmeticBoundary(t *testing.T) { runTest(t, "arithBoundary_ssa.go") }
    62  
    63  // TestArithmeticConst tests results for arithmetic operations against constants.
    64  func TestArithmeticConst(t *testing.T) { runTest(t, "arithConst_ssa.go") }
    65  
    66  func TestChan(t *testing.T) { runTest(t, "chan_ssa.go") }
    67  
    68  func TestCompound(t *testing.T) { runTest(t, "compound_ssa.go") }
    69  
    70  func TestCtl(t *testing.T) { runTest(t, "ctl_ssa.go") }
    71  
    72  func TestFp(t *testing.T) { runTest(t, "fp_ssa.go") }
    73  
    74  func TestLoadStore(t *testing.T) { runTest(t, "loadstore_ssa.go") }
    75  
    76  func TestMap(t *testing.T) { runTest(t, "map_ssa.go") }
    77  
    78  func TestRegalloc(t *testing.T) { runTest(t, "regalloc_ssa.go") }
    79  
    80  func TestString(t *testing.T) { runTest(t, "string_ssa.go") }
    81  
    82  func TestDeferNoReturn(t *testing.T) { buildTest(t, "deferNoReturn_ssa.go") }
    83  
    84  // TestClosure tests closure related behavior.
    85  func TestClosure(t *testing.T) { runTest(t, "closure_ssa.go") }
    86  
    87  func TestArray(t *testing.T) { runTest(t, "array_ssa.go") }
    88  
    89  func TestAppend(t *testing.T) { runTest(t, "append_ssa.go") }
    90  
    91  func TestZero(t *testing.T) { runTest(t, "zero_ssa.go") }
    92  
    93  func TestAddressed(t *testing.T) { runTest(t, "addressed_ssa.go") }
    94  
    95  func TestCopy(t *testing.T) { runTest(t, "copy_ssa.go") }
    96  
    97  func TestUnsafe(t *testing.T) { runTest(t, "unsafe_ssa.go") }
    98  
    99  func TestPhi(t *testing.T) { runTest(t, "phi_ssa.go") }
   100  
   101  func TestSlice(t *testing.T) { runTest(t, "slice.go") }