]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/go/types/check_test.go
go/types, types2: add FileVersions map to test Info
[gostls13.git] / src / go / types / check_test.go
index e99cb2e374723fc39cb39c0229c2d84d53b6b29b..fc9723a67fa5cf4569bb51e55dead7c0d0ed2d6a 100644 (file)
@@ -125,7 +125,7 @@ func parseFlags(src []byte, flags *flag.FlagSet) error {
 // testFiles type-checks the package consisting of the given files, and
 // compares the resulting errors with the ERROR annotations in the source.
 // Except for manual tests, each package is type-checked twice, once without
-// use of _Alias types, and once with _Alias types.
+// use of Alias types, and once with Alias types.
 //
 // The srcs slice contains the file content for the files named in the
 // filenames slice. The colDelta parameter specifies the tolerance for position
@@ -134,9 +134,11 @@ func parseFlags(src []byte, flags *flag.FlagSet) error {
 //
 // If provided, opts may be used to mutate the Config before type-checking.
 func testFiles(t *testing.T, filenames []string, srcs [][]byte, manual bool, opts ...func(*Config)) {
+       // Alias types are disabled by default
        testFilesImpl(t, filenames, srcs, manual, opts...)
        if !manual {
-               testFilesImpl(t, filenames, srcs, manual, append(opts, func(conf *Config) { *boolFieldAddr(conf, "_EnableAlias") = true })...)
+               t.Setenv("GODEBUG", "gotypesalias=1")
+               testFilesImpl(t, filenames, srcs, manual, opts...)
        }
 }
 
@@ -184,15 +186,16 @@ func testFilesImpl(t *testing.T, filenames []string, srcs [][]byte, manual bool,
        }
 
        // apply flag setting (overrides custom configuration)
-       var goexperiment string
+       var goexperiment, gotypesalias string
        flags := flag.NewFlagSet("", flag.PanicOnError)
        flags.StringVar(&conf.GoVersion, "lang", "", "")
        flags.StringVar(&goexperiment, "goexperiment", "", "")
        flags.BoolVar(&conf.FakeImportC, "fakeImportC", false, "")
-       flags.BoolVar(boolFieldAddr(&conf, "_EnableAlias"), "alias", false, "")
+       flags.StringVar(&gotypesalias, "gotypesalias", "", "")
        if err := parseFlags(srcs[0], flags); err != nil {
                t.Fatal(err)
        }
+
        exp, err := buildcfg.ParseGOEXPERIMENT(runtime.GOOS, runtime.GOARCH, goexperiment)
        if err != nil {
                t.Fatal(err)
@@ -203,15 +206,21 @@ func testFilesImpl(t *testing.T, filenames []string, srcs [][]byte, manual bool,
        }()
        buildcfg.Experiment = *exp
 
+       // By default, gotypesalias is not set.
+       if gotypesalias != "" {
+               t.Setenv("GODEBUG", "gotypesalias="+gotypesalias)
+       }
+
        // Provide Config.Info with all maps so that info recording is tested.
        info := Info{
-               Types:      make(map[ast.Expr]TypeAndValue),
-               Instances:  make(map[*ast.Ident]Instance),
-               Defs:       make(map[*ast.Ident]Object),
-               Uses:       make(map[*ast.Ident]Object),
-               Implicits:  make(map[ast.Node]Object),
-               Selections: make(map[*ast.SelectorExpr]*Selection),
-               Scopes:     make(map[ast.Node]*Scope),
+               Types:        make(map[ast.Expr]TypeAndValue),
+               Instances:    make(map[*ast.Ident]Instance),
+               Defs:         make(map[*ast.Ident]Object),
+               Uses:         make(map[*ast.Ident]Object),
+               Implicits:    make(map[ast.Node]Object),
+               Selections:   make(map[*ast.SelectorExpr]*Selection),
+               Scopes:       make(map[ast.Node]*Scope),
+               FileVersions: make(map[*ast.File]string),
        }
 
        // typecheck