GoPLS Viewer

Home|gopls/go/analysis/passes/buildtag/buildtag_test.go
1// Copyright 2018 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
5package buildtag_test
6
7import (
8    "runtime"
9    "strings"
10    "testing"
11
12    "golang.org/x/tools/go/analysis"
13    "golang.org/x/tools/go/analysis/analysistest"
14    "golang.org/x/tools/go/analysis/passes/buildtag"
15)
16
17func Test(t *testing.T) {
18    if strings.HasPrefix(runtime.Version(), "go1.") && runtime.Version() < "go1.16" {
19        t.Skipf("skipping on %v"runtime.Version())
20    }
21    analyzer := *buildtag.Analyzer
22    analyzer.Run = func(pass *analysis.Pass) (interface{}, error) {
23        defer func() {
24            // The buildtag pass is unusual in that it checks the IgnoredFiles.
25            // After analysis, add IgnoredFiles to OtherFiles so that
26            // the test harness checks for expected diagnostics in those.
27            // (The test harness shouldn't do this by default because most
28            // passes can't do anything with the IgnoredFiles without type
29            // information, which is unavailable because they are ignored.)
30            var files []string
31            files = append(filespass.OtherFiles...)
32            files = append(filespass.IgnoredFiles...)
33            pass.OtherFiles = files
34        }()
35
36        return buildtag.Analyzer.Run(pass)
37    }
38    analysistest.Run(tanalysistest.TestData(), &analyzer"a")
39}
40
MembersX
testing
analysistest
buildtag
Test
Test.t
Test.BlockStmt.BlockStmt.files
runtime
Members
X