linttest

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package linttest provides linter testing utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFileReports

func GetFileReports(t *testing.T, contents string) []*linter.Report

GetFileReports runs linter over a single file out of given content and returns all reports that were found.

func ParseTestFile

func ParseTestFile(t *testing.T, filename, content string) (rootNode node.Node, w *linter.RootWalker)

ParseTestFile parses given test file.

func SimpleNegativeTest

func SimpleNegativeTest(t *testing.T, contents string)

SimpleNegativeTest runs linter over a single file out of given content and expects there to be no warnings.

For positive testing, use Suite type directly.

Types

type Suite

type Suite struct {
	Files  []TestFile
	Expect []string

	LoadStubs []string
	// contains filtered or unexported fields
}

Suite is a configurable test runner for linter.

Use NewSuite to create usable instance.

func NewSuite

func NewSuite(t *testing.T) *Suite

NewSuite returns a new linter test suite for t.

func (*Suite) AddFile

func (s *Suite) AddFile(contents string)

AddFile adds a file to a suite file list. File gets an auto-generated name. If custom name is important, append a properly initialized TestFile to a s Files slice directly.

func (*Suite) AddNolintFile

func (s *Suite) AddNolintFile(contents string)

AddNolintFile adds a file to a suite file list that will be parsed, but not linted. File gets an auto-generated name. If custom name is important, append a properly initialized TestFile to a s Files slice directly.

func (*Suite) Match

func (s *Suite) Match(reports []*linter.Report)

Match tries to match every report against Expect list of s.

If expect slice is nil or empty, only nil (or empty) reports slice would match it.

func (*Suite) RunAndMatch

func (s *Suite) RunAndMatch()

RunAndMatch calls Match with the results of RunLinter.

This is a recommended way to use the Suite, but if reports slice is needed, one can use RunLinter directly.

func (*Suite) RunLinter

func (s *Suite) RunLinter() []*linter.Report

RunLinter executes linter over s Files and returns all issue reports that were produced during that.

type TestFile

type TestFile struct {
	Name string

	// Data is a file contents.
	Data []byte

	// Nolint marks file as one that ignores all warnings.
	// Can be used to define builtins, for example.
	Nolint bool
}

TestFile describes a file to be tested.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL