tap

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2020 License: MIT Imports: 8 Imported by: 12

README

go-tap

TAP (Test Anything Protocol) parser in golang.

import "github.com/shogo82148/go-tap"

func ExampleNewParser() {
	r := strings.NewReader(`1..3
ok 1 hogehoge
not ok foobar
# Doesn't wiggle
not ok 3 foobar # TODO not implemented yet`)
	p, err := NewParser(r)
	if err != nil {
		panic(err)
	}

	suite, err := p.Suite()
	if err != nil {
		panic(err)
	}

	for _, t := range suite.Tests {
		fmt.Println(t)
	}

	// Output:
	// ok 1 hogehoge
	// not ok 2 foobar
	// not ok 3 foobar # TODO not implemented yet
}

see godoc for more detail.

Documentation

Index

Examples

Constants

View Source
const DefaultTAPVersion = 12

DefaultTAPVersion is default TAP version.

Variables

View Source
var ErrUnsupportedVersion = errors.New("tap: unsupported version")

ErrUnsupportedVersion is an error for unsupported TAP version.

Functions

This section is empty.

Types

type Directive

type Directive int

Directive is a TAP-Directive (TODO/Skip)

const (
	// None describes no directive given.
	None Directive = iota

	// TODO describess the testpoint is a TODO.
	TODO

	// Skip describes the testpoint was skipped.
	Skip
)

func (Directive) String

func (d Directive) String() string

type Parser

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

Parser is a TAP parser.

func NewParser

func NewParser(r io.Reader) (*Parser, error)

NewParser creates a new Parser.

Example
r := strings.NewReader(`1..3
ok 1 hogehoge
not ok foobar
# Doesn't wiggle
not ok 3 foobar # TODO not implemented yet`)
p, err := NewParser(r)
if err != nil {
	panic(err)
}

suite, err := p.Suite()
if err != nil {
	panic(err)
}
if suite.Ok {
	fmt.Println("Everything ok")
	return
}

for _, t := range suite.Tests {
	fmt.Println(t)
}
Output:

ok 1 - hogehoge
not ok 2 - foobar
not ok 3 - foobar # TODO not implemented yet

func (*Parser) Next

func (p *Parser) Next() (*Testline, error)

Next returns next Testline.

func (*Parser) Suite

func (p *Parser) Suite() (*Testsuite, error)

Suite returns the Testsuite.

type Testline

type Testline struct {
	Ok          bool          // Whether the Testpoint executed ok
	Num         int           // The number of the test
	Description string        // A short description
	Directive   Directive     // Whether the test was skipped or is a todo
	Explanation string        // A short explanation why the test was skipped/is a todo
	Diagnostic  string        // A more detailed diagnostic message about the failed test
	Time        time.Duration // Time it took to test
	YAML        []byte        // The inline YAML-document, if given
	SubTests    []*Testline   // Sub-Tests
}

Testline is a single TAP-Testline.

func (*Testline) GoString

func (t *Testline) GoString() string

GoString returns the detail of the test result.

Example
r := strings.NewReader(`TAP version 13
ok 1 - foo
    # Subtest: bar
        # Subtest: subtest1
        ok 1 - subsubtest1
        ok 2 - subsubtest2 # TODO not implemented yet
        # note message for subsubtest2
        ok 3 - subsubtest3
        1..3
    ok 1 - subtest1
    1..1
ok 2 - bar
ok 3 - foobar
---
- foo
- bar
...
1..3
`)
p, err := NewParser(r)
if err != nil {
	panic(err)
}

suite, err := p.Suite()
if err != nil {
	panic(err)
}

for _, t := range suite.Tests {
	fmt.Printf("%#v", t)
}
Output:

ok 1 - foo
    # Subtest: bar
        # Subtest: subtest1
        ok 1 - subsubtest1
        ok 2 - subsubtest2 # TODO not implemented yet
        # note message for subsubtest2
        ok 3 - subsubtest3
        1..3
    ok 1 - subtest1
    1..1
ok 2 - bar
ok 3 - foobar
---
- foo
- bar
...

func (*Testline) String

func (t *Testline) String() string

type Testsuite

type Testsuite struct {
	Ok      bool          // Whether the Testsuite as a whole succeeded
	Tests   []*Testline   // Description of all Testlines
	Plan    int           // Number of tests intended to run (-1 means no plan)
	Version int           // version number of TAP
	Time    time.Duration // Time it took to test
}

Testsuite is the outcome of a Testsuite

Jump to

Keyboard shortcuts

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