Skip to content

Commit 81d3a42

Browse files
committed
Add T.Skip(count int, description string)
The spec [1] suggests "ok 23 # SKIP ...", but if you attempt this with: t.Pass("# SKIP foo") you get an extra hyphen ("ok 23 - # SKIP foo") which is parsed as a successful test (and not a skipped test). Michael gives the following example to motivate 'count' [2]: if ConditionIsMet() { t.Ok(Foo(), "foo") t.Ok(Bar(), "bar") } else { t.Skip(2, "condition not met") } The spec example of this is in [3], showing no special syntax for skipping multiple tests (although there is a special syntax for skipping *all* the tests). Also alphabetize TESTS in the Makefile. [1]: http://testanything.org/tap-version-13-specification.html#skipping-tests [2]: mndrix/tap-go#6 (comment) [3]: http://testanything.org/tap-version-13-specification.html#skipping-a-few
1 parent 92ea411 commit 81d3a42

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

util/tap/Makefile

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

44
.PHONY: $(TESTS)

util/tap/tap.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ func escapeNewlines(s string) string {
117117
return strings.Replace(strings.TrimRight(s, "\n"), "\n", "\n# ", -1)
118118
}
119119

120+
// Skip indicates that a test has been skipped.
121+
func (t *T) Skip(count int, description string) {
122+
for i := 0; i < count; i++ {
123+
t.printf("ok %d # SKIP %s\n", t.nextTestNumber, description)
124+
t.nextTestNumber++
125+
}
126+
}
127+
120128
// Diagnostic generates a diagnostic from the message,
121129
// which may span multiple lines.
122130
func (t *T) Diagnostic(message string) {

util/tap/test/skip/main.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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(4)
18+
t.Skip(1, "insufficient flogiston pressure")
19+
t.Skip(2, "no /sys directory")
20+
21+
got := buf.String()
22+
t.Ok(got == expected, "skip gave expected output")
23+
}
24+
25+
const expected = `TAP version 13
26+
1..4
27+
ok 1 # SKIP insufficient flogiston pressure
28+
ok 2 # SKIP no /sys directory
29+
ok 3 # SKIP no /sys directory
30+
`

0 commit comments

Comments
 (0)