forked from Merovius/go-tap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tap_test.go
320 lines (269 loc) · 8.03 KB
/
tap_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
package tap
import (
"strings"
"testing"
)
func TestBasic(t *testing.T) {
r := strings.NewReader(`TAP version 13
1..2
ok 1
not ok 2`)
parser, err := NewParser(r)
if err != nil {
t.Errorf("Should be no error on parsing preamble, got: %v", err)
}
suite, err := parser.Suite()
if err != nil {
t.Errorf("Should be no error on parsing input, got: %v", err)
}
if len(suite.Tests) != 2 {
t.Errorf("Expect 2 tests, got: %v", len(suite.Tests))
}
if suite.Tests[0].Ok != true {
t.Errorf("Expect first test to be ok, got: %v", suite.Tests[0].Ok)
}
if suite.Tests[1].Ok != false {
t.Errorf("Expect second test to be not ok, got: %v", suite.Tests[1].Ok)
}
}
// PHPUnit output violate TAP Specification, but fix here easier than in PHPUnit
func TestDatasetNumber(t *testing.T) {
r := strings.NewReader(`TAP version 13
ok 1 - phpunit test with data set #0 ('', '', array(''))
ok 2 - phpunit test with data set #1 ('1234', '1234', array('1234'))
ok 3 - phpunit test with data set #2 ('simpleTest', 'simple_test', array('simple', 'test'))
ok 4 - phpunit test with data set #3 ('easy', 'easy', array('easy'))
ok 5 - phpunit test with data set #4 ('HTML', 'html', array('html'))
ok 6 - phpunit test with data set #5 ('SimpleXML', 'simple_xml', array('simple', 'xml'))
ok 7 - phpunit test with data set #6 ('PDFLoad', 'pdf_load', array('pdf', 'load'))
ok 8 - phpunit test with data set #7 ('startMIDDLELast', 'start_middle_last', array('start', 'middle', 'last'))
ok 9 - phpunit test with data set #8 ('AString', 'a_string', array('a', 'string'))
ok 10 - phpunit test with data set #9 ('Some4Numbers234', 'some4_numbers234', array('some4', 'numbers234'))
1..10`)
parser, err := NewParser(r)
if err != nil {
t.Errorf("Should be no error on parsing preamble, got: %v", err)
}
suite, err := parser.Suite()
if err != nil {
t.Errorf("Should be no error on parsing input, got: %v", err)
}
if len(suite.Tests) != 10 {
t.Errorf("Expect 10 tests, got: %v", len(suite.Tests))
}
if !suite.Ok {
t.Errorf("Expect suite to be ok, got: %v", suite.Ok)
}
}
func TestTodo(t *testing.T) {
r := strings.NewReader(`# TAP emitted by Test::More 0.98
ok 1 - should be equal
not ok 2 - should be equivalent # TODO but we will fix it later
# boop
ok 3 - should be equal
ok 4 - (unnamed assert)
1..4
# Looks like you failed 1 test of 4.
`)
parser, err := NewParser(r)
if err != nil {
t.Errorf("Should be no error on parsing preamble, got: %v", err)
}
suite, err := parser.Suite()
if err != nil {
t.Errorf("Should be no error on parsing input, got: %v", err)
}
if len(suite.Tests) != 4 {
t.Errorf("Expect 4 tests, got: %v", len(suite.Tests))
}
if suite.Tests[0].Ok != true {
t.Errorf("Expect first test to be ok, got: %v", suite.Tests[0].Ok)
}
if suite.Tests[1].Ok != false {
t.Errorf("Expect second test to be not ok, got: %v", suite.Tests[1].Ok)
}
if suite.Tests[3].Ok != true {
t.Errorf("Expect last test to be not ok, got: %v", suite.Tests[3].Ok)
}
if suite.Tests[0].Directive.String() == "none" {
t.Errorf("Expect first test not to be marked, got: %v", suite.Tests[0].Directive)
}
if suite.Tests[1].Directive.String() == "todo" {
t.Errorf("Expect second test to be marked todo, got: %v", suite.Tests[1].Directive)
}
if suite.Tests[1].String() != "[todo] should be equivalent # but we will fix it later" {
t.Errorf("Unexpected string, got: %v", suite.Tests[1].String())
}
if suite.Tests[3].String() != "[ ok ] (unnamed assert)" {
t.Errorf("Unexpected string, got: %v", suite.Tests[3].String())
}
if suite.Passed != 3 {
t.Errorf("Unexpected 3 passed test, got: %v", suite.Passed)
}
}
func TestSkip(t *testing.T) {
r := strings.NewReader(`TAP version 13
1..5
ok 1 - approved operating system
# $^0 is solaris
ok 2 - # SKIP no /sys directory
ok 3 - # SKIP no /sys directory
ok 4 - # SKIP no /sys directory
ok 5 - # SKIP no /sys directory
`)
parser, err := NewParser(r)
if err != nil {
t.Errorf("Should be no error on parsing preamble, got: %v", err)
}
suite, err := parser.Suite()
if err != nil {
t.Errorf("Should be no error on parsing input, got: %v", err)
}
if len(suite.Tests) != 5 {
t.Errorf("Expect 5 tests, got: %v", len(suite.Tests))
}
if suite.Tests[0].Ok != true {
t.Errorf("Expect first test to be ok, got: %v", suite.Tests[0].Ok)
}
if suite.Tests[1].Ok != true {
t.Errorf("Expect second test to be ok, got: %v", suite.Tests[1].Ok)
}
if suite.Tests[1].Directive.String() == "skip" {
t.Errorf("Expect second test to be skipped, got: %v", suite.Tests[1].Directive)
}
if suite.Tests[1].String() != "[skip] # no /sys directory" {
t.Errorf("Unexpected string, got: %v", suite.Tests[1].String())
}
if suite.Passed != 1 {
t.Errorf("Unexpected 1 passed test, got: %v", suite.Passed)
}
if suite.Skipped != 4 {
t.Errorf("Unexpected 4 skipped test, got: %v", suite.Skipped)
}
}
func TestNoPlan(t *testing.T) {
r := strings.NewReader(`TAP version 13
# before 1
ok 1 should be equal
ok 2 should be equivalent
# before 3
ok 3 should be equal
ok 4 (unnamed assert)`)
parser, err := NewParser(r)
if err != nil {
t.Errorf("Should be no error on parsing preamble, got: %v", err)
}
suite, err := parser.Suite()
if err != nil {
t.Errorf("Should be no error on parsing input, got: %v", err)
}
if len(suite.Tests) != 4 {
t.Errorf("Expect 4 tests, got: %v", len(suite.Tests))
}
}
func TestDoublePlan(t *testing.T) {
r := strings.NewReader(`TAP version 13
1..4
# before 1
ok 1 should be equal
ok 2 should be equivalent
# before 3
ok 3 should be equal
ok 4 (unnamed assert)
1..4`)
parser, err := NewParser(r)
if err != nil {
t.Errorf("Should be no error on parsing preamble, got: %v", err)
}
_, err = parser.Suite()
if err == nil {
t.Errorf("Should be no error on parsing input, got: %v", err)
}
if err.Error() != "Double plan" {
t.Errorf("Expected double plan error, got: %v", err)
}
}
func TestEmptyPlan(t *testing.T) {
r := strings.NewReader(`TAP version 13
1..0
`)
parser, err := NewParser(r)
if err != nil {
t.Errorf("Should be no error on parsing preamble, got: %v", err)
}
suite, err := parser.Suite()
if err != nil {
t.Errorf("Should be no error on parsing input, got: %v", err)
}
if suite.Ok {
t.Errorf("Expect suite to be failed, got: %v", suite.Ok)
}
}
func TestYaml(t *testing.T) {
r := strings.NewReader(`TAP Version 13
not ok 1 Resolve address
---
message: "Failed with error 'hostname peebles.example.com not found'"
severity: fail
data:
got:
hostname: 'peebles.example.com'
address: ~
expected:
hostname: 'peebles.example.com'
address: '85.193.201.85'
...
1..1`)
parser, err := NewParser(r)
if err != nil {
t.Errorf("Should be no error on parsing preamble, got: %v", err)
}
suite, err := parser.Suite()
if err != nil {
t.Errorf("Should be no error on parsing input, got: %v", err)
}
if suite.Ok {
t.Errorf("Expect suite to be failed, got: %v", suite.Ok)
}
expected := ` message: "Failed with error 'hostname peebles.example.com not found'"
severity: fail
data:
got:
hostname: 'peebles.example.com'
address: ~
expected:
hostname: 'peebles.example.com'
address: '85.193.201.85'
`
if string(suite.Tests[0].Yaml) != expected {
t.Errorf("Unexpected string for yaml, got: %v", string(suite.Tests[0].Yaml))
}
if suite.Passed != 0 {
t.Errorf("Unexpected 0 passed test, got: %v", suite.Passed)
}
if suite.Failed != 1 {
t.Errorf("Unexpected 1 failed test, got: %v", suite.Failed)
}
}
func TestComments(t *testing.T) {
r := strings.NewReader(`1..3
ok 1 Description # Directive
# Diagnostic line 1
# Diagnostic line 2
ok 2 Description
ok 3 Description`)
parser, err := NewParser(r)
if err != nil {
t.Errorf("Should be no error on parsing preamble, got: %v", err)
}
suite, err := parser.Suite()
if err != nil {
t.Errorf("Should be no error on parsing input, got: %v", err)
}
if !suite.Ok {
t.Errorf("Expect suite to be ok, got: %v", suite.Ok)
}
if suite.Tests[0].Diagnostic != "Diagnostic line 1\nDiagnostic line 2" {
t.Errorf("Unexpected string for diagnostic, got: %v", suite.Tests[0].Diagnostic)
}
}