testutil

package
v0.0.0-...-f90256a Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2017 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package testutil contains methods to test checkers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(str string) func(err error) error

Contains contains

func HasSuffix

func HasSuffix(suffix string) func(err error) error

HasSuffix returns a function that checks that an error is returned which has the provided suffix.

func MatchesRegexp

func MatchesRegexp(re string) func(err error) error

MatchesRegexp returns a function that checks that an error is return which matches the provided regexp.

func NoError

func NoError(err error) error

NoError returns err. Use this if you expect the operation to have no error.

func Skip

func Skip(s lint.Skipper, then func(error) error) func(err error) error

Skip returns a function that skips errors using s and verifies the result using then

func SkippedErrors

func SkippedErrors(pattern string) func(error) error

SkippedErrors returns a function that skips all errors matching pattern and verifies there are no errors left.

func Test

func Test(t Errorer, pkg string, tests []StaticCheckTest)

Test runs the provided StaticCheckTests for pkg. Errors are reported using Errorer.

func TestArgs

func TestArgs(t Errorer, tests []ArgTest)

TestArgs runs the provided ArgTests. Errors are reported using Errorer.

func TestSkips

func TestSkips(t Errorer, tests []SkipTest)

TestSkips runs the provided SkipTests. Errors are reported using Errorer.

Types

type ArgTest

type ArgTest struct {
	A        Arger
	Expected []string
}

ArgTest verifies that the expected command line arguments are returned

func (ArgTest) Test

func (a ArgTest) Test() error

Test runs ArgTest and returns an error if the arguments generated by a.A do not match a.Expected

type Arger

type Arger interface {
	Args() []string
}

Arger holds the Args method that returns a list of command line arguments

type Errorer

type Errorer interface {
	Error(args ...interface{})
}

Errorer is used to report Errors. testing.T can be used as an Errorer.

type SkipTest

type SkipTest struct {
	S    lint.Skipper
	Line string
	Skip bool
}

SkipTest is a table driven test for skippers

func (SkipTest) Test

func (s SkipTest) Test() error

Test returns an error if the s.S.Skip(s.Line) != s.Skip

type StaticCheckMultiFileTest

type StaticCheckMultiFileTest struct {
	// Contents are the contents of the created files.
	Contents [][]byte
	// Checker is the checker to run on the package.
	Checker lint.Checker
	// Validate returns nil if err is what is expected.
	Validate func(err error) error
}

StaticCheckMultiFileTest is a table-driven test for a checker testing a package with multiple files.

func (StaticCheckMultiFileTest) Test

Test runs the multifile test for pkg.

type StaticCheckTest

type StaticCheckTest struct {
	// File is a src file to use instead of Content.
	File string
	// Content is the content of the created file.
	Content []byte
	// Checker is the checker to run on the package.
	Checker lint.Checker
	// Validate returns nil if err is what is expected.
	Validate func(err error) error
}

StaticCheckTest is a table-driven test for a checker.

func (StaticCheckTest) Test

func (s StaticCheckTest) Test(pkg string) error

Test runs the test for pkg.

Jump to

Keyboard shortcuts

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