@@ -31,16 +31,20 @@ import "testing/quick"
3131// T is a type to encapsulate test state. Methods on this type generate TAP
3232// output.
3333type T struct {
34- nextTestNumber int
34+ nextTestNumber * int
35+
36+ // TODO toggles the TODO directive for Ok, Fail, Pass, and similar.
37+ TODO bool
3538
3639 // Writer indicates where TAP output should be sent. The default is os.Stdout.
3740 Writer io.Writer
3841}
3942
4043// New creates a new Tap value
4144func New () * T {
45+ nextTestNumber := 1
4246 return & T {
43- nextTestNumber : 1 ,
47+ nextTestNumber : & nextTestNumber ,
4448 }
4549}
4650
@@ -74,8 +78,12 @@ func (t *T) Ok(test bool, description string) {
7478 ok = "not ok"
7579 }
7680
77- t .printf ("%s %d - %s\n " , ok , t .nextTestNumber , description )
78- t .nextTestNumber ++
81+ if t .TODO {
82+ t .printf ("%s %d # TODO %s\n " , ok , * t .nextTestNumber , description )
83+ } else {
84+ t .printf ("%s %d - %s\n " , ok , * t .nextTestNumber , description )
85+ }
86+ (* t .nextTestNumber )++
7987}
8088
8189// Fail indicates that a test has failed. This is typically only used when the
@@ -105,7 +113,7 @@ func (t *T) Check(function interface{}, description string) {
105113
106114// Count returns the number of tests completed so far.
107115func (t * T ) Count () int {
108- return t .nextTestNumber - 1
116+ return * t .nextTestNumber - 1
109117}
110118
111119// AutoPlan generates a test plan based on the number of tests that were run.
@@ -117,6 +125,21 @@ func escapeNewlines(s string) string {
117125 return strings .Replace (strings .TrimRight (s , "\n " ), "\n " , "\n # " , - 1 )
118126}
119127
128+ // Todo returns copy of the test-state with TODO set.
129+ func (t * T ) Todo () * T {
130+ newT := * t
131+ newT .TODO = true
132+ return & newT
133+ }
134+
135+ // Skip indicates that a test has been skipped.
136+ func (t * T ) Skip (count int , description string ) {
137+ for i := 0 ; i < count ; i ++ {
138+ t .printf ("ok %d # SKIP %s\n " , * t .nextTestNumber , description )
139+ (* t .nextTestNumber )++
140+ }
141+ }
142+
120143// Diagnostic generates a diagnostic from the message,
121144// which may span multiple lines.
122145func (t * T ) Diagnostic (message string ) {
0 commit comments