1
2
3
4
5 package test
6
7 import (
8 "internal/testenv"
9 "os"
10 "path/filepath"
11 "testing"
12 )
13
14 const aliasSrc = `
15 package x
16
17 type T = int
18 `
19
20 func TestInvalidLang(t *testing.T) {
21 t.Parallel()
22
23 testenv.MustHaveGoBuild(t)
24
25 dir := t.TempDir()
26
27 src := filepath.Join(dir, "alias.go")
28 if err := os.WriteFile(src, []byte(aliasSrc), 0644); err != nil {
29 t.Fatal(err)
30 }
31
32 outfile := filepath.Join(dir, "alias.o")
33
34 if testLang(t, "go9.99", src, outfile) == nil {
35 t.Error("compilation with -lang=go9.99 succeeded unexpectedly")
36 }
37
38
39 if testLang(t, "go1.99", src, outfile) == nil {
40 t.Error("compilation with -lang=go1.99 succeeded unexpectedly")
41 }
42
43 if testLang(t, "go1.8", src, outfile) == nil {
44 t.Error("compilation with -lang=go1.8 succeeded unexpectedly")
45 }
46
47 if err := testLang(t, "go1.9", src, outfile); err != nil {
48 t.Errorf("compilation with -lang=go1.9 failed unexpectedly: %v", err)
49 }
50 }
51
52 func testLang(t *testing.T, lang, src, outfile string) error {
53 run := []string{testenv.GoToolPath(t), "tool", "compile", "-p=p", "-lang", lang, "-o", outfile, src}
54 t.Log(run)
55 out, err := testenv.Command(t, run[0], run[1:]...).CombinedOutput()
56 t.Logf("%s", out)
57 return err
58 }
59
View as plain text