[tap] Fix bug in producer test count
In order to switch to "TODO" or "SKIP" mode we can
just set a temporary flag and unset it in the next
call to OK. This fixes a bug where the count is
unchanged after calling Todo or Skip because the
copied Producer does not increment the same integer
value.
Change-Id: I34236795722d136ad59d53ded481c8d62d8acbfa
diff --git a/tap/producer.go b/tap/producer.go
index c2e9f66..53d6194 100644
--- a/tap/producer.go
+++ b/tap/producer.go
@@ -58,20 +58,20 @@
case Skip:
p.writeln("%s %d # SKIP %s", ok, p.testNumber, description)
}
+
+ p.directive = None
}
// Todo returns a new Producer that prints TODO directives.
func (p *Producer) Todo() *Producer {
- newP := *p
- newP.directive = Todo
- return &newP
+ p.directive = Todo
+ return p
}
// Skip returns a new Producer that prints SKIP directives.
func (p *Producer) Skip() *Producer {
- newP := *p
- newP.directive = Skip
- return &newP
+ p.directive = Skip
+ return p
}
func (p *Producer) writeln(format string, args ...interface{}) {
diff --git a/tap/producer_test.go b/tap/producer_test.go
index 641ccbc..8e56ebb 100644
--- a/tap/producer_test.go
+++ b/tap/producer_test.go
@@ -42,16 +42,32 @@
func ExampleProducer_many_test() {
p := tap.NewProducer(os.Stdout)
- p.Plan(3)
+ p.Plan(4)
p.Ok(true, "- this test passed")
p.Ok(false, "")
p.Ok(false, "- this test failed")
p.Skip().Ok(true, "this test is skippable")
// Output:
// TAP version 13
- // 1..3
+ // 1..4
// ok 1 - this test passed
// not ok 2
// not ok 3 - this test failed
// ok 4 # SKIP this test is skippable
}
+
+func ExampleProducer_skip_todo_alternating() {
+ 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
+}