Skip to content

Commit 010390e

Browse files
committed
Add Pass() and Fail()
These are sometimes helpful in complex tests.
1 parent a39a5d7 commit 010390e

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

util/tap/tap.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ func (t *T) Ok(test bool, description string) {
7777
t.nextTestNumber++
7878
}
7979

80+
// Fail indicates that a test has failed. This is typically only used when the
81+
// logic is too complex to fit naturally into an Ok() call.
82+
func (t *T) Fail(description string) {
83+
t.Ok(false, description)
84+
}
85+
86+
// Pass indicates that a test has passed. This is typically only used when the
87+
// logic is too complex to fit naturally into an Ok() call.
88+
func (t *T) Pass(description string) {
89+
t.Ok(true, description)
90+
}
91+
8092
// Check runs randomized tests against a function just as "testing/quick.Check"
8193
// does. Success or failure generate appropriate TAP output.
8294
func (t *T) Check(function interface{}, description string) {

util/tap/test/failing/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "github.com/mndrix/tap-go"
44

55
func main() {
66
t := tap.New()
7-
t.Header(1)
7+
t.Header(2)
88
t.Ok(false, "first test")
9+
t.Fail("second test")
910
}

util/tap/test/known/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ func main() {
66
t := tap.New()
77
t.Header(2)
88
t.Ok(true, "first test")
9-
t.Ok(true, "second test")
9+
t.Pass("second test")
1010
}

0 commit comments

Comments
 (0)