Skip to content

Commit 76112da

Browse files
committed
Explicitly test diagnostic output
To verify the changes in #4, I intentionally broke Diagnostic() by prefixing lines with "!" instead of "#" but the tests still passed. The spec[1] allows a test harness to silently ignore lines it doesn't understand, so that behavior makes sense. Red light green light testing[2] requires that our test be capable of failing if something is broken. This commit adds that by comparing the actual output against our expected output. Hat tip to @wking for suggesting to compare output[3]. 1: http://testanything.org/tap-version-13-specification.html#anything-else 2: http://stackoverflow.com/a/404860/174463 3: mndrix/tap-go#4 (comment)
1 parent 3d4b01e commit 76112da

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

util/tap/test/diagnostic/main.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
11
package main
22

3-
import "github.com/mndrix/tap-go"
3+
import (
4+
"bytes"
5+
"io"
6+
"os"
7+
8+
tap "github.com/mndrix/tap-go"
9+
)
410

511
func main() {
12+
// collect output for comparison later
13+
buf := new(bytes.Buffer)
614
t := tap.New()
15+
t.Writer = io.MultiWriter(os.Stdout, buf)
16+
717
t.Header(1)
818
t.Diagnostic("expecting all to be well")
919
t.Diagnosticf("here's some perfectly magical output: %d %s 0x%X.", 6, "abracadabra", 28)
1020
t.Diagnostic("some\nmultiline\ntext\n")
1121
t.Diagnosticf("%d lines\n%s multiline\ntext", 3, "more")
12-
t.Pass("all good")
22+
23+
got := buf.String()
24+
t.Ok(got == expected, "diagnostics gave expected output")
1325
}
26+
27+
const expected = `TAP version 13
28+
1..1
29+
# expecting all to be well
30+
# here's some perfectly magical output: 6 abracadabra 0x1C.
31+
# some
32+
# multiline
33+
# text
34+
# 3 lines
35+
# more multiline
36+
# text
37+
`

0 commit comments

Comments
 (0)