2015-07-10 12:58:53 -06:00
|
|
|
// Copyright 2015 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
package gc
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"internal/testenv"
|
|
|
|
|
"os/exec"
|
2015-07-20 15:39:14 -07:00
|
|
|
"path/filepath"
|
2015-07-10 12:58:53 -06:00
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
2015-07-20 15:39:14 -07:00
|
|
|
// TODO: move all these tests elsewhere?
|
|
|
|
|
// Perhaps teach test/run.go how to run them with a new action verb.
|
|
|
|
|
func runTest(t *testing.T, filename string) {
|
2016-11-02 17:55:29 -07:00
|
|
|
t.Parallel()
|
2015-09-08 08:59:57 -07:00
|
|
|
doTest(t, filename, "run")
|
|
|
|
|
}
|
|
|
|
|
func buildTest(t *testing.T, filename string) {
|
2016-11-02 17:55:29 -07:00
|
|
|
t.Parallel()
|
2015-09-08 08:59:57 -07:00
|
|
|
doTest(t, filename, "build")
|
|
|
|
|
}
|
|
|
|
|
func doTest(t *testing.T, filename string, kind string) {
|
2015-07-10 12:58:53 -06:00
|
|
|
testenv.MustHaveGoBuild(t)
|
|
|
|
|
var stdout, stderr bytes.Buffer
|
2016-08-30 11:08:47 -07:00
|
|
|
cmd := exec.Command(testenv.GoToolPath(t), kind, filepath.Join("testdata", filename))
|
2015-07-10 12:58:53 -06:00
|
|
|
cmd.Stdout = &stdout
|
|
|
|
|
cmd.Stderr = &stderr
|
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
|
|
|
t.Fatalf("Failed: %v:\nOut: %s\nStderr: %s\n", err, &stdout, &stderr)
|
|
|
|
|
}
|
|
|
|
|
if s := stdout.String(); s != "" {
|
|
|
|
|
t.Errorf("Stdout = %s\nWant empty", s)
|
|
|
|
|
}
|
|
|
|
|
if s := stderr.String(); strings.Contains(s, "SSA unimplemented") {
|
|
|
|
|
t.Errorf("Unimplemented message found in stderr:\n%s", s)
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-20 15:39:14 -07:00
|
|
|
|
|
|
|
|
// TestShortCircuit tests OANDAND and OOROR expressions and short circuiting.
|
2016-09-15 13:29:17 -07:00
|
|
|
func TestShortCircuit(t *testing.T) { runTest(t, "short.go") }
|
2015-07-20 15:39:14 -07:00
|
|
|
|
|
|
|
|
// TestBreakContinue tests that continue and break statements do what they say.
|
2016-09-15 13:29:17 -07:00
|
|
|
func TestBreakContinue(t *testing.T) { runTest(t, "break.go") }
|
2015-07-25 12:53:58 -05:00
|
|
|
|
2015-09-17 10:31:16 -07:00
|
|
|
// TestTypeAssertion tests type assertions.
|
2016-09-15 13:29:17 -07:00
|
|
|
func TestTypeAssertion(t *testing.T) { runTest(t, "assert.go") }
|
2015-09-17 10:31:16 -07:00
|
|
|
|
2015-07-25 12:53:58 -05:00
|
|
|
// TestArithmetic tests that both backends have the same result for arithmetic expressions.
|
2016-09-20 13:59:40 -07:00
|
|
|
func TestArithmetic(t *testing.T) { runTest(t, "arith.go") }
|
2015-08-12 16:38:11 -04:00
|
|
|
|
|
|
|
|
// TestFP tests that both backends have the same result for floating point expressions.
|
2016-09-15 13:29:17 -07:00
|
|
|
func TestFP(t *testing.T) { runTest(t, "fp.go") }
|
2015-08-17 17:46:06 -05:00
|
|
|
|
|
|
|
|
// TestArithmeticBoundary tests boundary results for arithmetic operations.
|
2016-09-15 13:29:17 -07:00
|
|
|
func TestArithmeticBoundary(t *testing.T) { runTest(t, "arithBoundary.go") }
|
2015-08-18 19:14:47 -05:00
|
|
|
|
|
|
|
|
// TestArithmeticConst tests results for arithmetic operations against constants.
|
2016-09-15 13:29:17 -07:00
|
|
|
func TestArithmeticConst(t *testing.T) { runTest(t, "arithConst.go") }
|
2015-09-07 19:29:26 -05:00
|
|
|
|
2016-09-15 13:29:17 -07:00
|
|
|
func TestChan(t *testing.T) { runTest(t, "chan.go") }
|
2015-09-07 19:29:26 -05:00
|
|
|
|
2017-04-12 18:37:27 -04:00
|
|
|
// TestComparisonsConst tests results for comparison operations against constants.
|
|
|
|
|
func TestComparisonsConst(t *testing.T) { runTest(t, "cmpConst.go") }
|
|
|
|
|
|
2016-09-15 13:29:17 -07:00
|
|
|
func TestCompound(t *testing.T) { runTest(t, "compound.go") }
|
2015-09-07 19:29:26 -05:00
|
|
|
|
2016-09-15 13:29:17 -07:00
|
|
|
func TestCtl(t *testing.T) { runTest(t, "ctl.go") }
|
2015-09-07 19:29:26 -05:00
|
|
|
|
2016-09-15 13:29:17 -07:00
|
|
|
func TestLoadStore(t *testing.T) { runTest(t, "loadstore.go") }
|
2015-09-07 19:29:26 -05:00
|
|
|
|
2016-09-15 13:29:17 -07:00
|
|
|
func TestMap(t *testing.T) { runTest(t, "map.go") }
|
2015-09-07 19:29:26 -05:00
|
|
|
|
2016-09-15 13:29:17 -07:00
|
|
|
func TestRegalloc(t *testing.T) { runTest(t, "regalloc.go") }
|
2015-09-07 19:29:26 -05:00
|
|
|
|
2016-09-15 13:29:17 -07:00
|
|
|
func TestString(t *testing.T) { runTest(t, "string.go") }
|
2015-09-08 08:59:57 -07:00
|
|
|
|
2016-09-15 13:29:17 -07:00
|
|
|
func TestDeferNoReturn(t *testing.T) { buildTest(t, "deferNoReturn.go") }
|
2015-09-07 19:07:02 -05:00
|
|
|
|
|
|
|
|
// TestClosure tests closure related behavior.
|
2016-09-15 13:29:17 -07:00
|
|
|
func TestClosure(t *testing.T) { runTest(t, "closure.go") }
|
2015-09-12 23:27:26 -07:00
|
|
|
|
2016-09-15 13:29:17 -07:00
|
|
|
func TestArray(t *testing.T) { runTest(t, "array.go") }
|
2015-09-11 11:02:57 -07:00
|
|
|
|
2016-09-15 13:29:17 -07:00
|
|
|
func TestAppend(t *testing.T) { runTest(t, "append.go") }
|
2015-09-18 18:23:34 -07:00
|
|
|
|
2016-09-15 13:29:17 -07:00
|
|
|
func TestZero(t *testing.T) { runTest(t, "zero.go") }
|
2015-09-11 16:40:05 -04:00
|
|
|
|
2016-09-15 13:29:17 -07:00
|
|
|
func TestAddressed(t *testing.T) { runTest(t, "addressed.go") }
|
2015-10-21 17:18:07 -07:00
|
|
|
|
2016-09-15 13:29:17 -07:00
|
|
|
func TestCopy(t *testing.T) { runTest(t, "copy.go") }
|
2015-11-10 15:35:36 -08:00
|
|
|
|
2016-09-15 13:29:17 -07:00
|
|
|
func TestUnsafe(t *testing.T) { runTest(t, "unsafe.go") }
|
2016-01-04 13:34:54 -08:00
|
|
|
|
2016-09-15 13:29:17 -07:00
|
|
|
func TestPhi(t *testing.T) { runTest(t, "phi.go") }
|
2016-03-21 10:22:03 -07:00
|
|
|
|
|
|
|
|
func TestSlice(t *testing.T) { runTest(t, "slice.go") }
|
2016-04-01 11:05:30 -07:00
|
|
|
|
|
|
|
|
func TestNamedReturn(t *testing.T) { runTest(t, "namedReturn.go") }
|
2016-04-11 21:23:11 -07:00
|
|
|
|
|
|
|
|
func TestDuplicateLoad(t *testing.T) { runTest(t, "dupLoad.go") }
|
2016-08-20 22:05:47 -07:00
|
|
|
|
|
|
|
|
func TestSqrt(t *testing.T) { runTest(t, "sqrt_const.go") }
|