Skip to content

Commit b0fae82

Browse files
author
Michael Hendricks
authored
Merge pull request opencontainers#2 from wking/auto-plan-header
tap: Teach Header to skip the plan when testCount < 1
2 parents d8624b4 + f0db097 commit b0fae82

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

util/tap/Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
.PHONY: test
1+
TESTS = known auto
22

3-
test:
4-
go build main/test.go
5-
prove -v -e '' ./test
3+
.PHONY: $(TESTS)
4+
5+
all: $(TESTS)
6+
7+
$(TESTS): %: test/%/main.go
8+
go build -o $@ test/$@/main.go
9+
prove -v -e '' ./$@

util/tap/tap.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ func New() *T {
1515
}
1616

1717
// Header displays a TAP header including version number and expected
18-
// number of tests to run.
18+
// number of tests to run. For an unknown number of tests, set
19+
// testCount to zero (in which case the plan is not written); this is
20+
// useful with AutoPlan.
1921
func (t *T) Header(testCount int) {
2022
fmt.Printf("TAP version 13\n")
21-
fmt.Printf("1..%d\n", testCount)
23+
if testCount > 0 {
24+
fmt.Printf("1..%d\n", testCount)
25+
}
2226
}
2327

2428
// Ok generates TAP output indicating whether a test passed or failed.

util/tap/test/auto/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package main
2+
3+
import "github.com/mndrix/tap.go"
4+
5+
func main() {
6+
t := tap.New()
7+
t.Header(0)
8+
t.Ok(true, "first test")
9+
t.Ok(true, "second test")
10+
t.AutoPlan()
11+
}

util/tap/test/known/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main
2+
3+
import "github.com/mndrix/tap.go"
4+
5+
func main() {
6+
t := tap.New()
7+
t.Header(2)
8+
t.Ok(true, "first test")
9+
t.Ok(true, "second test")
10+
}

0 commit comments

Comments
 (0)