...

Source file src/golang.org/x/tools/go/analysis/passes/directive/directive_test.go

Documentation: golang.org/x/tools/go/analysis/passes/directive

     1  // Copyright 2023 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  package directive_test
     6  
     7  import (
     8  	"testing"
     9  
    10  	"golang.org/x/tools/go/analysis"
    11  	"golang.org/x/tools/go/analysis/analysistest"
    12  	"golang.org/x/tools/go/analysis/passes/directive"
    13  	"golang.org/x/tools/internal/testenv"
    14  )
    15  
    16  func Test(t *testing.T) {
    17  	testenv.NeedsGo1Point(t, 16)
    18  	analyzer := *directive.Analyzer
    19  	analyzer.Run = func(pass *analysis.Pass) (interface{}, error) {
    20  		defer func() {
    21  			// The directive pass is unusual in that it checks the IgnoredFiles.
    22  			// After analysis, add IgnoredFiles to OtherFiles so that
    23  			// the test harness checks for expected diagnostics in those.
    24  			// (The test harness shouldn't do this by default because most
    25  			// passes can't do anything with the IgnoredFiles without type
    26  			// information, which is unavailable because they are ignored.)
    27  			var files []string
    28  			files = append(files, pass.OtherFiles...)
    29  			files = append(files, pass.IgnoredFiles...)
    30  			pass.OtherFiles = files
    31  		}()
    32  
    33  		return directive.Analyzer.Run(pass)
    34  	}
    35  	analysistest.Run(t, analysistest.TestData(), &analyzer, "a")
    36  }
    37  

View as plain text