Documentation ¶
Overview ¶
Package tap implements support for the Test Anything Protocol, a language-agnostic format for outputting the results of tests: https://testanything.org.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Document ¶
Document represents a complete TAP document.
type Object ¶
type Object interface {
Type() Type
}
Object is a TAP element such as a test line, plan, version header, or Yaml block.
type Producer ¶
type Producer struct {
// contains filtered or unexported fields
}
Producer produces TAP output.
This producer always includes test numbers.
Example (Many_test) ¶
package main import ( "os" "go.fuchsia.dev/fuchsia/tools/testing/tap" ) func main() { p := tap.NewProducer(os.Stdout) p.Plan(4) p.Ok(true, "- this test passed") p.Ok(false, "") }
Output: TAP version 13 1..4 ok 1 - this test passed not ok 2
Example (Single_test) ¶
package main import ( "os" "go.fuchsia.dev/fuchsia/tools/testing/tap" ) func main() { p := tap.NewProducer(os.Stdout) p.Plan(1) p.Ok(true, "- this test passed") }
Output: TAP version 13 1..1 ok 1 - this test passed
Example (Skip_todo_alternating) ¶
package main import ( "os" "go.fuchsia.dev/fuchsia/tools/testing/tap" ) func main() { p := tap.NewProducer(os.Stdout) p.Plan(4) p.Skip().Ok(true, "implement this test") p.Todo().Ok(false, "oh no!") p.Skip().Ok(false, "skipped another") p.Todo().Skip().Todo().Ok(true, "please don't write code like this") }
Output: TAP version 13 1..4 ok 1 # SKIP implement this test not ok 2 # TODO oh no! not ok 3 # SKIP skipped another ok 4 # TODO please don't write code like this
func NewProducer ¶
NewProducer creates a new Producer that writes to the given Writer.
func (*Producer) Ok ¶
Ok outputs a test line containing the given description and starting with either "ok" if test is true or "not ok" if false. If this producer was created using Todo or Skip, then the corresponding directive is also printed, and the description is used as the explanation of that directive.
func (*Producer) Skip ¶
Skip returns a new Producer that prints SKIP directives.
Example ¶
package main import ( "os" "go.fuchsia.dev/fuchsia/tools/testing/tap" ) func main() { p := tap.NewProducer(os.Stdout) p.Plan(1) p.Skip().Ok(true, "implement this test") }
Output: TAP version 13 1..1 ok 1 # SKIP implement this test
func (*Producer) Todo ¶
Todo returns a new Producer that prints TODO directives.
Example ¶
package main import ( "os" "go.fuchsia.dev/fuchsia/tools/testing/tap" ) func main() { p := tap.NewProducer(os.Stdout) p.Plan(1) p.Todo().Ok(true, "implement this test") }
Output: TAP version 13 1..1 ok 1 # TODO implement this test
func (*Producer) YAML ¶
YAML produces a YAML block from the given input. This will indent the input data. The caller should not do this themselves.
Example ¶
package main import ( "os" "time" "github.com/go-yaml/yaml" "go.fuchsia.dev/fuchsia/tools/testing/tap" ) func main() { p := tap.NewProducer(os.Stdout) p.Plan(1) p.Ok(true, "passed") bytes, err := yaml.Marshal(struct { Name string `yaml:"name"` Start time.Time `yaml:"start_time"` End time.Time `yaml:"end_time"` }{ Name: "foo_test", Start: time.Date(2019, 1, 1, 12, 30, 0, 0, time.UTC), End: time.Date(2019, 1, 1, 12, 40, 0, 0, time.UTC), }) if err != nil { panic(err) } p.YAML(bytes) }
Output: TAP version 13 1..1 ok 1 passed --- name: foo_test start_time: 2019-01-01T12:30:00Z end_time: 2019-01-01T12:40:00Z ...
type TestLine ¶
type TestLine struct { Ok bool Count int Description string Directive Directive Explanation string Diagnostic string YAML string }
TestLine represents a TAP test line beginning with "ok" or "not ok".