-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
errorformat_test.go
382 lines (369 loc) · 9.63 KB
/
errorformat_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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
package errorformat
import (
"reflect"
"strings"
"testing"
)
func TestScanner_Scan(t *testing.T) {
defer func(save func(string) bool) { fileexists = save }(fileexists)
fileexists = func(string) bool { return true }
tests := []struct {
efm []string
in string
want []string
}{
{
efm: []string{`%f:%l:%c: %m`, `%-G%.%#`},
in: `
golint.new.go:3:5: exported var V should have comment or be unexported
golint.new.go:5:5: exported var NewError1 should have comment or be unexported
golint.new.go:7:1: comment on exported function F should be of the form "F ..."
golint.new.go:11:1: comment on exported function F2 should be of the form "F2 ..."
hoge
`,
want: []string{
`golint.new.go|3 col 5| exported var V should have comment or be unexported`,
`golint.new.go|5 col 5| exported var NewError1 should have comment or be unexported`,
`golint.new.go|7 col 1| comment on exported function F should be of the form "F ..."`,
`golint.new.go|11 col 1| comment on exported function F2 should be of the form "F2 ..."`,
},
},
{
efm: []string{
`%C %.%#`,
`%A File "%f", line %l%.%#`,
`%Z%\b%m`,
},
in: `
==============================================================
FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest)
--------------------------------------------------------------
Traceback (most recent call last):
File "unittests/dbfacadeTest.py", line 89, in testFoo
self.assertEquals(34, dtid)
File "/usr/lib/python2.2/unittest.py", line 286, in
failUnlessEqual
raise self.failureException, \
AssertionError: 34 != 33
--------------------------------------------------------------
Ran 27 tests in 0.063s`,
want: []string{
`||`,
`|| ==============================================================`,
`|| FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest)`,
`|| --------------------------------------------------------------`,
`|| Traceback (most recent call last):`,
`unittests/dbfacadeTest.py|89| AssertionError: 34 != 33`,
`||`,
`|| --------------------------------------------------------------`,
`|| Ran 27 tests in 0.063s`,
},
},
{
efm: []string{
`%A[%f]`,
`%C%trror`,
`%C%l,%c`,
`%Z%m`,
},
in: `[~/.vimrc]
Error
12,5`,
want: []string{"~/.vimrc|12 col 5 error|"},
},
{
efm: []string{
`%A[%f]`,
`%C%tarning %n`,
`%C%l,%c`,
`%Z%m`,
},
in: `[~/.vimrc]
warning 14
12,5`,
want: []string{"~/.vimrc|12 col 5 warning 14|"},
},
{
efm: []string{
`$%m`,
`%-G%.%#`,
},
in: `$hoge
$foo
piyo`,
want: []string{"|| hoge", "|| foo"},
},
{
efm: []string{`(%l,%c): %m`},
in: `(1,2): abc
(13,27): xyz
hoge`,
want: []string{"|1 col 2| abc", "|13 col 27| xyz", "|| hoge"},
},
{
efm: []string{`%[a-i]%m`},
in: `hoge
foo
piyo`,
want: []string{"|| oge", "|| oo", "|| piyo"},
},
{efm: []string{`{%l} %m`}, in: `{14} msg`, want: []string{"|14| msg"}},
{efm: []string{`[%l] %m`}, in: `[14] msg`, want: []string{"|14| msg"}},
{
efm: []string{`%EError %n`, `%Cline %l`, `%Ccolumn %c`, `%Z%m`},
in: `Error 275
line 42
column 3
' ' expected after '--'`,
want: []string{"|42 col 3 error 275| ' ' expected after '--'"},
},
{ // :h errorformat-separate-filename
efm: []string{`%+P[%f]`, `(%l,%c)%*[ ]%t%*[^:]: %m`, `%-Q`},
in: `[a1.tt]
(1,17) error: ';' missing
(21,2) warning: variable 'z' not defined
(67,3) error: end of file found before string ended
[a2.tt]
[a3.tt]
NEW compiler v1.1
(2,2) warning: variable 'x' not defined
(67,3) warning: 's' already defined
`,
want: []string{
"a1.tt|| [a1.tt]",
"a1.tt|1 col 17 error| ';' missing",
"a1.tt|21 col 2 warning| variable 'z' not defined",
"a1.tt|67 col 3 error| end of file found before string ended",
"a2.tt|| [a2.tt]",
"a3.tt|| [a3.tt]",
"a3.tt|| NEW compiler v1.1",
"a3.tt|2 col 2 warning| variable 'x' not defined",
"a3.tt|67 col 3 warning| 's' already defined",
},
},
{
efm: []string{`%-P[%f]`, `(%l,%c)%*[ ]%t%*[^:]: %m`, `%-Q`, `%-G%.%#`},
in: `[a1.tt]
(1,17) error: ';' missing
(21,2) warning: variable 'z' not defined
(67,3) error: end of file found before string ended
[a2.tt]
[a3.tt]
NEW compiler v1.1
(2,2) warning: variable 'x' not defined
(67,3) warning: 's' already defined
`,
want: []string{
"a1.tt|1 col 17 error| ';' missing",
"a1.tt|21 col 2 warning| variable 'z' not defined",
"a1.tt|67 col 3 error| end of file found before string ended",
"a3.tt|2 col 2 warning| variable 'x' not defined",
"a3.tt|67 col 3 warning| 's' already defined",
},
},
{ // grep format. (ag, pt, etc...)
efm: []string{`%l:%m`, `%-P%f`, `%-Q`},
in: `errorformat.go
1:// Package errorformat provides 'errorformat' functionality of Vim. :h
398:// NewEfm converts a 'errorformat' string to regular expression pattern with
README.md
1:## go-errorformat - vim 'errorformat' implementation in Go
`,
want: []string{
"errorformat.go|1| // Package errorformat provides 'errorformat' functionality of Vim. :h",
"errorformat.go|398| // NewEfm converts a 'errorformat' string to regular expression pattern with",
"README.md|1| ## go-errorformat - vim 'errorformat' implementation in Go",
},
},
{ // sbt
efm: []string{
`%E[%t%.%+] %f:%l: error: %m`,
`%A[%t%.%+] %f:%l: %m`,
`%Z[%.%+] %p^`,
`%C[%.%+] %.%#`,
`%-G%.%#`,
},
in: `
[error] /path/to/file:14: error: value ++ is not a member of Int
[error] val x = 1 ++ 2
[error] ^
[warn] /path/to/file2:14: local val in method watch is never used
[warn] val x = 1
[warn] ^
`,
want: []string{
"/path/to/file|14 col 13 error| value ++ is not a member of Int",
"/path/to/file2|14 col 8 warning| local val in method watch is never used",
},
},
{ // multiline
efm: []string{
`%E[%t%.%+] %f:%l: error: %m`,
`%A[%t%.%+] %f:%l: %m`,
`[%t%.%+] %f: error: %m`, // oneline
`%Z[%.%+] %p^`,
`%C[%.%+] %.%#`,
`%-G%.%#`,
},
in: `
[error] /path/to/file:14: error: value ++ is not a member of Int
[error] val x = 1 ++ 2
[error] ^
[error] /path/to/file: error: oneline error for the file
[error] /path/to/file:14: error: multiline
[error] without pointer
[error] /path/to/file: error: oneline error for the file 2
`,
want: []string{
"/path/to/file|14 col 13 error| value ++ is not a member of Int",
"/path/to/file| error| oneline error for the file",
"/path/to/file|14 error| multiline",
"/path/to/file| error| oneline error for the file 2",
},
},
{
efm: []string{
`%EMultilineError`,
`%Z%f:%l-%e:%c-%k`,
},
in: `MultilineError
~/.vimrc:1-2:3-4`,
want: []string{"~/.vimrc|1-2 col 3-4 error|"},
},
{ // note
efm: []string{
`[%tote]%f:%l:%c: %m`,
`%-G%.%#`,
},
in: `
[note]/path/to/file:1:2: note msg 1
[Note]/path/to/file:1:2: note msg 2`,
want: []string{
"/path/to/file|1 col 2 note| note msg 1",
"/path/to/file|1 col 2 note| note msg 2",
},
},
{ // end line/column
efm: []string{
`%f:%l-%e:%c-%k: %m`,
`%-G%.%#`,
},
in: `/path/to/file:1-2:3-4: msg`,
want: []string{
"/path/to/file|1-2 col 3-4| msg",
},
},
}
nexttext:
for _, tt := range tests {
efm, err := NewErrorformat(tt.efm)
if err != nil {
t.Error(err)
continue
}
s := efm.NewScanner(strings.NewReader(tt.in))
i := 0
for s.Scan() {
got := s.Entry().String()
efm := strings.Join(tt.efm, ",")
if i >= len(tt.want) {
t.Errorf("%v:%d: got %q, want is not specified", efm, i, got)
continue nexttext
}
want := tt.want[i]
if got != want {
t.Errorf("%v:%d:\ngot: %q\nwant: %q", efm, i, got, want)
}
i++
}
}
}
func TestEntry_Types(t *testing.T) {
tests := []struct {
t rune
nr int
want string
}{
{t: 'e', want: "error"},
{t: 'E', want: "error"},
{t: 'e', nr: 14, want: "error 14"},
{t: 'w', nr: 14, want: "warning 14"},
{t: 'i', want: "info"},
{t: 'n', want: "note"},
{nr: 14, want: "error 14"},
}
for _, tt := range tests {
e := &Entry{Type: tt.t, Nr: tt.nr}
if got := e.Types(); got != tt.want {
t.Errorf("(%v, %v): got %q, want %q", e.Type, e.Nr, got, tt.want)
}
}
}
type matchCase struct {
in string
want *Match
}
func TestNewEfm(t *testing.T) {
tests := []struct {
errorformat string
cases []matchCase
}{
{
errorformat: `%f:%l:%c: %m`,
cases: []matchCase{
{
in: "golint.new.go:3:5: exported var V should have comment or be unexported",
want: &Match{
F: "golint.new.go",
L: 3,
C: 5,
M: "exported var V should have comment or be unexported",
},
},
{in: "", want: nil},
{in: "golint.new.go:3:5", want: nil},
{
in: `/path/t\ o/file:1:4: message`,
want: &Match{F: `/path/t\ o/file`, L: 1, C: 4, M: "message"},
},
{
in: `\path\to\file:1:4: message`,
want: &Match{F: `\path\to\file`, L: 1, C: 4, M: "message"},
},
},
},
{
errorformat: ``,
cases: []matchCase{
{in: "", want: &Match{}},
{in: "golint.new.go:3:5", want: nil},
},
},
{
// windows
errorformat: `%f:%m`,
cases: []matchCase{
{
in: "c:/foo/bar.c:msg:hi:14",
want: &Match{F: "c:/foo/bar.c", M: "msg:hi:14"},
},
{
in: "hoge/c:/foo/bar.c:msg:hi:14",
want: &Match{F: "hoge/c", M: "/foo/bar.c:msg:hi:14"},
},
},
},
}
for _, tt := range tests {
efm, err := NewEfm(tt.errorformat)
if err != nil {
t.Errorf("NewEfm(%v) got an unexpected error: %v", tt.errorformat, err)
}
for _, c := range tt.cases {
if got := efm.Match(c.in); !reflect.DeepEqual(got, c.want) {
t.Errorf("efm: %v, efm.Match(%v) =\n%#v\nwant:\n %#v",
tt.errorformat, c.in, got, c.want)
}
}
}
}