Skip to content
This repository was archived by the owner on Feb 8, 2020. It is now read-only.

Commit f5c62d7

Browse files
committed
Add T.TODO(test bool, description string)
The spec [1] suggests "not ok 13 # TODO ...", but if you attempt this with: t.Fail("# TODO foo") you get an extra hyphen ("not ok 13 - # TODO foo") which is parsed as a failed test (and not a TODO test). [1]: http://testanything.org/tap-version-13-specification.html#todo-tests
1 parent b16a8be commit f5c62d7

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
TESTS = auto check diagnostic failing known skip writer
1+
TESTS = auto check diagnostic failing known skip todo writer
22
GOPATH = $(CURDIR)/gopath
33

44
.PHONY: $(TESTS)

tap.go

+12
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ func escapeNewlines(s string) string {
117117
return strings.Replace(strings.TrimRight(s, "\n"), "\n", "\n# ", -1)
118118
}
119119

120+
// TODO indicates a known bug (which is expected to fail).
121+
func (t *T) TODO(test bool, description string) {
122+
// did the test pass or not?
123+
ok := "ok"
124+
if !test {
125+
ok = "not ok"
126+
}
127+
128+
t.printf("%s %d # TODO %s\n", ok, t.nextTestNumber, description)
129+
t.nextTestNumber++
130+
}
131+
120132
// Skip indicates that a test has been skipped.
121133
func (t *T) Skip(description string) {
122134
t.printf("ok %d # SKIP %s\n", t.nextTestNumber, description)

test/todo/main.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import (
4+
"bytes"
5+
"io"
6+
"os"
7+
8+
tap "github.com/mndrix/tap-go"
9+
)
10+
11+
func main() {
12+
// collect output for comparison later
13+
buf := new(bytes.Buffer)
14+
t := tap.New()
15+
t.Writer = io.MultiWriter(os.Stdout, buf)
16+
17+
t.Header(2)
18+
t.TODO(false, "bend space and time")
19+
20+
got := buf.String()
21+
t.Ok(got == expected, "skip gave expected output")
22+
}
23+
24+
const expected = `TAP version 13
25+
1..2
26+
not ok 1 # TODO bend space and time
27+
`

0 commit comments

Comments
 (0)