mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[git-generate] cd src/cmd/compile/internal/gc rf ' mv bench_test.go constFold_test.go dep_test.go \ fixedbugs_test.go iface_test.go float_test.go global_test.go \ inl_test.go lang_test.go logic_test.go \ reproduciblebuilds_test.go shift_test.go ssa_test.go \ truncconst_test.go zerorange_test.go \ cmd/compile/internal/test ' mv testdata ../test Change-Id: I041971b7e9766673f7a331679bfe1c8110dcda66 Reviewed-on: https://go-review.googlesource.com/c/go/+/279480 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
// Copyright 2018 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 test
|
|
|
|
import (
|
|
"internal/testenv"
|
|
"io/ioutil"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
const aliasSrc = `
|
|
package x
|
|
|
|
type T = int
|
|
`
|
|
|
|
func TestInvalidLang(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
testenv.MustHaveGoBuild(t)
|
|
|
|
dir, err := ioutil.TempDir("", "TestInvalidLang")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer os.RemoveAll(dir)
|
|
|
|
src := filepath.Join(dir, "alias.go")
|
|
if err := ioutil.WriteFile(src, []byte(aliasSrc), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
outfile := filepath.Join(dir, "alias.o")
|
|
|
|
if testLang(t, "go9.99", src, outfile) == nil {
|
|
t.Error("compilation with -lang=go9.99 succeeded unexpectedly")
|
|
}
|
|
|
|
// This test will have to be adjusted if we ever reach 1.99 or 2.0.
|
|
if testLang(t, "go1.99", src, outfile) == nil {
|
|
t.Error("compilation with -lang=go1.99 succeeded unexpectedly")
|
|
}
|
|
|
|
if testLang(t, "go1.8", src, outfile) == nil {
|
|
t.Error("compilation with -lang=go1.8 succeeded unexpectedly")
|
|
}
|
|
|
|
if err := testLang(t, "go1.9", src, outfile); err != nil {
|
|
t.Errorf("compilation with -lang=go1.9 failed unexpectedly: %v", err)
|
|
}
|
|
}
|
|
|
|
func testLang(t *testing.T, lang, src, outfile string) error {
|
|
run := []string{testenv.GoToolPath(t), "tool", "compile", "-lang", lang, "-o", outfile, src}
|
|
t.Log(run)
|
|
out, err := exec.Command(run[0], run[1:]...).CombinedOutput()
|
|
t.Logf("%s", out)
|
|
return err
|
|
}
|