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.
12 "golang.org/x/tools/go/analysis"
13 "golang.org/x/tools/go/analysis/analysistest"
14 "golang.org/x/tools/go/analysis/passes/buildtag"
17 func Test(t *testing.T) {
18 if strings.HasPrefix(runtime.Version(), "go1.") && runtime.Version() < "go1.16" {
19 t.Skipf("skipping on %v", runtime.Version())
21 analyzer := *buildtag.Analyzer
22 analyzer.Run = func(pass *analysis.Pass) (interface{}, error) {
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.)
31 files = append(files, pass.OtherFiles...)
32 files = append(files, pass.IgnoredFiles...)
33 pass.OtherFiles = files
36 return buildtag.Analyzer.Run(pass)
38 analysistest.Run(t, analysistest.TestData(), &analyzer, "a")