Documentation
¶
Index ¶
- func Filter(t analysistest.Testing, filter func(format string, args ...interface{}) bool) analysistest.Testing
- func ModFile(t *testing.T, path string, fix modfile.VersionFixer) io.Reader
- func ReplaceStderr(onoff bool)
- func RunWithVersions(t *testing.T, dir string, a *analysis.Analyzer, vers []ModuleVersion, ...) map[ModuleVersion][]*analysistest.Result
- func WithModules(t *testing.T, srcdir string, modfile io.Reader) (dir string)
- type ErrorfFunc
- type ModuleVersion
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Filter ¶
func Filter(t analysistest.Testing, filter func(format string, args ...interface{}) bool) analysistest.Testing
Filter calls t.Errorf when the filter returns true.
func ModFile ¶
ModFile opens a mod file with the path and fixes versions by the version fixer. If the path is direcotry, ModFile opens go.mod which is under the path.
func ReplaceStderr ¶ added in v0.2.0
func ReplaceStderr(onoff bool)
func RunWithVersions ¶ added in v0.2.0
func RunWithVersions(t *testing.T, dir string, a *analysis.Analyzer, vers []ModuleVersion, pkg string) map[ModuleVersion][]*analysistest.Result
RunWithVersions runs analysistest.Run with modules which version is specified the vers.
Example:
func TestAnalyzer(t *testing.T) {
vers := AllVersion(t, "github.com/tenntenn/greeting/v2")
RunWithVersions(t, analysistest.TestData(), mod.Analyzer, vers, "a")
}
The test run in temporary directory which is isolated the dir. analysistest.Run uses packages.Load and it prints errors into os.Stderr. Becase the error messages include the temporary directory path, so RunWithVersions replaces os.Stderr. Replacing os.Stderr is not thread safe. If you want to turn off replacing os.Stderr, you can use ReplaceStderr(false).
func WithModules ¶
WithModules creates a temp dir which is copied from srcdir and generates vendor directory with go.mod. go.mod can be specified by modfileReader. Example:
func TestAnalyzer(t *testing.T) {
testdata := testutil.WithModules(t, analysistest.TestData(), nil)
analysistest.Run(t, testdata, sample.Analyzer, "a")
}
Types ¶
type ErrorfFunc ¶
type ErrorfFunc func(format string, args ...interface{})
ErrorfFunc implements analysistest.Testing.
func (ErrorfFunc) Errorf ¶
func (f ErrorfFunc) Errorf(format string, args ...interface{})
Errorf implements analysistest.Testing.
type ModuleVersion ¶ added in v0.2.0
ModuleVersion has module path and its version.
func AllVersion ¶ added in v0.2.0
func AllVersion(t *testing.T, module string) []ModuleVersion
AllVersion get available all versions of the module.
func FilterVersion ¶ added in v0.2.0
func FilterVersion(t *testing.T, module, constraints string) []ModuleVersion
FilterVersion returns versions of the module which satisfy the constraints such as ">= v2.0.0" The constraints rule uses github.com/hashicorp/go-version.
Example:
func TestAnalyzer(t *testing.T) {
vers := FilterVersion(t, "github.com/tenntenn/greeting/v2", ">= v2.0.0")
RunWithVersions(t, analysistest.TestData(), mod.Analyzer, vers, "a")
}
func (ModuleVersion) String ¶ added in v0.2.0
func (modver ModuleVersion) String() string
String implements fmt.Stringer.