GoPLS Viewer

Home|gopls/internal/typeparams/typeparams_test.go
1// Copyright 2021 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//go:build go1.18
6// +build go1.18
7
8package typeparams_test
9
10import (
11    "go/ast"
12    "go/importer"
13    "go/parser"
14    "go/token"
15    "go/types"
16    "strings"
17    "testing"
18
19    "golang.org/x/tools/internal/apidiff"
20    "golang.org/x/tools/internal/testenv"
21)
22
23func TestAPIConsistency(t *testing.T) {
24    testenv.NeedsGoBuild(t// This is a lie. We actually need the source code.
25
26    // The packages below exclude enabled_*.go, as typeparams.Enabled is
27    // permitted to change between versions.
28    old := typeCheck(t, []string{"common.go""typeparams_go117.go"})
29    new := typeCheck(t, []string{"common.go""typeparams_go118.go"})
30
31    report := apidiff.Changes(oldnew)
32
33    // Temporarily ignore API diff related to Environment, so that we can use a
34    // transient alias in go/types to allow renaming this type without ever
35    // breaking the x/tools builder.
36    // TODO(rfindley): remove this
37    var filteredChanges []apidiff.Change
38    for _change := range report.Changes {
39        if strings.Contains(change.Message"Environment") {
40            continue
41        }
42        filteredChanges = append(filteredChangeschange)
43    }
44    report.Changes = filteredChanges
45    if len(report.Changes) > 0 {
46        t.Errorf("API diff:\n%s"report)
47    }
48}
49
50func typeCheck(t *testing.Tfilenames []string) *types.Package {
51    fset := token.NewFileSet()
52    var files []*ast.File
53    for _name := range filenames {
54        ferr := parser.ParseFile(fsetnamenil0)
55        if err != nil {
56            t.Fatal(err)
57        }
58        files = append(filesf)
59    }
60    conf := types.Config{
61        Importerimporter.Default(),
62    }
63    pkgerr := conf.Check(""fsetfilesnil)
64    if err != nil {
65        t.Fatal(err)
66    }
67    return pkg
68}
69
MembersX
typeCheck.t
typeCheck.filenames
typeCheck.RangeStmt_1445.BlockStmt.err
TestAPIConsistency.RangeStmt_1055.change
typeCheck
typeCheck.RangeStmt_1445.name
typeCheck.RangeStmt_1445.BlockStmt.f
typeCheck.conf
importer
apidiff
TestAPIConsistency
TestAPIConsistency.old
typeCheck.fset
typeCheck.pkg
typeCheck.err
TestAPIConsistency.t
TestAPIConsistency.new
TestAPIConsistency.report
TestAPIConsistency.filteredChanges
typeCheck.files
Members
X