lib

package
v1.4.10 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2018 License: MIT Imports: 10 Imported by: 55

Documentation

Overview

Package lib is exposing parsers and output generation

Index

Constants

View Source
const (
	// XUnitTemplate is XML template for xunit style reporting
	XUnitTemplate string = `` /* 526-byte string literal not displayed */

	// XMLMultiTemplate is template when we have multiple suites
	XMLMultiTemplate string = `
<testsuites>` + XUnitTemplate + `</testsuites>
`

	// XUnitNetTemplate is XML template for xunit.net
	// see https://xunit.codeplex.com/wikipage?title=XmlFormat
	XUnitNetTemplate string = `` /* 1103-byte string literal not displayed */

)

Variables

View Source
var Options struct {
	// FailOnRace will mark test a failed if there is a race
	FailOnRace bool
}

Options is library options

Functions

func WriteXML

func WriteXML(suites []*Suite, out io.Writer, xmlTemplate string, testTime time.Time)

WriteXML exits xunit XML of tests to out

Types

type GotestLexer added in v1.4.3

type GotestLexer struct {
	// contains filtered or unexported fields
}

GotestLexer is a lexer for gotest output

func (*GotestLexer) Err added in v1.4.3

func (lex *GotestLexer) Err() error

Err returns the current error (if any)

func (*GotestLexer) Scan added in v1.4.3

func (lex *GotestLexer) Scan() bool

Scan scans the next token. Return true if there's a new one

func (*GotestLexer) Token added in v1.4.3

func (lex *GotestLexer) Token() *Token

Token returns the current Token

type GtParser added in v1.4.3

type GtParser struct {
	// contains filtered or unexported fields
}

GtParser is a gotest output parser

func (*GtParser) Err added in v1.4.3

func (gtp *GtParser) Err() error

Err is the current error

func (*GtParser) Scan added in v1.4.3

func (gtp *GtParser) Scan() bool

Scan scans for the next suite

func (*GtParser) Suite added in v1.4.3

func (gtp *GtParser) Suite() *Suite

Suite is the current suite

type Lexer added in v1.4.3

type Lexer interface {
	Scan() bool
	Token() *Token
	Err() error
}

Lexer generates tokens

func NewGotestLexer added in v1.4.3

func NewGotestLexer(in io.Reader) Lexer

NewGotestLexer returns a new lexer for gotest files

type LineScanner

type LineScanner struct {
	*bufio.Reader
	// contains filtered or unexported fields
}

LineScanner scans lines and keep track of line numbers

func NewLineScanner

func NewLineScanner(r io.Reader) *LineScanner

NewLineScanner creates a new line scanner from r

func (*LineScanner) Err added in v1.4.5

func (ls *LineScanner) Err() error

Err returns the current error (nil if no error)

func (*LineScanner) Line

func (ls *LineScanner) Line() int

Line returns the current line number

func (*LineScanner) Scan

func (ls *LineScanner) Scan() bool

Scan advances to next line.

func (*LineScanner) Text added in v1.4.5

func (ls *LineScanner) Text() string

Text returns the current line

type Parser added in v1.4.3

type Parser interface {
	Scan() bool
	Suite() *Suite
	Err() error
}

Parser generates suites

func NewGtParser added in v1.4.3

func NewGtParser(in io.Reader) Parser

NewGtParser return a new gotest parser

type Status

type Status int

Status is test status

const (
	UnknownStatus Status = iota
	Failed
	Skipped
	Passed
)

Test statuses

func Token2Status

func Token2Status(token string) Status

Token2Status return matching status for token

type Suite

type Suite struct {
	Name   string
	Time   string
	Status string
	Tests  []*Test
}

Suite of tests (found in some unit testing frameworks)

func (*Suite) Len

func (suite *Suite) Len() int

Len return the number of tests in the suite

func (*Suite) NumFailed

func (suite *Suite) NumFailed() int

NumFailed return number of failed tests in suite

func (*Suite) NumPassed

func (suite *Suite) NumPassed() int

NumPassed return number of passed tests in the suite

func (*Suite) NumSkipped

func (suite *Suite) NumSkipped() int

NumSkipped return number of skipped tests in suite

type SuiteStack

type SuiteStack struct {
	// contains filtered or unexported fields
}

SuiteStack is a stack of test suites

func (*SuiteStack) Pop

func (s *SuiteStack) Pop() *Suite

Pop removes and returns a node from the stack in last to first order.

func (*SuiteStack) Push

func (s *SuiteStack) Push(n *Suite)

Push adds a node to the stack.

type Suites

type Suites []*Suite

Suites is a list of suites

func ParseGocheck

func ParseGocheck(rd io.Reader, suitePrefix string) (Suites, error)

ParseGocheck parses output of "go test -gocheck.vv", returns a list of tests See data/gocheck.out for an example TODO: Refactor to shorter ones

func ParseGotest

func ParseGotest(rd io.Reader, suitePrefix string) (Suites, error)

ParseGotest parser output of gotest TODO: Make it shorter

func (Suites) HasFailures

func (s Suites) HasFailures() bool

HasFailures return true is there's at least one failing suite

type Test

type Test struct {
	Name, Time, Message string
	Status              Status
	AppendedErrorOutput bool
	// contains filtered or unexported fields
}

Test data structure

type TestResults

type TestResults struct {
	Suites     []*Suite
	Assembly   string
	RunDate    string
	RunTime    string
	Time       string
	Len        int
	NumPassed  int
	NumFailed  int
	NumSkipped int

	Skipped Status
	Passed  Status
	Failed  Status
}

TestResults is passed to XML template

type Token added in v1.4.3

type Token struct {
	Line int
	Type TokenType
	Data string
}

Token is a lex token (line oriented)

func (*Token) String added in v1.4.3

func (tok *Token) String() string

type TokenType added in v1.4.3

type TokenType int

TokenType is the type of token

const (
	StartToken TokenType = iota
	EndToken
	SuiteToken
	NoFilesToken
	BuildFailedToken
	ExitToken
	DataToken
)

Token types

func (TokenType) String added in v1.4.3

func (typ TokenType) String() string

Jump to

Keyboard shortcuts

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